feat: add AWS SigV4 auth for OpenAI-compatible model providers#17820
feat: add AWS SigV4 auth for OpenAI-compatible model providers#17820
Conversation
7dbf447 to
8411f07
Compare
b5c6093 to
30c7e0a
Compare
8411f07 to
3f2e856
Compare
d4f7674 to
cbe3a00
Compare
ce18907 to
ea95994
Compare
ad93f1e to
d946bfa
Compare
0a65677 to
bc752c5
Compare
|
not a huge fan of this code that reads region from api key, feels very error prone. so I changed the logic back to reading from config. I can add this back as a fallback if needed. |
| }); | ||
| return Arc::new(AmazonBedrockModelProvider { | ||
| info: provider_info, | ||
| aws, |
There was a problem hiding this comment.
a bit funky to pull out aws from provider_info that already carries it. non blocking
There was a problem hiding this comment.
I think the goal is to eventually pull out provider info so I left this shape, but happy to collapse if you think it's better
| } | ||
|
|
||
| async fn resolve_auth_method(aws: &ModelProviderAwsAuthInfo) -> Result<BedrockAuthMethod> { | ||
| if let Some(token) = bearer_token_from_env() { |
There was a problem hiding this comment.
does amazon sdk not resolve this?
There was a problem hiding this comment.
nope, this is the only one outside of sdk path because it's bearer token based
|
|
||
| async fn context(&self) -> std::result::Result<&AwsAuthContext, AuthError> { | ||
| self.context | ||
| .get_or_try_init(|| AwsAuthContext::load(self.config.clone())) |
There was a problem hiding this comment.
do we ever create without context?
There was a problem hiding this comment.
Seems like with_context always sets a value.
There was a problem hiding this comment.
I think there's some benefit of lazy-loading, so I kept this logic. lmk what you think
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 98df4aab9d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Summary
Add first-class Amazon Bedrock Mantle provider support so Codex can keep using its existing Responses API transport with OpenAI-compatible AWS-hosted endpoints such as AOA/Mantle.
This is needed for the AWS launch path, where provider traffic should authenticate with AWS credentials instead of OpenAI bearer credentials. Requests are authenticated immediately before transport send, so SigV4 signs the final method, URL, headers, and body bytes that
reqwestwill send.What Changed
codex-aws-authcrate for loading AWS SDK config, resolving credentials, and signing finalized HTTP requests with AWS SigV4.amazon-bedrockprovider that targets Bedrock Mantle Responses endpoints, defaults tous-east-1, supports region/profile overrides, disables WebSockets, and does not require OpenAI auth.codex-model-provider: preferAWS_BEARER_TOKEN_BEDROCKwhen set, otherwise use AWS SDK credentials and SigV4 signing.AuthProvider::apply_authandRequest::prepare_body_for_sendso request-signing providers can sign the exact outbound request after JSON serialization/compression.aws.regionconfig first (required for bearer token codepath), and fallback to SDK default region.Testing
Amazon Bedrock Mantle Responses paths:
cargo build.awsprovider usingenv_key = "AWS_BEARER_TOKEN_BEDROCK"streamed rawresponsesoutput withresponse.output_text.delta,response.completed, andmantle-env-ok.codex exec --profile awsturn returnedmantle-env-ok.AWS_PROFILEstill passed, empty env var failed locally, and malformed env var reached Mantle and failed with401 invalid_api_key.amazon-bedrockwithAWS_BEARER_TOKEN_BEDROCKset passed despite bogus AWS profiles, returningamazon-bedrock-env-ok.amazon-bedrockSDK/SigV4 auth passed withAWS_BEARER_TOKEN_BEDROCKunset and temporary AWS session env credentials, returningamazon-bedrock-sdk-env-ok.