Azure / Azure/azure-rest-api-specs

sdk-generation-agent: GITHUB_TOKEN in workflow-level `env` is visible to the agent container

Open
#44,982 0 comments 0 reactions 1 assignee Claimed by @praveenkuttappan View on GitHub
Dominant language
TypeSpec
Stars
3.1k
Forks
5.9k
Avg merge
3d 2h
Merged PRs (30d)
424

Description

## Summary

`gh aw compile` reports a warning on `.github/workflows/sdk-generation-agent.md` that I don't think can be resolved without input from the workflow owner:

```
⚠ Warning: secrets detected in 'env' section will be leaked to the agent container.
Found: ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}
Consider using engine-specific secret configuration instead.
```

The source is the workflow-level `env` block:

```yaml
env:
AZSDK_CLI_PATH: /tmp/bin
AZURE_CLIENT_ID: ...
AZURE_TENANT_ID: ...
GITHUB_TOKEN: ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}
```

This was added deliberately in e28e6cd2e53f ("Sdk generation agent auth changes", #40598), so I did not want to change it unilaterally.

## Why it matters

`sdk-generation-agent` is triggered by `issues` (`opened`, `labeled`) and `issue_comment` (`created`). The workflow's own prompt acknowledges that issue and comment bodies are untrusted input. Because `GITHUB_TOKEN` is set at the workflow level, it is present in the environment of the agent container, so anything that successfully influences the agent's behavior can read a PAT (`GITHUB_PERSONAL_ACCESS_TOKEN`) whose scopes are likely broader than the per-run `secrets.GITHUB_TOKEN`.

Mitigations already in place: `tools.github.min-integrity: approved`, and the `Run sdk generation` label gate.

## What I already ruled out

- **`gh aw fix`** refuses to auto-fix this one — it reports `codemod top-level-env-secrets-guided-error ... Manual fix required: move the secret into engine-specific secret configuration.`
- **Moving it to `engine.env`** would take it away from the imported setup steps (`shared-github-aw-imports/install_azsdk_cli_import.md`, `global_networks_auth_import.md`), which inherit the workflow-level `env`. Per the [gh-aw engines reference](https://github.github.com/gh-aw/reference/engines/), only `COPILOT_PROVIDER_*` credentials are treated as non-leaking in `engine.env` anyway, so this may not even clear the warning.
- **Removing it entirely** would presumably break the `azsdk` CLI calls the agent makes (`azsdk release-plan get/update`, `azsdk spec-workflow generate-sdk`).

## Questions for the owner

1. Which consumers actually need `GITHUB_TOKEN`? The `azsdk` CLI invoked by the agent, the `azsdk-mcp` installer step, or both?
2. Is the `GITHUB_PERSONAL_ACCESS_TOKEN` fallback still required, or would the per-run `secrets.GITHUB_TOKEN` suffice? Dropping the PAT would shrink the blast radius considerably while keeping the workflow working.
3. If the PAT is required, what scopes does it carry? That determines how serious "visible to the agent container" actually is here.

## Context

Found while recompiling the agentic workflows from gh-aw v0.68.1 to v0.83.1. The other compiler warnings (outdated `actions/checkout@v6` and `actions/github-script@v7`, and the `pull_request_target` checkout lint on `hero-scenarios`) are fixed in that PR; for this one I only added an explanatory comment above the `env` entry so the next person doesn't try to "fix" it blindly.

Filed by GitHub Copilot on behalf of @xirzec.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.