Skip to content

Commit 5e7f7e3

Browse files
fix(server): a desktop left running past a day keeps its local backend credential
The desktop hands each backend one bootstrap token for the life of the desktop process, but the server expired that grant after 24 hours. After that the renderer's topology poll re-presented the dead token to secondary (WSL) backends every few seconds forever: ~100k `Unknown bootstrap credential` failures a day in prod traces, from a handful of long-running desktops. The grant now lives as long as the server process that was launched with it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent ca95267 commit 5e7f7e3

2 files changed

Lines changed: 16 additions & 28 deletions

File tree

‎apps/server/src/auth/PairingGrantStore.test.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,16 @@ it.layer(NodeServices.layer)("PairingGrantStore.layer", (it) => {
168168
),
169169
);
170170

171-
it.effect("reports seeded desktop bootstrap credentials as expired after their ttl", () =>
171+
it.effect("keeps the seeded desktop bootstrap credential valid for the life of the server", () =>
172172
Effect.gen(function* () {
173173
const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
174174

175-
// The desktop-bootstrap grant lives for 24h. Within that window
176-
// it stays reusable.
177-
yield* TestClock.adjust(Duration.hours(12));
178-
const stillValid = yield* bootstrapCredentials.consume("desktop-bootstrap-token");
179-
expect(stillValid.method).toBe("desktop-bootstrap");
175+
// A desktop left running for days keeps the token it was launched
176+
// with, and the renderer re-exchanges it on every topology poll.
177+
yield* TestClock.adjust(Duration.days(30));
178+
const grant = yield* bootstrapCredentials.consume("desktop-bootstrap-token");
180179

181-
yield* TestClock.adjust(Duration.hours(13));
182-
const expired = yield* Effect.flip(bootstrapCredentials.consume("desktop-bootstrap-token"));
183-
184-
expect(expired._tag).toBe("ExpiredBootstrapCredentialError");
185-
expect(expired.message).toContain("Bootstrap credential expired");
180+
expect(grant.method).toBe("desktop-bootstrap");
186181
}).pipe(
187182
Effect.provide(
188183
Layer.merge(

‎apps/server/src/auth/PairingGrantStore.ts‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export interface BootstrapGrant {
2626
readonly subject: string;
2727
readonly label?: string;
2828
readonly proofKeyThumbprint?: string;
29-
readonly expiresAt: DateTime.DateTime;
29+
/** Null for a grant that lives as long as the server process. */
30+
readonly expiresAt: DateTime.DateTime | null;
3031
}
3132

3233
export class UnknownBootstrapCredentialError extends Schema.TaggedError<UnknownBootstrapCredentialError>()(
@@ -237,22 +238,12 @@ type ConsumeResult =
237238
};
238239

239240
const DEFAULT_ONE_TIME_TOKEN_TTL_MINUTES = Duration.minutes(5);
240-
// The desktop-bootstrap grant rides on a trusted IPC channel (fd3 or
241-
// stdin) at backend launch, so it doesn't have to be short-lived the
242-
// way a user-facing pairing link does. Letting it live for the
243-
// lifetime of the backend process (24h is more than long enough for
244-
// practical desktop use, and well under "forever" in case the seed
245-
// gets logged anywhere by accident) means a page reload past the 5-min
246-
// window can still recover by re-bootstrapping rather than locking
247-
// the user out of the backend.
248-
const DESKTOP_BOOTSTRAP_TTL_HOURS = Duration.hours(24);
249241
// A dev server's startup token is read off a log by whoever (or whatever) is
250242
// driving the session, often minutes later — after a `node --watch` restart, a
251243
// detour into another task, or a hand-off to the person actually doing the
252244
// testing. Five minutes turns that into a restart-the-server loop for no
253245
// security benefit: the token only unlocks a local dev backend, and its holder
254-
// could read the log anyway. Same reasoning (and duration) as the desktop
255-
// bootstrap grant above. Only applies when a dev URL is configured; user-issued
246+
// could read the log anyway. Only applies when a dev URL is configured; user-issued
256247
// pairing links and real servers keep the 5-minute default.
257248
const DEV_STARTUP_TTL_HOURS = Duration.hours(24);
258249
const PAIRING_TOKEN_ALPHABET = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
@@ -310,14 +301,16 @@ export const make = Effect.gen(function* () {
310301
}).pipe(Effect.asVoid);
311302

312303
if (config.desktopBootstrapToken) {
313-
const now = yield* DateTime.now;
314304
yield* seedGrant(config.desktopBootstrapToken, {
315305
method: "desktop-bootstrap",
316306
scopes: AuthAdministrativeScopes,
317307
subject: "desktop-bootstrap",
318-
expiresAt: DateTime.add(now, {
319-
milliseconds: Duration.toMillis(DESKTOP_BOOTSTRAP_TTL_HOURS),
320-
}),
308+
// The grant rides on a trusted IPC channel (fd3 or stdin) at backend
309+
// launch and lives as long as this process. The desktop hands the
310+
// renderer one token for its whole lifetime, so an expiry would leave a
311+
// running desktop holding a dead credential that it re-presents on
312+
// every topology poll.
313+
expiresAt: null,
321314
// Unbounded uses so the renderer can re-exchange the seed for a
322315
// fresh bearer session after a page reload (or after the prior
323316
// bearer expires). The seed itself stays inside the desktop
@@ -448,7 +441,7 @@ export const make = Effect.gen(function* () {
448441
}
449442

450443
const next = new Map(current);
451-
if (DateTime.isGreaterThanOrEqualTo(now, grant.expiresAt)) {
444+
if (grant.expiresAt !== null && DateTime.isGreaterThanOrEqualTo(now, grant.expiresAt)) {
452445
next.delete(credential);
453446
return [
454447
{

0 commit comments

Comments
 (0)