feat(server): add reusable auth token for dev worktrees #8606
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 7 commits into
main fromrefs/pull/8606/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/auth/EnvironmentAuth.ts lines 967 to 968OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -887,4 +949,20 @@949+ const fallback = issuePairingCredentialForSubject({887950 scopes: AuthAdministrativeScopes,888951 subject: INTERNAL_ADMINISTRATIVE_BOOTSTRAP_SUBJECT,889952 purpose: "startup",890- }).pipe(Effect.withSpan("EnvironmentAuth.issueStartupPairingCredential"));953+ });954+ if (!devAuth) {955+ return fallback.pipe(Effect.withSpan("EnvironmentAuth.issueStartupPairingCredential"));956+ }957+ return sessions.verify(devAuth.credential).pipe(958+ Effect.map(959+ (session) =>960+ ({961+ id: session.sessionId,962+ credential: devAuth.credential,963+ label: "Reusable dev token",964+ expiresAt: DateTime.toUtc(session.expiresAt ?? REUSABLE_DEV_SESSION_EXPIRES_AT),965+ }) satisfies AuthPairingCredentialResult,966+ ),967+ Effect.catchIf(SessionStore.isSessionCredentialInvalidError, () => fallback),968+ Effect.mapError((cause) => new ServerAuthPairingLinkCreationError({ cause })),
github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change
github-actions[bot](GitHub profile, opens in a new tab) removed labels📱 Native Change
- apps/server/src/auth/ReusableDevAuth.ts line 26Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -0,0 +6,21 @@6+import type { ServerConfig } from "../config.ts";7+8+export const REUSABLE_DEV_SESSION_PREFIX = "dev-auth-";9+// The database schema requires an expiry for a configured token with no normal session TTL.10+export const REUSABLE_DEV_SESSION_EXPIRES_AT = DateTime.makeUnsafe("9999-12-31T23:59:59.999Z");11+12+export function resolveReusableDevAuth(13+ config: Pick<ServerConfig["Service"], "mode" | "devUrl" | "devAuthToken">,14+) {15+ if (config.mode !== "web" || config.devUrl === undefined || config.devAuthToken === undefined) {16+ return undefined;17+ }18+ const token = config.devAuthToken;19+ if (Redacted.value(token).length === 0) {20+ return undefined;21+ }22+ const hash = NodeCrypto.createHash("sha256").update(Redacted.value(token)).digest();23+ const tokenId = hash.toString("hex");24+ return {25+ credential: Redacted.value(token),26+ sessionId: AuthSessionId.make(`${REUSABLE_DEV_SESSION_PREFIX}${tokenId}`),
- apps/server/src/auth/EnvironmentAuth.ts line 730Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -697,5 +712,19 @@697712 const createBrowserSession: EnvironmentAuth["Service"]["createBrowserSession"] = (698713 credential,699714 requestMetadata,700- ) =>701- bootstrapCredentials.consume(credential).pipe(715+ ) => {716+ if (devAuth?.matches(credential)) {717+ return sessions.verify(credential).pipe(718+ mapSessionVerificationErrors,719+ Effect.flatMap((session) =>720+ DateTime.now.pipe(721+ Effect.map(722+ (now) =>723+ ({724+ response: {725+ authenticated: true,726+ scopes: session.scopes,727+ sessionMethod: session.method,728+ expiresAt: DateTime.toUtc(DateTime.add(now, { days: 30 })),729+ } satisfies AuthBrowserSessionResult,730+ sessionToken: credential,packages/client-runtime/src/rpc/session.ts lines 294 to 301Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -289,4 +290,12 @@289290 Effect.mapError(mapRpcError),290291 Effect.flatMap(() => Effect.fail(configSubscriptionEndedError)),291292 ),292- ).pipe(Effect.withSpan("environment.initialSync"));293+ ).pipe(294+ Effect.flatMap((config) =>295+ config.environment.environmentId === connection.environmentId296+ ? Effect.succeed(config)297+ : environmentMismatchError({298+ expected: connection.environmentId,299+ actual: config.environment.environmentId,300+ }),301+ ),
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
45105bed-eb24-471f-b1a3-44dd7849532b📥 Commits
Reviewing files that changed from the base of the PR and between 165b000b090e1cae045e918388533c7c5c4ff860 and bc3bd44c66dcc3a71d7763270f4e202ad0eec36e.
📒 Files selected for processing (3)
docs/operations/development.mdpackages/client-runtime/src/rpc/session.test.tspackages/client-runtime/src/rpc/session.ts🚧 Files skipped from review as they are similar to previous changes (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
📝 Walkthrough
Walkthrough#
The change adds reusable web development authentication with persistent sessions, dedicated cookies, token exchange, and documentation. It updates URL pairing-token bootstrap behavior and validates mismatched server environments before configuration subscriptions proceed.
Changes#
Reusable development authentication
apps/server/src/auth/ReusableDevAuth.ts,apps/server/src/cli/config.ts,apps/server/src/config.ts,scripts/dev-runner.ts,scripts/*.test.ts,apps/server/src/cli/config.test.tsT3CODE_DEV_AUTH_TOKEN. Desktop mode does not expose or forward the token.apps/server/src/auth/SessionStore.ts,apps/server/src/persistence/AuthSessions.ts,apps/server/src/auth/SessionStore.test.tsapps/server/src/auth/EnvironmentAuth.ts,apps/server/src/auth/http.ts,apps/server/src/auth/*test.tsAGENTS.md,docs/internals/environment-auth.md,docs/operations/development.mdPairing URL bootstrap handling
apps/web/src/environments/primary/auth.ts,apps/web/src/authBootstrap.test.tsClient environment validation
packages/client-runtime/src/rpc/session.ts,packages/client-runtime/src/rpc/session.test.tsPriority: ➖ Normal
Estimated code review effort: 4 (Complex) | ~60 minutes
Change: Feature
Sequence Diagram(s)#
Merge Risk: 🟡 Moderate · up to
bc3bdA service sharing the development hostname can receive and reuse the administrative development token from the browser cookie. Restrict the exchanged browser credential or its delivery scope before merging.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 17 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.