Repository navigation
feat(server): Cloudflare Access identity pairing (fork trial) - #1
Conversation
…gs toggle Verify Cf-Access-Jwt-Assertion via JWKS, remember human identities after first pair, and resume trusted browsers without a new pairing code. Operators can revoke a single session or drop the stored Access identity from Connections. Default off; no service-token shortcut. Co-authored-by: spk-alex <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d268343ab4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const session = yield* sessions.issue({ | ||
| method: "browser-session-cookie", | ||
| subject: "cloudflare-access-identity", | ||
| scopes: AuthStandardClientScopes, | ||
| cloudflareAccessIdentityKey: identity.value.identityKey, |
There was a problem hiding this comment.
Preserve the paired grant's scopes when resuming an identity
When a user pairs with a restricted-scope credential, EnvironmentAuth.createBrowserSession correctly issues only grant.scopes, but the browser-session handler records that identity regardless of its scopes. Opening a fresh browser then reaches this code and receives AuthStandardClientScopes, including terminal, filesystem-write, and access-management permissions. The identity record stores no grant scopes, so resuming silently escalates a restricted pairing into full control of the environment. Persist the authorized scopes with the identity and use those when issuing resumed sessions.
Useful? React with 👍 / 👎.
| const settings = useScopedSettings(); | ||
| const updateSettings = useUpdateScopedSettings(); | ||
| const session = useEnvironmentSessionState(environmentId); |
There was a problem hiding this comment.
Target Cloudflare settings at the selected access environment
With multiple connected environments, the Access page's “Showing access for” picker changes environmentId, but these hooks read and mutate the unrelated outer SettingsScopeProvider. With the default empty settings search, that scope is all, and planScopedSettingsPatch writes to every connected environment; a retained machine scope can instead target a different machine. Consequently, changing the selected server's Access toggle, team domain, or AUD can overwrite other servers' authentication configuration while displaying another server's values. Read settings and execute updates explicitly against the supplied environmentId.
AGENTS.md reference: AGENTS.md:L75-L75
Useful? React with 👍 / 👎.
| const http = yield* HttpClient.HttpClient; | ||
| let keySet: { readonly keys: Jwks.KeySet; readonly expiresAt: number } | undefined; |
There was a problem hiding this comment.
Retain the JWKS cache across verification calls
For production verification, keySet is initialized inside each invocation of verifyCloudflareAccessJwt, so every call starts with an empty cache and fetches Cloudflare's certificates again. The ten-minute TTL and stale-key fallback therefore never work across requests. Every pairing or identity resume incurs an external network request, and even a brief certificate-endpoint outage prevents previously verified identities from reconnecting. Keep the cache in a longer-lived service or closure, keyed by the configured JWKS endpoint.
Useful? React with 👍 / 👎.
Co-authored-by: spk-alex <[email protected]>
Squashed from the fork's history before rebasing onto upstream: - 11d10fd feat: default signed-in users to their own chats - c6d9960 feat: prefer personal subscriptions and share until weekly reset - 8d99e2d feat(server): Cloudflare Access identity pairing (fork trial) (#1) - aca7d4b fix: integrate current main and repair auth check failures - 26328e0 test: include current migrations in preview upgrade expectations - 70489b6 fix(server): preserve account ownership through queued and background work - f8851d8 feat(server): Cloudflare Access identity pairing skip after first pair - 10098bd fix(server): unify Cloudflare identity pairing and preserve granted access - 5d4bdd9 test(server): retain forged Cloudflare email header coverage - da6ac9e fix(server): accept human Cloudflare application tokens - 86bbfb6 fix(auth): use Cloudflare Access identity for My chats Folded in afterwards: subscription owner checks read settings only when they must (88c0082), the notes on two upstream tests changed for fork access checks (5522d41), and gt()/<T> wrapping of this feature's UI copy (from db8f6fb). Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01JLQGRKNn8mKpTc44SCwRT2
Squashed from the fork's history before rebasing onto upstream: - 11d10fd feat: default signed-in users to their own chats - c6d9960 feat: prefer personal subscriptions and share until weekly reset - 8d99e2d feat(server): Cloudflare Access identity pairing (fork trial) (#1) - aca7d4b fix: integrate current main and repair auth check failures - 26328e0 test: include current migrations in preview upgrade expectations - 70489b6 fix(server): preserve account ownership through queued and background work - f8851d8 feat(server): Cloudflare Access identity pairing skip after first pair - 10098bd fix(server): unify Cloudflare identity pairing and preserve granted access - 5d4bdd9 test(server): retain forged Cloudflare email header coverage - da6ac9e fix(server): accept human Cloudflare application tokens - 86bbfb6 fix(auth): use Cloudflare Access identity for My chats Folded in afterwards: subscription owner checks read settings only when they must (88c0082), the notes on two upstream tests changed for fork access checks (5522d41), and gt()/<T> wrapping of this feature's UI copy (from db8f6fb). Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01JLQGRKNn8mKpTc44SCwRT2
Problem
When T3 Code sits behind Cloudflare Access, every new browser still needs a one-time pairing code even after the user has already proven who they are through Access. Operators also had no way to revoke someone’s Access-bound identity separately from a single browser session.
Change
Cf-Access-Jwt-Assertionagainst Cloudflare JWKS (human identities only; service tokens rejected). After first successful pair, the verified Access subject is stored and later browsers with the same identity can auto-resume with standard client scopes. Migrations add identity storage and a session column for the bound key.revokeCloudflareAccessIdentityon revoke RPC;cloudflareAccessIdentityPairedon client session records for the UI.CloudflareAccessIdentityPairing.layernowprovideMergesSessionStore.layerso the live host matches unit-test wiring and avoidsService not found: t3/auth/SessionStoreafter migrations.Scope and approval
Fork-only trial on
smartphonekey/t3code— no upstream pingdotgg/t3code issue or PR. Toggle defaults off; no listen-address or secrets changes.Verification
vp test runonCloudflareAccessIdentityPairing.test.ts,CloudflareAccessJwt.test.ts, andEnvironmentAuth.test.ts(CF stubbed in auth suite; full stack covered in pairing tests).ConnectionsSettings.tsx;CloudflareAccessIdentitySettings.tsxunder Access when the operator can write access settings.Composer (cloud agent)
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.