Fix Codex environment variable override for custom API keys #880
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.
Fixes issue #668 where Codex workflows could not properly override the default
OPENAI_API_KEYsecret, preventing organizations from using custom API keys without secret duplication.Problem
The
codex logincommand was hardcoded to use${{ secrets.OPENAI_API_KEY }}, ignoring any custom environment variable overrides specified in the engine configuration:This caused authentication failures when users tried to use organization-specific API keys, as the login command would always use the default secret regardless of the environment variable override.
Solution
Modified the Codex engine to use the environment variable
$OPENAI_API_KEYinstead of the hardcoded secret reference in the login command:This change allows the login command to respect custom environment variable overrides while maintaining backward compatibility for existing workflows.
Changes
pkg/workflow/codex_engine.goto use environment variable in login commandpkg/cli/workflows/test-codex-custom-env.mddemonstrating the override functionalitydocs/src/content/docs/reference/frontmatter.mdwith detailed examples of secret overridesExample Usage
Organizations can now override the default API key:
The generated workflow will use the custom secret for both the login command and the execution environment, enabling proper authentication with organization-specific API keys.
Backward Compatibility
Existing workflows continue to work unchanged - they still use the default
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}environment variable, which now properly flows through to the login command.Closes #668
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.contoso.com/tmp/go-build2070014085/b279/cli.test -test.testlogfile=/tmp/go-build2070014085/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true(dns block)/tmp/go-build2880104756/b279/cli.test -test.testlogfile=/tmp/go-build2880104756/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true(dns block)/tmp/go-build2129480747/b279/cli.test -test.testlogfile=/tmp/go-build2129480747/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true(dns block)If you need me to access, download, or install something from one of these locations, you can either:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.