Skip to content

Commit c8245c3

Browse files
committed
fix(linux): retire previously managed provider credentials
1 parent 512be49 commit c8245c3

2 files changed

Lines changed: 23 additions & 36 deletions

File tree

‎src/commands/daemon-install-helpers.test.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,12 +754,15 @@ describe("buildGatewayInstallPlan", () => {
754754
},
755755
);
756756

757-
it("preserves operator ownership when migrating a managed file-backed provider API key", async () => {
757+
it("removes managed provider credentials when their configuration no longer owns them", async () => {
758758
mockNodeGatewayPlanFixture({ serviceEnvironment: { OPENCLAW_PORT: "3000" } });
759759
mocks.hasAnyAuthProfileStoreSource.mockReturnValue(false);
760760

761761
const plan = await buildGatewayInstallPlan({
762-
env: isolatedPlanEnv({ OPENAI_API_KEY: "rotated-shell-openai" }),
762+
env: isolatedPlanEnv({
763+
OPENAI_API_KEY: "existing-managed-openai",
764+
ANTHROPIC_API_KEY: "fresh-operator-anthropic",
765+
}),
763766
existingEnvironment: {
764767
OPENAI_API_KEY: "existing-managed-openai",
765768
OPENCLAW_SERVICE_MANAGED_ENV_KEYS: "OPENAI_API_KEY",
@@ -771,8 +774,10 @@ describe("buildGatewayInstallPlan", () => {
771774
config: {},
772775
});
773776

774-
expect(plan.environment.OPENAI_API_KEY).toBe("existing-managed-openai");
775-
expect(plan.environmentValueSources?.OPENAI_API_KEY).toBe("file");
777+
expect(plan.environment.OPENAI_API_KEY).toBeUndefined();
778+
expect(plan.environmentValueSources?.OPENAI_API_KEY).toBeUndefined();
779+
expect(plan.environment.ANTHROPIC_API_KEY).toBe("fresh-operator-anthropic");
780+
expect(plan.environmentValueSources?.ANTHROPIC_API_KEY).toBe("file");
776781
expect(plan.environment.OPENCLAW_SERVICE_MANAGED_ENV_KEYS).toBeUndefined();
777782
});
778783

‎src/commands/daemon-install-helpers.ts‎

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -187,49 +187,32 @@ async function collectAmbientProviderApiKeyServiceEnvVars(params: {
187187
durableEnvironment: Record<string, string | undefined>;
188188
authProfileEnvironment: Record<string, string | undefined>;
189189
existingEnvironment?: Record<string, string | undefined>;
190-
existingEnvironmentValueSources?: Record<
191-
string,
192-
GatewayServiceEnvironmentValueSource | undefined
193-
>;
194190
platform: NodeJS.Platform;
195191
}): Promise<Record<string, string>> {
196192
if (params.platform !== "linux") {
197193
return {};
198194
}
199-
const existingManagedKeys = readManagedServiceEnvKeysFromEnvironment(params.existingEnvironment);
200-
const existingManagedFileEnvironment = Object.fromEntries(
201-
Object.entries(params.existingEnvironment ?? {}).filter(
202-
([key, value]) =>
203-
existingManagedKeys.has(key.toUpperCase()) &&
204-
readEnvironmentValueSource(params.existingEnvironmentValueSources, key) === "file" &&
205-
value?.trim(),
206-
),
207-
);
208195
const ownedKeys = new Set(
209196
[
210197
...Object.keys(params.durableEnvironment),
211198
...Object.keys(params.authProfileEnvironment),
212-
...Object.keys(params.existingEnvironment ?? {}).filter(
213-
(key) => !Object.hasOwn(existingManagedFileEnvironment, key),
214-
),
199+
...Object.keys(params.existingEnvironment ?? {}),
215200
].map((key) => key.toUpperCase()),
216201
);
217202
const candidates = new Map(
218-
Object.entries({ ...params.env, ...existingManagedFileEnvironment }).flatMap(
219-
([rawKey, rawValue]) => {
220-
const key = normalizeEnvVarKey(rawKey, { portable: true })?.toUpperCase();
221-
const value = rawValue?.trim();
222-
return key &&
223-
key.endsWith("_API_KEY") &&
224-
!key.endsWith("_ADMIN_API_KEY") &&
225-
!ownedKeys.has(key) &&
226-
value &&
227-
!isDangerousHostEnvVarName(key) &&
228-
!isDangerousHostEnvOverrideVarName(key)
229-
? [[key, value] as const]
230-
: [];
231-
},
232-
),
203+
Object.entries(params.env).flatMap(([rawKey, rawValue]) => {
204+
const key = normalizeEnvVarKey(rawKey, { portable: true })?.toUpperCase();
205+
const value = rawValue?.trim();
206+
return key &&
207+
key.endsWith("_API_KEY") &&
208+
!key.endsWith("_ADMIN_API_KEY") &&
209+
!ownedKeys.has(key) &&
210+
value &&
211+
!isDangerousHostEnvVarName(key) &&
212+
!isDangerousHostEnvOverrideVarName(key)
213+
? [[key, value] as const]
214+
: [];
215+
}),
233216
);
234217
if (candidates.size === 0) {
235218
return {};
@@ -730,7 +713,6 @@ async function buildGatewayInstallEnvironment(params: {
730713
durableEnvironment,
731714
authProfileEnvironment,
732715
existingEnvironment: params.existingEnvironment,
733-
existingEnvironmentValueSources: params.existingEnvironmentValueSources,
734716
platform: params.platform,
735717
});
736718
const stateDirDotEnvRenderEnvironment = omitEnvironmentEntriesShadowedBy(

0 commit comments

Comments
 (0)