Skip to content

Replace custom authentication with a standard OIDC relying party - #599

Open
pmeier wants to merge 13 commits into
ux-rework-devfrom
split/oidc-rp-chunks
Open

pmeier wants to merge 13 commits into
ux-rework-devfrom
split/oidc-rp-chunks

Conversation

@pmeier

@pmeier pmeier commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

This is just #598 split into multiple commits to make this more reviewable. All commits up until b77f570 where done by @tylerpotts and not by me.

…d refreshable token source

Shared client-side building block for CLI and desktop server login. No
callers yet; later commits in this stack use it. Part of the OIDC relying
party split (#585, #597).
… rewire the router

Team servers now validate access tokens issued by the identity provider
(signature, iss, aud, exp) and provision users from token claims: the
first request with a new token resolves (iss, sub) to a user and
reconciles groups and the admin role from the groups claim, cached per
token for at most 5 minutes and failing closed. auth.type is now 'oidc'
(default) or 'none' (no authentication, implicit admin). Adds the
in-process OIDC provider (internal/auth/authtest) used by tests.

Removes the old server-side OIDC login/callback and RFC 8628 device
token exchange handlers: nebi no longer runs the login redirect itself,
clients talk to the IdP directly. GET /api/v1/auth/config now advertises
issuer/client id/scopes so clients can configure themselves.

Intermediate state (cleaned up in the following commits):
- basic.go, proxy.go, authcode.go and the reconciliation monitor still
  exist but are no longer wired into the router (dead code).
- auth.go keeps LoginRequest/LoginResponse/ErrInvalidCredentials and
  UserContextKey (defined in basic.go) so the dead code still compiles.
- The web UI still posts to the removed /auth/login endpoint; frontend
  login is broken until the OIDC RP frontend commit lands.
- Some legacy tests were retargeted or dropped where they exercised
  replaced internals; they are deleted with the code anyway.
…reconciliation monitor

Deletes the legacy authentication machinery that the OIDC resource server
replaced: BasicAuthenticator (username/password login, nebi-signed JWTs,
ADMIN_USERNAME bootstrap), the gateway IdToken cookie flow (proxy.go),
the single-use auth-code store, and the authorization reconciliation
status monitor with its stale-token enforcement and retry loop. auth.go
loses LoginRequest/LoginResponse/ErrInvalidCredentials; UserContextKey
moves to auth.go.

Intermediate state:
- users.password_hash is no longer written; the column drop and the
  CLI-side store migration (password_hash removal, refresh-token
  credential fields) land with the user-management commits.
- The federated identity review queue still exists but nothing creates
  reviews anymore; it is removed next.
- db.go keeps migrating the now-unused review table until its own
  removal commit.
…he backend

nebi no longer creates, deletes or promotes users. Admins get a read-only
view: users and their groups are provisioned from identity provider
tokens, so user CRUD, toggle-admin, the ADMIN bootstrap helpers and the
whole review-queue surface (list/approve/reject/discard) are gone, along
with the CLI client methods and the desktop remote proxies for them.

Intermediate state:
- admin-managed groups still exist; their removal and the full schema
  migration (drop users.password_hash, groups.source/description, the
  review and reconciliation tables) land with the groups chunk.
- the admin frontend still renders user/review screens against the now
  removed endpoints until the frontend chunk lands.
…a migration

Groups are now identity-provider groups only, synced from the groups claim
of access tokens. Drops the group CRUD and membership-management service,
handlers and RBAC surface (group admin grants, bulk policy removal), the
groups.source/description columns, and the audit actions that tracked
nebi-managed users and groups.

db.Migrate now runs the complete one-way migration: delete native groups
with their memberships, grants and casbin policies, drop
users.password_hash and the groups columns, and drop the federated
identity review and auth reconciliation tables. This is the destructive
step of the upgrade; it is idempotent.
nebi login now runs the RFC 8628 device authorization grant with PKCE
directly against the identity provider (internal/oidcclient); the CLI
stores the provider's access and refresh tokens plus the token endpoint
and client id in the local credentials store, and refreshes them
automatically. The desktop app's connect-to-server flow uses the same
path via POST /remote/connect and /remote/connect/poll, so no nebi-
issued tokens or password-based CLI login remain. The router is now the
final version.

Intermediate state: the web UI still uses the old login page until the
frontend chunk lands.
…oup screens

Login is now authorization code + PKCE against the identity provider via
oidc-client-ts: the SPA redirects to the IdP, handles the callback at
/auth/callback, renews with the refresh token and performs RP-initiated
logout. Server config (issuer, client id, scopes) is read from
GET /api/v1/auth/config, so the UI configures itself per deployment.
Tests run against an in-test fake OIDC client (test/fakeOidc.ts).

Removes the password login form, the user management and create-user
screens, the federated identity review queue UI, group creation and the
group admin grant controls; admin group views are read-only over
identity-provider groups.
…ples and swagger

docker-compose.yml now brings up nebi behind Traefik together with
Keycloak (realm auto-import with a preconfigured public client) and
Postgres; docker/local.override.yml adapts it for a laptop, gen-local-
certs.sh produces the local TLS material, and compose.env.example
documents the variables. The old prod compose file and password/ADMIN
bootstrap env vars are gone. Docs describe the OIDC-only setup, the
device-flow CLI login and the new auth.type oidc|none options. Swagger
is regenerated for the new API surface.
@github-actions

Copy link
Copy Markdown

@pmeier pmeier changed the title [DONOTMERGE] OIDC split Replace custom authentication with a standard OIDC relying party Oct 5, 2026
@pmeier
pmeier requested a review from tylerpotts October 5, 2026 14:04
@pmeier
pmeier marked this pull request as ready for review October 5, 2026 14:05
@pmeier pmeier self-assigned this Oct 5, 2026
…p-chunks

# Conflicts:
#	frontend/package-lock.json
#	frontend/package.json
…p-chunks

# Conflicts:
#	app.go
#	docker-compose.prod.yml
#	docker-compose.yml
- oidcclient: guard the refreshing token source's cached access token with a
  mutex. Callers sharing one source (the desktop app serves parallel
  requests from it) raced on it and could persist a refreshed token twice.
  Add unit tests for the token source and the device-flow polling rules.
- auth: bound every identity-provider call (discovery and JWKS fetches) with
  a 10s HTTP client. go-oidc otherwise uses http.DefaultClient, which has no
  timeout, and the first discovery attempt runs before the listener starts.
- store: drop the users.password_hash column locally instead of importing
  internal/db, which pulled the Postgres driver into the CLI binary. Keep
  the data directory 0700 now that it holds a refresh token.
- /version reports features.auth from the resolved auth type, so a team
  server with auth.type none no longer advertises authentication.
- remote connect: read the device-flow poll interval under the lock.
- Remove dead code from the replaced auth model (cliclient.IsOIDCRedirect,
  login/user audit constants, golang-jwt dependency) and update
  CONTRIBUTING.md, the components doc, and the frontend README, which still
  described password login and JWT sessions.
@tylerpotts

Copy link
Copy Markdown
Collaborator

I ran this PR through an LLM code review (three parallel reviewers: architecture, Go auth/API/RBAC/DB, Go CLI/desktop/store/compose, plus a docs-drift pass; every finding was adversarially re-verified against the code at 5364010 before being accepted). Build, vet, go test -race -tags=e2e, golangci-lint, Biome and vitest were all green at that commit, swagger was byte-identical to a fresh regeneration, and the app.go merge resolution against #601 was confirmed complete.

Confirmed findings, all fixed in the follow-up commit I am pushing now:

  • Data race in oidcclient.notifyingSource.Token(): the cached access token was read and written without a lock. The desktop handler shares one token source across parallel requests, so any page load with an expired access token hit it (reproduced with -race). Fixed with a mutex plus a regression test that fails without the fix.
  • No HTTP timeout on identity-provider calls: Discover passed no oidc.ClientContext, so go-oidc used http.DefaultClient (no timeout) for discovery and later JWKS fetches, and the first discovery runs synchronously before ListenAndServe. A stalled provider could block startup. Fixed with a 10s client.
  • internal/store imported internal/db for DropColumns, which pulled the gorm Postgres driver and pgx into the CLI binary. Fixed by dropping the column locally. The store directory is now also created 0700 since it holds the refresh token.
  • /version advertised features.auth: true for a team server running auth.type: none; the device-flow poll interval was read outside the lock that writes it.
  • Dead code from the replaced auth model (cliclient.IsOIDCRedirect, login/user audit constants, golang-jwt in go.mod) and three docs that still described password login and JWT sessions (CONTRIBUTING.md, nebi-components.md, frontend/README.md).

Noted but left for follow-up issues rather than this PR: the Fly deploy workflow now expects OIDC_ISSUER_URL / OIDC_CLIENT_ID repository secrets that do not exist yet, so the deploy will fail once this reaches main; pre-existing seeded admin users keep their casbin admin policy after the migration; a JWKS fetch failure after discovery surfaces as 401 rather than 503; auth.jwt_secret is now only the registry-credential encryption key and deserves a rename. The BC list for this change is on #598.

Comment thread internal/oidcclient/oidcclient.go Resolved
Comment thread internal/oidcclient/oidcclient.go Resolved
Comment thread internal/oidcclient/oidcclient.go Resolved

@tylerpotts tylerpotts left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments on optionally replacing some hand-rolled code with calls to the oauth2 library. Otherwise PR seems good to go

Comment thread cmd/nebi-server/main.go
NEBI_AUTH_OIDC_ISSUER_URL issuer; must match the tokens' "iss" claim
NEBI_AUTH_OIDC_CLIENT_ID public client of the web UI, CLI and desktop app
NEBI_AUTH_OIDC_ADMIN_GROUPS identity-provider groups whose members are admins
NEBI_AUTH_OIDC_SCOPES scopes clients request (default openid,profile,email)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we make this configurable if we never need anything else?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need it for providers other than Keycloak. Nebi depends on the groups claim for group sharing and admin assignment, and several providers only release that claim when the client requests a groups scope, for example Dex and Okta. With a hardcoded openid,profile,email, those deployments would silently get no groups and no admins.

I added that explanation to the server-setup docs and config.yaml.example in c0e8a8c. Leaving this open in case you still want it removed.

Comment thread cmd/nebi-server/main.go Resolved
Comment thread cmd/nebi-server/main.go Resolved
Comment thread internal/api/handlers/user.go Resolved
Comment thread internal/api/handlers/version.go Resolved
Comment thread internal/api/router.go Resolved
Comment thread internal/api/router_test.go Resolved
Comment thread internal/auth/basic_test.go Resolved
Comment thread internal/auth/oidc.go Resolved
Comment thread internal/db/db.go Resolved
Comment thread docker/local.override.yml Resolved
- oidcclient: delegate discovery to go-oidc and the device flow, PKCE and
  RFC 8628 polling to oauth2 (Config.DeviceAuth, DeviceAccessToken,
  S256ChallengeOption, VerifierOption) instead of hand-rolled requests.
  Reject device authorizations without expires_in, which bounds polling.
- Desktop connect: wait for the device token in a background goroutine
  with oauth2's polling; /remote/connect/poll only reports the outcome.
  A new connect or a disconnect cancels the pending wait.
- Rename auth.jwt_secret / NEBI_AUTH_JWT_SECRET to encryption_key /
  NEBI_ENCRYPTION_KEY: it only derives the registry-credential key now.
- Drop the legacy database migration (password_hash, native groups,
  review tables) from the server and CLI store; upgrades are tracked in
  #589. Document that existing databases are not migrated yet.
- Remove the one-time tests asserting that removed auth routes 404.
- Document when to add a groups scope to auth.oidc_scopes.
- Reword the docker/local.override.yml header.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants