Repository navigation
Call KF Auth as the app and check the console's token - #73
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merge only after kf-console #76 is deployed to production. On staging, the console must be deployed with #76 before this goes to staging.
Moves underlay off the shared
AUTH_INTERNAL_API_KEY, following kf-console'sdocs/calling-kf.md./api/internal/users/:id/orgs,/users/search,/users/:id, used to link new orgs to a KF org) now sendAuthorization: Basic base64(OIDC_CLIENT_ID:OIDC_CLIENT_SECRET)instead ofBearer <key>. The console grantskf_underlayusers.search,users.getandusers.orgs.GET /api/kf/summarychecks theKF-Console-Tokenheader and no longer readsAuthorization. The token must verify against KF Auth's JWKS (EdDSA, fetched from<OIDC_ISSUER_URL>/api/auth/jwkswithjose'screateRemoteJWKSet), withiss=<OIDC_ISSUER_URL>/api/auth,aud=OIDC_CLIENT_ID,sub=kf-console, at most 60 s old with 30 s of skew,htm=GETandhtu=APP_URL+/api/kf/summary(the registeredsummary_url, not the URL the request arrived at). Anything else answers 401. The auth check now runs before thekf_org_idcheck.AUTH_INTERNAL_API_KEYis gone from the code andwrangler.jsonc; nothing reads it now.joseis added to@underlay/server(it was already in the lockfile through better-auth).Underlay has no webhook receiver, so there is no
body_sha256check to add.Checked: tests sign tokens with a locally generated EdDSA key and serve its JWKS from a stub fetch, with no network. They accept a good token and refuse a missing header, a non-JWT, a wrong
aud,sub,iss, an expired or too-old token, a wronghtm, a wronghtupath or host, a token signed by an unpublished key, and a tampered payload. A route test runs the real check through/api/kf/summary, and the oldBearerkey alone now gets 401. The outbound test checks that internal calls carryBasic base64(id:secret)and no Bearer.pnpm fmt:check,pnpm lint,pnpm typecheck,pnpm testand the web build and SSR smoke all pass locally.Env: the
AUTH_INTERNAL_API_KEYsecret can be deleted from each Worker (wrangler secret delete AUTH_INTERNAL_API_KEY --env staging|prod) and from the encrypted env files after this deploys. Nothing needs to be added:OIDC_CLIENT_ID/OIDC_CLIENT_SECRETare already set.