feat(config): api_key_helper — dynamic API keys from a shell command#236
Merged
emal-avala merged 1 commit intomainfrom Apr 24, 2026
Merged
feat(config): api_key_helper — dynamic API keys from a shell command#236emal-avala merged 1 commit intomainfrom
emal-avala merged 1 commit intomainfrom
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
527a513 to
6a27382
Compare
Adds `api.api_key_helper`: a shell command that prints an API key to stdout. When no static key has been resolved from file or env, the helper is executed via `bash -c` and its trimmed stdout becomes the session key. Use case: pull a short-lived key from a secrets manager (vault, 1Password, `aws sts`, `gcloud auth print-access-token`, …) instead of pinning a long-lived key to disk. Resolution order: 1. CLI / env vars (highest) 2. `config.toml` `api.api_key` 3. **`api.api_key_helper` output** ← new fallback 4. None → operator error surfaces as before The helper field is marked `skip_serializing` (same contract as `api_key`) so it never lands in a dumped config. Leak-safe diagnostics: helper errors are categorized via a private `ApiKeyHelperError` enum (`SpawnFailed` / `NonZeroExit` / `InvalidUtf8`). Only the category string is logged — never raw subprocess stdout or stderr, either of which could carry the key. Tests: - default is None; parses from TOML; not serialized - trims trailing newline from stdout - non-zero exit is categorized as NonZeroExit - stderr contents never appear in the logged category - multi-line output trimmed only at edges - full category-mapping coverage guard
6a27382 to
75c672a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
api.api_key_helper: an optional shell command whose trimmed stdout becomes the session API key. Intended for sourcing short-lived tokens from a secrets manager (vault, 1Password,aws sts,gcloud auth print-access-token, …) without pinning a long-lived key to disk.Resolution order (unchanged behavior when helper is unset)
config.tomlapi.api_keyapi.api_key_helperstdoutConfiguration example
The helper is executed via
bash -c, so pipelines and env interpolation work out of the box.Guarantees
skip_serializing, same asapi_key, so dumped configs can't leak it.ApiKeyHelperErrorcategory (SpawnFailed/NonZeroExit/InvalidUtf8). Thewarn!log only emits the category string, never raw stdout or stderr (either of which could contain the API key itself).Tests (10)
Schema (3):
NoneRuntime (7, unix-only since they shell out to
bash):echoresult is trimmedNonZeroExitNonZeroExitcategory()mapping guard for future variantsFull
config::suite: 107 pass, 0 fail. Clippy clean.Test plan
cargo test -p agent-code-lib --lib configcargo clippy --workspace --tests --no-deps -- -D warningscargo fmt --all --check