Skip to content

feat: support Amazon Bedrock through the AWS SDK credential chain - #123

Open
kabigon-1015 wants to merge 1 commit into
openai:mainfrom
kabigon-1015:feat/amazon-bedrock-provider
Open

kabigon-1015 wants to merge 1 commit into
openai:mainfrom
kabigon-1015:feat/amazon-bedrock-provider

Conversation

@kabigon-1015

@kabigon-1015 kabigon-1015 commented Jul 23, 2026 •

Copy link
Copy Markdown

Summary

Adds a provider input (openai (default) | amazon-bedrock) so Codex can run against OpenAI models on Amazon Bedrock, authenticating through the AWS SDK credential chain — e.g. short-lived OIDC credentials from aws-actions/configure-aws-credentials — with no long-lived keys stored in the repository.

Addresses #107.

permissions:
  id-token: write
steps:
  - uses: aws-actions/configure-aws-credentials@v4
    with:
      role-to-assume: arn:aws:iam::123456789012:role/codex-bedrock-role
      aws-region: us-east-1
  - uses: openai/codex-action@v1
    with:
      provider: amazon-bedrock
      model: openai.gpt-5.6-sol
      permission-profile: ":read-only"
      prompt: "Review the public change."

Design notes

  • No credential inputs, no credential forwarding. The Codex CLI already resolves AWS credentials and region through the SDK credential chain (env, OIDC web identity, shared config, instance role, AWS_BEARER_TOKEN_BEDROCK), and runCodexExec spawns codex with the inherited environment. The action only selects the provider (--config model_provider="amazon-bedrock") and validates inputs. This keeps the action-side surface minimal and supports every auth method the CLI supports, including enterprise setups where long-lived keys are prohibited.
  • Read server info is skipped for Bedrock. Its current condition (openai-api-key != '' || prompt != '') makes any keyless run with a prompt poll for a server-info file that no proxy ever writes, then fail. This gating fix is required for any proxy-less provider to work.
  • Hardening stays on. drop-sudo, its verification, and the user-namespace setup for the sandbox now also run for the Bedrock path.
  • Fail fast on misconfiguration: openai-api-key combined with provider: amazon-bedrock is rejected (the proxy and the credential chain are mutually exclusive by design), as is a missing AWS_REGION/AWS_DEFAULT_REGION.
  • codex-args still wins. The provider config is pushed before extraArgs, so callers can layer provider settings such as model_providers.amazon-bedrock.aws.profile.

Relationship to #111

#111 pioneered the provider input (thank you @Suto-Michimasa!). This PR takes a different approach to authentication — delegating entirely to the AWS SDK credential chain instead of validating/forwarding specific credential env vars — and additionally fixes the Read server info gating that otherwise fails a keyless run. Happy to converge the two PRs in whichever direction the maintainers prefer.

Known limitations (documented)

  • safety-strategy: unprivileged-user is not supported with Bedrock: sudo resets the environment, so chain-resolved credentials do not reach the Codex process. The README directs users to drop-sudo/read-only.
  • Because there is no proxy, credentials are visible to the Codex process; docs/security.md now recommends short-lived OIDC credentials scoped to Bedrock inference only.

Verification

  • pnpm run check / pnpm run build / pnpm test (4 new unit tests covering the provider flag, default behavior, codex-args ordering, and invalid-provider rejection)

  • End-to-end run on GitHub Actions (ubuntu-latest), pinned to this branch's head SHA: OIDC → aws-actions/configure-aws-credentials (no long-lived keys, no AWS_BEARER_TOKEN_BEDROCK) → provider: amazon-bedrock / model: openai.gpt-5.6-luna / sandbox: read-only. The job succeeded end to end; sanitized log excerpt:

    # proxy install / "Read server info" steps: skipped (no openai-api-key)
    Confirmed sudo privilege is disabled.
    Running: CODEX_HOME=/home/runner/.codex codex "exec" "--skip-git-repo-check" \
      "--cd" "..." "--output-last-message" "..." \
      "--model" "openai.gpt-5.6-luna" \
      "--config" "model_provider=\"amazon-bedrock\"" "--sandbox" "read-only"
    codex> pong
    final-message: pong   # propagated through the action output
    

    This confirms the credential chain path works with OIDC-issued temporary credentials only, the proxy steps are cleanly skipped, and the drop-sudo hardening still runs for the Bedrock path.

🤖 Generated with Claude Code

Add a provider input ('openai' | 'amazon-bedrock') to run Codex against
OpenAI models on Amazon Bedrock without the Responses API proxy.

- Authentication is delegated entirely to the AWS SDK credential chain
  (e.g. short-lived OIDC credentials from
  aws-actions/configure-aws-credentials), so no key input or credential
  forwarding is added.
- Skip proxy installation and the 'Read server info' step when the
  provider is 'amazon-bedrock'; without this, a keyless run with a
  prompt fails after polling for a server info file that no proxy ever
  writes.
- Keep the drop-sudo hardening and user-namespace setup active for the
  Bedrock path.
- Fail fast on conflicting inputs (openai-api-key with amazon-bedrock)
  and on a missing AWS region.
- Document the OIDC setup in the README and the credential-exposure
  trade-off in docs/security.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions

github-actions Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@kabigon-1015

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jul 28, 2026
@kabigon-1015
kabigon-1015 marked this pull request as ready for review July 28, 2026 04:45
@itarakanov

Copy link
Copy Markdown

Thanks for this — we'd use it as soon as it lands. We run Codex as a PR reviewer on Amazon Bedrock with OIDC-only credentials, and today we drive the Codex CLI ourselves because the action can't run without an OpenAI key. The Read server info gating fix here is exactly the first thing blocking us. Three more things would let us switch:

1. Support the amazon-bedrock-runtime provider as well as amazon-bedrock.
The CLI ships both, and they're different endpoints with different IAM:

provider endpoint IAM action model ids
amazon-bedrock bedrock-mantle.{region}.api.aws bedrock-mantle:CreateInference on a project —
amazon-bedrock-runtime bedrock-runtime.{region}.amazonaws.com (Responses API) bedrock:InvokeModel cross-Region inference profiles, e.g. us.openai.gpt-5.6-sol

Our role grants bedrock:InvokeModel only, so hardcoding model_provider="amazon-bedrock" fails with a 403 naming bedrock-mantle:CreateInference. And because model_provider is a restricted root in codex-args (and --config on the command line beats a trusted codex-home/config.toml), there's no way to pick the other one from outside. Accepting provider: amazon-bedrock-runtime would cover it.

2. Allow --ignore-rules under a protected safety strategy, or ignore checkout rules by default.
For a PR reviewer the checkout is untrusted, and execpolicy .rules files in a PR branch can widen which commands the model may run. --ignore-rules only narrows what's allowed, so it seems safe to let through validateProtectedExtraArgs. Having the action skip rules from the working tree in protected runs would work just as well for us.

3. Keep the AWS credentials out of the model's shell commands.
As the PR notes, without the proxy the credentials are visible to the Codex process. They have to be, since they're the model credential, but they don't need to reach the commands the model runs. We do that with a shell_environment_policy that excludes AWS_* in our own config.toml. Since shell_environment_policy is restricted in codex-args, it would be good for the Bedrock path to set it itself, or to document the trusted config.toml route for it.

Happy to test a branch end to end against bedrock-runtime with OIDC credentials if that's useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants