-
Notifications
You must be signed in to change notification settings - Fork 0
client: clear disconnected hub token on standalone recycle #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: Dev
Are you sure you want to change the base?
Changes from all commits
d35592b
71c57ea
d560ac6
08ada6f
ec51e42
e25b653
80fff9a
fc4de77
c7d8407
54e2274
2c4dca1
a34e8b7
ebb4d55
682112e
af6113a
847f4f1
ac78647
aaa9eaf
35ff3a4
1ea3f47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { loadConfig } from "../config"; | |
| import { removePid, removeRuntimePort, writePid, writeRuntimePort } from "../config/process-state"; | ||
| import { installCrashGuards } from "../lib/crash-guard"; | ||
| import { selfLaunchArgv } from "../lib/self-launch-argv"; | ||
| import { serviceApiTokenFingerprint } from "../lib/service-secrets"; | ||
| import { findAvailablePort } from "../server/ports"; | ||
| import { startMachineListener } from "./machine-listener"; | ||
| import { readClientConnectionState } from "./state"; | ||
|
|
@@ -17,7 +18,20 @@ function cleanup(): void { | |
| removeRuntimePort(process.pid); | ||
| } | ||
|
|
||
| export function scheduleStandaloneRecycle(): void { | ||
| export function standaloneRecycleEnv( | ||
| env: NodeJS.ProcessEnv, | ||
| disconnectedTokenFingerprint: string, | ||
| ): NodeJS.ProcessEnv { | ||
| const childEnv = { ...env }; | ||
| const admissionToken = childEnv.OPENCODEX_API_AUTH_TOKEN?.trim(); | ||
| if (admissionToken && serviceApiTokenFingerprint(admissionToken) === disconnectedTokenFingerprint) { | ||
| delete childEnv.OPENCODEX_API_AUTH_TOKEN; | ||
| delete childEnv.OCX_API_TOKEN_FILE; | ||
| } | ||
| return childEnv; | ||
| } | ||
|
|
||
| export function scheduleStandaloneRecycle(disconnectedTokenFingerprint: string): void { | ||
| if (recycleScheduled) return; | ||
| recycleScheduled = true; | ||
| const timer = setTimeout(() => { | ||
|
|
@@ -46,7 +60,7 @@ export function scheduleStandaloneRecycle(): void { | |
| detached: true, | ||
| stdio: "ignore", | ||
| windowsHide: true, | ||
| env: { ...process.env }, | ||
| env: standaloneRecycleEnv(process.env, disconnectedTokenFingerprint), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the client runs under the Windows Task Scheduler service, this filtered environment is never used because AGENTS.md reference: AGENTS.md:L329-L335 Useful? React with 👍 / 👎. |
||
| }); | ||
| child.unref(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { serviceApiTokenFingerprint } from "../src/lib/service-secrets"; | ||
| import { standaloneRecycleEnv } from "../src/client/runtime"; | ||
|
|
||
| describe("standalone recycle environment", () => { | ||
| test("removes a disconnected hub token and its token-file source", () => { | ||
| const hubToken = "hub-issued-token"; | ||
| const source = { | ||
| OPENCODEX_API_AUTH_TOKEN: hubToken, | ||
| OCX_API_TOKEN_FILE: "/tmp/hub-service-token", | ||
| PATH: "/usr/bin", | ||
| }; | ||
|
|
||
| expect(standaloneRecycleEnv(source, serviceApiTokenFingerprint(hubToken))).toEqual({ | ||
| PATH: "/usr/bin", | ||
| }); | ||
| expect(source.OPENCODEX_API_AUTH_TOKEN).toBe(hubToken); | ||
| }); | ||
|
|
||
| test("preserves an independently configured operator credential", () => { | ||
| const operatorToken = "operator-token"; | ||
| const source = { | ||
| OPENCODEX_API_AUTH_TOKEN: operatorToken, | ||
| OCX_API_TOKEN_FILE: "/tmp/operator-token", | ||
| }; | ||
|
|
||
| expect(standaloneRecycleEnv(source, serviceApiTokenFingerprint("disconnected-hub-token"))).toEqual(source); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
OPENCODEX_API_AUTH_TOKENcontains the disconnected hub token whileOCX_API_TOKEN_FILEpoints to an independently configured operator credential, this deletes both variables solely because the environment token matches. The replacement therefore cannot letloadServiceTokenFromFilerestore the operator credential and starts with no intended admission token. Check the referenced file's token fingerprint or only removeOCX_API_TOKEN_FILEwhen it identifies the disconnected service-token source.AGENTS.md reference: src/AGENTS.md:L10-L10
Useful? React with 👍 / 👎.