feat(bedrock): add AWS SigV4 and STS web identity authentication#5388
Open
skamenan7 wants to merge 2 commits intollamastack:mainfrom
Open
feat(bedrock): add AWS SigV4 and STS web identity authentication#5388skamenan7 wants to merge 2 commits intollamastack:mainfrom
skamenan7 wants to merge 2 commits intollamastack:mainfrom
Conversation
Contributor
|
This pull request has merge conflicts that must be resolved before it can be merged. @skamenan7 please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork |
742fe2a to
4302e2f
Compare
d8c9c75 to
c1851ac
Compare
43847c4 to
47fdbc5
Compare
Contributor
|
This pull request has merge conflicts that must be resolved before it can be merged. @skamenan7 please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork |
47fdbc5 to
21a1f1b
Compare
The Bedrock inference provider previously required a pre-signed bearer token (AWS_BEARER_TOKEN_BEDROCK). This PR adds full AWS credential chain support so Bedrock works natively in EKS/IRSA, GitHub Actions OIDC, EC2, ECS, and Lambda without managing long-lived credentials. When no api_key is configured, requests are signed using AWS SigV4 via botocore. STS role assumption and web identity federation are supported through RefreshableBotoSession, which refreshes credentials automatically. Bearer token mode is unchanged — if api_key is set in config or passed via x-llamastack-provider-data, it takes precedence. Also corrects the endpoint URL from bedrock-mantle to bedrock-runtime.<region>.amazonaws.com/openai/v1, and gates the bedrock model in ci-tests on AWS_DEFAULT_REGION (works for both bearer and SigV4 modes) instead of AWS_BEARER_TOKEN_BEDROCK. Closes llamastack#4730 Signed-off-by: skamenan7 <skamenan@redhat.com>
the provider-compat-matrix pre-commit hook generates this file from recording data; existing bedrock recordings used bedrock-mantle (the old endpoint) so the hook output reflects that correctly Signed-off-by: skamenan7 <skamenan@redhat.com>
21a1f1b to
99db583
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.
What does this PR do?
The Bedrock inference provider previously depended on a pre-signed bearer token (
AWS_BEARER_TOKEN_BEDROCK). That works for short-lived manual setups, but it is a poor fit for environments that already rely on AWS identity, like Kubernetes/OpenShift with IRSA, GitHub Actions with OIDC, EC2, ECS, and Lambda.This PR adds AWS SigV4 support for the Bedrock OpenAI-compatible endpoint using standard AWS credential sources. When no
api_keyis configured, requests are signed with SigV4 via botocore. Static credentials, profiles, IAM roles, and web identity are supported. Whenaws_role_arnis configured, the explicit assume-role and web-identity path usesRefreshableBotoSessionto refresh temporary credentials automatically. Bearer token mode is unchanged: ifapi_keyis set in config or passed viax-llamastack-provider-data, it takes precedence.This also updates the endpoint URL from the legacy
bedrock-mantlehostname tobedrock-runtime.<region>.amazonaws.com/openai/v1.Closes #4730
Auth modes
Bearer token, unchanged:
SigV4 via AWS credentials, new:
STS web identity / IRSA, new:
Per-request bearer override still works on a SigV4-mode server. If
x-llamastack-provider-dataincludes{"aws_bearer_token_bedrock": "<token>"}, that request uses the bearer path. Empty, whitespace-only, or null values fall back to SigV4.Implementation notes
BedrockSigV4Authis anhttpx.Authimplementation that removes the OpenAI SDK placeholderAuthorizationheader and replaces it with a SigV4 signature generated through botocore.httpx.AsyncClientis built once ininitialize()and reused, soget_extra_client_params()can stay synchronous and the adapter does not create a new client per request.asyncio.to_thread()is used so signing and credential resolution do not block the event loop.asyncio.shield()is used around signing and shutdown cleanup so cancellation does not interrupt those operations halfway through.Test plan
Unit tests:
Focused SigV4 unit tests:
Local live validation in SigV4 mode:
Server config with
api_keyintentionally omitted:Validated locally for: