Skip to content

v0.26.0: OAuth sign-in with scopes - #21

Merged
jansvabik merged 13 commits into
mainfrom
feat/p7-c1-oauth-login
Nov 7, 2026
Merged

jansvabik merged 13 commits into
mainfrom
feat/p7-c1-oauth-login

Conversation

@jansvabik

Copy link
Copy Markdown
Member

norcube login becomes a first-party OAuth 2.0 client of Norcube Auth: the browser approves the sign-in and hands the CLI a one-time code over 127.0.0.1, exchanged with PKCE. Tokens no longer pass through the dashboard page.

  • login --scopes limits a login to the given scopes (the CI token scopes, plus the Monitor ones); commands outside them exit 5 with a hint. The default stays full.
  • logout revokes the login on Norcube Auth; login --force ends the session it replaces.
  • A session from an older version moves to the new sign-in on its first command. auth status and doctor only describe it and leave it as it is.
  • The loopback callback refuses a request with another state and keeps waiting; metadata endpoints must share the issuer's origin; the sign-in waits as long as the server keeps the request (10 minutes).
  • --debug redacts OAuth codes and the PKCE verifier.
  • go-selfupdate 1.7.0 drops the deprecated x/crypto/openpgp.

Tested end to end against staging: browser and scoped sign-in, token exchange for every product, --force, logout revocation, forged callbacks. See CHANGELOG.md for the full notes, including the upgrade notes for older binaries.

The CLI becomes a first-party OAuth 2.0 client of Norcube Auth
(client_id norcube-cli), discovered from the auth URL's RFC 8414
metadata:

- Browser sign-in: authorization code with PKCE (S256) and a random
  state over a 127.0.0.1 loopback redirect on a random port. The
  callback must carry the state and the issuer (RFC 9207) before the
  code is exchanged. The request names the scopes, the hostname
  (device_name) and the CLI's User-Agent (client_user_agent).
- Device sign-in against the OAuth server's device authorization
  endpoint, polled at the token endpoint, with scopes.
- TokenSource: an OAuth sign-in refreshes only its 5-minute CLI access
  token, under the in-process mutex and the per-profile lock, and
  stores the rotated refresh token before using the new access token.
  A refused refresh reads the stored token again once, in case another
  process rotated it. Tokens per (audience, organization) come from the
  RFC 8693 token exchange, without the lock, cached in memory only.
- Errors: invalid_grant asks for a login (exit 4), org_access_denied is
  the existing ErrOrgAccessDenied, insufficient_scope is a ScopeError
  that names the login's scopes.
- Credentials format 2: refresh token, cached CLI access token, granted
  scopes and a format marker, within the Windows keyring limit (a store
  that refuses the blob gets it without the access token).
- An older sign-in (format 1) is moved to OAuth once, under the lock,
  by exchanging its refresh JWT; a token Norcube Auth won't move asks
  for one login. Without the token exchange in the metadata (an older
  server) the older refresh keeps working.
- RevokeRefreshToken (RFC 7009) for logout.

authtest is a fake Norcube Auth OAuth server for the tests: metadata,
authorization redirect, code exchange, refresh with rotation, grace and
reuse detection, token exchange, device flow, upgrade and revocation.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
- login signs in through OAuth when Norcube Auth offers it (browser or
  --device), else with the older sign-in. --scopes a,b limits the login
  to those scopes (validated locally, completed from a static list that
  mirrors the server catalog; the default is full) and the login prints
  the scopes Norcube granted. The OAuth sign-in doesn't name the user,
  so login reads /auth/me afterwards.
- logout revokes an OAuth sign-in's refresh token (RFC 7009); an older
  sign-in still uses /auth/cli/sign-out. A server failure is reported
  and the local sign-out happens anyway.
- A refusal for missing scope under a limited login says which scopes
  the login has and to run `norcube login` for full access (exit 5).
- auth sessions list has a SCOPES column; whoami and auth status show
  the login's scopes, auth status its credential format; doctor shows
  the credential format and scopes, warns about the older format and
  skips services a limited login doesn't cover.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
README gets a "Signing in" section (the OAuth login, --scopes,
--device, CLI sessions and Connected apps, revocation on logout).
ARCHITECTURE describes the sign-in flows, the token exchange, the
credential formats, the error mapping and the fallback. The changelog
lists the changes and what upgrading means: an older binary on the same
machine must sign in again after the move, and one with its own copy of
the refresh token signs the upgraded CLI out when it presents it.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
- login --force (and any login that replaces a stored session) ends the
  previous session on Norcube Auth before storing the new one, the way
  logout does: RFC 7009 revocation for an OAuth sign-in, the older
  sign-out endpoint for an older one. Best effort: a failure is a
  warning and the new session is stored anyway.
- The token exchange omits organization_id for the auth audience when
  there is no organization, so an account without one can sign in and
  use whoami, org list and org create. Product audiences still need an
  organization and get the usage error before any request. login reads
  /auth/me even when default_organization is null, and the organization
  lookup for --org no longer needs the default organization.
- The fake server accepts a missing organization_id only for auth.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
…anization

README, ARCHITECTURE and the changelog describe both.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
The trace redacted only a field named code. The device code and the PKCE code_verifier are one-time credentials too and leaked; now every *_code field except user_code (the short code the person types, shown on screen anyway) and anything named verifier is redacted. The code_challenge stays: it is a hash.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
- The loopback callback answers a request with another state 400 and
  keeps waiting, so a local probe can't abort the sign-in; it is single
  use.
- Metadata endpoints must share the issuer's origin. A token endpoint
  answering without OAuth drops the cached metadata and the request is
  sent once to the rediscovered endpoint; doctor forgets the cache too.
- login --scopes sends a well-formed scope this release doesn't know;
  Norcube Auth answers invalid_scope if it doesn't exist.
- The fake counts refreshes inside the grace window; the race tests
  assert there are none.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
login --scopes offers the four monitor scopes, and tests check that a
full sign-in reaches every service in the registry. The changelog notes
move back under Unreleased and DESIGN.md describes the OAuth sign-in.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
…opes

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
Their session and token checks went through the normal token path,
which moves a format 1 sign-in to OAuth on first use. A diagnostic must
not change the profile it describes: TokenSource.KeepLegacy uses the
older refresh instead, and both commands set it.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
The CLI gave up after 5 minutes while the server and the dashboard allow
10; an approval between the two sent the browser to a closed port.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
The scan's accepted entry for GO-2026-5932 goes with it, so the finding
fails CI again if the import ever comes back.

Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
Signed-off-by: Jan Švábík <jansvabik@jansvabik.cz>
@jansvabik
jansvabik merged commit 519d2da into main Nov 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant