You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: always route Gemini through api-proxy sidecar when --enable-api-proxy is active (#1946)
* Initial plan
* fix: always set GEMINI_API_BASE_URL when api-proxy enabled
When --enable-api-proxy is active, set GEMINI_API_BASE_URL and the
GEMINI_API_KEY placeholder unconditionally in the agent environment,
regardless of whether config.geminiApiKey is present in the AWF runner
environment.
Previously, both were only set when config.geminiApiKey was truthy,
causing the Gemini CLI to fail with exit code 41 ("no auth method")
whenever the key was available only as a GitHub Actions secret and not
as a runner-level env var.
The api-proxy sidecar returns 503 when the real key is absent — a
clear, actionable failure vs a confusing missing-auth error.
Also update docs/api-proxy-sidecar.md to:
- Add GEMINI_API_KEY to the api-proxy env table
- Add GEMINI_API_BASE_URL / GEMINI_API_KEY placeholder rows to the
agent env table with a :::note explaining the always-set behaviour
- Add GitHub Actions caution note in the required env vars section
- Add a Gemini CLI exit-code-41 troubleshooting entry
- Fix the Limitations section (was incorrectly "only OpenAI/Anthropic")
- Fix the container ports list to include port 10003 (Gemini)
Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/d29ba1a1-4886-4755-ab93-12a3eb6fa4a3
* fix: address review feedback on Gemini docs
- Add COPILOT_GITHUB_TOKEN/COPILOT_API_KEY to required env vars list
- Add sudo --preserve-env note for GitHub Actions usage
- Update troubleshooting: exit 41 replaced by 503 (placeholder
key now satisfies CLI pre-flight)
- Update 'API keys not detected' message to list all providers
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Landon Cox <landon.cox@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|`COPILOT_PROVIDER_BASE_URL`|`http://172.30.0.30:10002`|`COPILOT_API_KEY` provided to host | Points Copilot CLI BYOK provider at sidecar |
150
151
|`COPILOT_PROVIDER_API_KEY`|`placeholder-token-for-credential-isolation`|`COPILOT_API_KEY` provided to host | BYOK provider API key placeholder (real key in sidecar) |
152
+
|`GEMINI_API_BASE_URL`|`http://172.30.0.30:10003`|`--enable-api-proxy` always | Redirects Gemini CLI to proxy (set unconditionally — see note below) |
153
+
|`GEMINI_API_KEY`|`gemini-api-key-placeholder-for-credential-isolation`|`--enable-api-proxy` always | Placeholder so Gemini CLI auth check passes (real key in sidecar) |
151
154
|`OPENAI_API_KEY`| Not set |`--enable-api-proxy`| Excluded from agent (held in api-proxy) |
152
155
|`ANTHROPIC_API_KEY`| Not set |`--enable-api-proxy`| Excluded from agent (held in api-proxy) |
153
156
|`HTTP_PROXY`|`http://172.30.0.10:3128`| Always | Routes through Squid proxy |
@@ -156,6 +159,14 @@ The agent container receives **redacted placeholders** and proxy URLs:
156
159
|`AWF_API_PROXY_IP`|`172.30.0.30`|`--enable-api-proxy`| Used by iptables setup script |
157
160
|`AWF_ONE_SHOT_TOKENS`|`COPILOT_GITHUB_TOKEN,GITHUB_TOKEN,...`| Always | Tokens protected by one-shot-token library |
158
161
162
+
:::note[Gemini always redirected to proxy]
163
+
Unlike OpenAI, Anthropic, and Copilot, `GEMINI_API_BASE_URL` and the `GEMINI_API_KEY` placeholder are **always** set in the agent when `--enable-api-proxy` is active, regardless of whether `GEMINI_API_KEY` is present in the runner environment.
164
+
165
+
This prevents the Gemini CLI from failing with exit code 41 ("no auth method") when the real API key is only available as a GitHub Actions secret (not as a runner-level environment variable). In that case the api-proxy sidecar will return `503` for Gemini requests — a clear, actionable failure rather than a confusing missing-auth error.
166
+
167
+
**Important**: `GEMINI_API_KEY` must be set as a **runner-level environment variable** (e.g. `env: GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}` in the workflow step), not only as a GitHub Actions secret. The AWF process running on the runner must be able to read it so it can pass the key to the api-proxy sidecar container.
168
+
:::
169
+
159
170
:::tip[Placeholder tokens]
160
171
Token variables in the agent are set to `placeholder-token-for-credential-isolation` instead of real values. This ensures:
-`COPILOT_API_KEY` — GitHub Copilot API key (BYOK)
279
+
280
+
:::caution[GitHub Actions: expose keys as runner env vars]
281
+
When running AWF in a GitHub Actions workflow, API keys must be available as **runner-level environment variables** — not just as GitHub Actions secrets. AWF reads the key from the environment at startup to pass it to the api-proxy sidecar container. Use `env:` in the workflow step and `sudo --preserve-env` to ensure keys pass through:
> **Note:** `sudo` strips most environment variables by default. Use `--preserve-env=VAR` (or `sudo -E` to preserve all) to ensure API keys are visible to the AWF process.
291
+
292
+
If the key is present only in `secrets.*` but not exported into the step's `env:`, AWF will warn that no Gemini key was found and the api-proxy Gemini listener will return `503`.
- **Proxy**: Routes via Squid at `http://172.30.0.10:3128`
288
317
289
318
### Health check
@@ -296,14 +325,33 @@ Docker healthcheck on the `/health` endpoint (port 10000):
296
325
297
326
## Troubleshooting
298
327
328
+
### Gemini proxy returns 503
329
+
330
+
When `--enable-api-proxy` is active, `GEMINI_API_BASE_URL` and a placeholder `GEMINI_API_KEY` are always injected into the agent container. If the real `GEMINI_API_KEY` was not set in the AWF runner environment, the api-proxy Gemini listener (port 10003) responds with **503** to all requests.
331
+
332
+
**Solution**: Export `GEMINI_API_KEY` in the runner environment before invoking AWF. In GitHub Actions, add it to the step's `env:` block and use `sudo --preserve-env`:
> **Note:** Exit code 41 ("no auth method") should no longer occur with `--enable-api-proxy` since the placeholder key satisfies the CLI's pre-flight check. If you see exit 41, ensure `--enable-api-proxy` is active.
346
+
299
347
### API keys not detected
300
348
301
349
```
302
350
⚠️ API proxy enabled but no API keys found in environment
303
-
Set OPENAI_API_KEYor ANTHROPIC_API_KEY to use the proxy
351
+
Set OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY, COPILOT_GITHUB_TOKEN, or COPILOT_API_KEY to use the proxy
304
352
```
305
353
306
-
**Solution**: Export API keys before running awf:
354
+
**Solution**: Export API keys before running awf (use `sudo --preserve-env` in CI):
logger.debug('GEMINI_API_KEY set to placeholder value for credential isolation');
1676
+
if(!config.geminiApiKey){
1672
1677
logger.warn('--enable-api-proxy is active but GEMINI_API_KEY is not set.');
1673
1678
logger.warn(` The api-proxy Gemini listener (port ${API_PROXY_PORTS.GEMINI}) will start in fallback mode and return 503 responses until GEMINI_API_KEY is set.`);
1674
1679
logger.warn(' Set GEMINI_API_KEY in the AWF runner environment to enable Gemini credential isolation.');
0 commit comments