Skip to content

Commit 6d623b8

Browse files
committed
fix(config): collect GEMINI_API_KEY from system env into managed service keys
When GEMINI_API_KEY is set in the system environment but not in the config env section or .env file, it was written as a plaintext literal in the generated systemd service file instead of being managed via OPENCLAW_SERVICE_MANAGED_ENV_KEYS. Add GEMINI_API_KEY (and related GOOGLE_API_KEY, GEMINI_API_KEYS, GEMINI_API_KEY_0) to the list of provider API keys collected from the system environment into durableEnvironment, so they are included in the managed service env keys list. Fixes #95895
1 parent 514b336 commit 6d623b8

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/config/state-dir-dotenv.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,41 @@ export type DurableServiceEnvVarSources = {
127127
durableEnvironment: Record<string, string>;
128128
};
129129

130+
/** Provider API key env vars that should be collected from the system environment
131+
* into durableEnvironment when not already present from .env or config.
132+
* Prevents them from being written as plaintext literals in generated service
133+
* files instead of being managed via OPENCLAW_SERVICE_MANAGED_ENV_KEYS (#95895). */
134+
const PROVIDER_ENV_API_KEYS = [
135+
"GEMINI_API_KEY",
136+
"GEMINI_API_KEYS",
137+
"GEMINI_API_KEY_0",
138+
"GOOGLE_API_KEY",
139+
] as const;
140+
130141
/** Collects durable service env vars from state-dir `.env` and config, preserving each source. */
131142
export function collectDurableServiceEnvVarSources(params: {
132143
env: Record<string, string | undefined>;
133144
config?: OpenClawConfig;
134145
}): DurableServiceEnvVarSources {
135146
const stateDirDotEnvEnvironment = readStateDirDotEnvVars(params.env);
136147
const configEnvironment = collectConfigServiceEnvVars(params.config);
148+
// Collect provider API keys from the system environment when not already present
149+
// in .env or config. This prevents them from being written as plaintext literals
150+
// in generated service files instead of being managed via OPENCLAW_SERVICE_MANAGED_ENV_KEYS.
151+
const systemEnvProviderKeys: Record<string, string> = {};
152+
for (const key of PROVIDER_ENV_API_KEYS) {
153+
const value = params.env[key]?.trim();
154+
if (value && !stateDirDotEnvEnvironment[key] && !configEnvironment[key]) {
155+
systemEnvProviderKeys[key] = value;
156+
}
157+
}
137158
return {
138159
stateDirDotEnvEnvironment,
139160
configEnvironment,
140161
durableEnvironment: {
141162
...stateDirDotEnvEnvironment,
142163
...configEnvironment,
164+
...systemEnvProviderKeys,
143165
},
144166
};
145167
}

0 commit comments

Comments
 (0)