Repository navigation
feat: read DOCKER_AGENT_ENV_-prefixed secret variables - #4708
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Doctor can report an available credential that runtime ignores when a higher-priority source contains an empty override.
1 open issue
What changed in this PR
Adds Docker Agent-specific secret overrides so users can keep separate credentials or 1Password references without affecting other tools that share the standard environment variable names.
Changes:
- Introduces
DOCKER_AGENT_ENV_lookup precedence across default sources and--env-from-file. - Updates doctor to recognize overrides and report their names through
found_as. - Adds precedence tests and documents usage, empty-value fallback, and limitations.
| File | Description |
|---|---|
pkg/environment/prefixed.go |
Adds override lookup with settings-namespace protection. |
pkg/environment/prefixed_test.go |
Tests precedence, fallback, and namespace isolation. |
pkg/environment/default.go |
Centralizes override and 1Password provider composition. |
pkg/environment/default_test.go |
Tests override precedence across default sources. |
pkg/config/runtime.go |
Includes explicit env files in the shared secret chain. |
pkg/config/runtime_test.go |
Tests precedence between env files and default sources. |
docs/guides/secrets/index.md |
Documents overrides and transcription/sandbox limitations. |
cmd/root/doctor.go |
Recognizes overrides and reports credential source names. |
cmd/root/doctor_test.go |
Tests doctor selection, reporting, and override lookup. |
Review effort: Balanced
| if value, ok := s.Provider.Get(ctx, candidate); ok && value != "" { | ||
| return s.Name, candidate, true | ||
| } |
There was a problem hiding this comment.
Good catch, fixed in fff6189, but on the runtime side rather than in doctor: the docs say an empty override is ignored, so the empty shell value should not hide the env-file override. PrefixedProvider now takes the sources and skips empty overrides source by source, which is what findSource already did. --env-from-file goes through the same NewChain, so it is covered too.
Regression tests: TestPrefixedProvider_EmptyOverrideDoesNotHideLaterSources (runtime) and TestFindSource_EmptyOverrideDoesNotHideLaterOverride, which also asserts doctor and the run-time chain agree.
2cc8ba1 to
fff6189
Compare
|
👋 Some commits in this PR are not signed and verified by GitHub. Please sign your commits with a GPG or SSH key registered in your GitHub account, then force-push.\n\nCommits that are not verified: |
DOCKER_AGENT_ENV_<NAME> now shadows <NAME>, so docker-agent can get its own value (e.g. an op:// reference) for variables that other tools such as Claude Code and Codex also read. - One chain constructor, NewChain, serves the default chain and --env-from-file, so the override spans every source; op:// values in --env-from-file are now resolved as well. - An empty override falls back to <NAME>. - The prefix is a sub-namespace of DOCKER_AGENT_ and settings in that namespace are never looked up as overrides, so can never resolve to DOCKER_AGENT_REMOTE_AUTH_TOKEN. Refs #4702 Signed-off-by: Arnaud Héritier <aheritier@apache.org>.
Doctor's lookup env honours the override, so auto-selection and agent-file checks match the provider table. findSource checks the override across all sources first, mirroring the run-time chain. env_var stays the canonical name; the override name is reported as found_as. Refs #4702 Signed-off-by: Arnaud Héritier <aheritier@apache.org>
Refs #4702 Signed-off-by: Arnaud Héritier <aheritier@apache.org>
…sources PrefixedProvider read overrides through a MultiProvider, which stops at the first source that defines the variable, even when empty. An empty shell DOCKER_AGENT_ENV_X therefore hid a DOCKER_AGENT_ENV_X in the docker-agent env file, while doctor reported the latter as found. PrefixedProvider now takes the sources and skips empty overrides source by source, matching doctor and the documented behavior. Signed-off-by: Arnaud Héritier <aheritier@apache.org>
fff6189 to
f630e5b
Compare

Closes #4702
Summary
docker-agent shares variable names with other tools: Claude Code reads
ANTHROPIC_API_KEY, Codex readsOPENAI_API_KEY. ExportingANTHROPIC_API_KEY="op://…"to benefit from 1Password references breaks those tools, which do not resolveop://.docker-agent now looks up
DOCKER_AGENT_ENV_<NAME>before<NAME>:Changes
pkg/environment:PrefixedProviderandLookupNames; a singleNewChainconstructor (OnePassword(Prefixed(Multi(...)))) used byNewDefaultProviderand by--env-from-fileinpkg/config/runtime.go.docker agent doctor: its lookup env honours the override (auto-selection, agent-file checks),findSourcemirrors the run-time order, and the name found is reported as a new optionalfound_asJSON field;env_varstays the canonical name.Behavior decisions
DOCKER_AGENT_ENV_, notDOCKER_AGENT_.DOCKER_AGENT_is docker-agent's settings namespace (DOCKER_AGENT_REMOTE_AUTH_TOKEN,DOCKER_AGENT_ENCRYPT_KEY,DOCKER_AGENT_DATA_DIR, …). With a bareDOCKER_AGENT_prefix, an MCP${REMOTE_AUTH_TOKEN}would resolve to docker-agent's own token. Names already inDOCKER_AGENT_are never looked up as overrides.--env-from-fileincluded.<NAME>, so a blank line orexport X=cannot hide a valid key. Doctor and the runtime agree on this.Side effect:
op://values in--env-from-filewere not resolved before (env files sat outside the 1Password wrapper, although the docs said they were); they are now.Out of scope
OPENAI_API_KEYwithos.Getenv, bypassing the chain. Fixing it needs lazy resolution inpkg/audio/transcribeto avoid anopprompt on every TUI launch; follow-up PR. Documented.--sandboxproxy are not read through the chain; documented.Tests
PrefixedProvidertable test asserting value and names looked up, including the settings-namespace case that would have leaked.NewDefaultProviderandRuntimeConfig.EnvProvider: overrides span the default chain and--env-from-filein both directions.doctor: auto-selection with only the override set and DMR down (mutation-checked), JSONenv_var/found_as, agent-file requirements,findSourceprecedence and empty-override fallback.References
pkg/environment/default.go--env-from-filechainpkg/config/runtime.go(computedEnvProvider)pkg/environment/onepassword.go, 1Password CLIop readpkg/sandbox/sandbox.go(EnvForSource,proxyManagedEnvVars)docs/guides/secrets/index.mdThis is part 1 of 2 in a stack made with GitButler: