bedrock: Add Bedrock API key authentication support#41393
bedrock: Add Bedrock API key authentication support#41393bennetbo merged 16 commits intozed-industries:mainfrom
Conversation
Fixes zed-industries#41312 This adds support for AWS Bedrock API keys (bearer tokens) as an authentication method. Users can now authenticate using: - Traditional access keys (existing) - Bearer tokens via ZED_AWS_BEARER_TOKEN_BEDROCK environment variable (new) - Bearer tokens via UI input field (new) Changes: - Added bearer_token field to BedrockCredentials struct - Added ZED_AWS_BEARER_TOKEN_BEDROCK environment variable constant - Updated authentication logic to check for bearer tokens (read-only from ENV) - Implemented BearerTokenProvider using AWS SDK's ResolveIdentity trait - Modified client initialization to use token_provider when bearer token is present - Enhanced UI with bearer token input field and updated instructions - Updated all help text and tooltips to mention bearer token option Bearer tokens are: - Read from environment variables (never written) - Stored in Zed's credential store when provided via UI - Passed to AWS SDK using the proper token_provider configuration Also includes fix for duplicate Region field (issue zed-industries#41313). References: - AWS Bedrock API Key Documentation: https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys-use.html Co-authored-by: Ona <no-reply@ona.com>
5f4a482 to
c715051
Compare
Replace unwrap() with proper error handling using context() to propagate errors instead of panicking when serializing credentials. Co-authored-by: Ona <no-reply@ona.com>
Support reading credentials from individual environment variables: - ZED_ACCESS_KEY_ID (required) - ZED_SECRET_ACCESS_KEY (required) - ZED_SESSION_TOKEN (optional) - ZED_AWS_REGION (defaults to us-east-1) This provides a more intuitive way to set credentials via environment variables, in addition to the existing ZED_AWS_CREDENTIALS JSON format and ZED_AWS_BEARER_TOKEN_BEDROCK for bearer tokens. Co-authored-by: Ona <no-reply@ona.com>
ZED_AWS_CREDENTIALS_VAR was never meant to be read from environment variables - it was a legacy constant for the credential store key. Credentials are now stored under AMAZON_AWS_URL in the credential store. Environment variables are now properly limited to: - ZED_ACCESS_KEY_ID + ZED_SECRET_ACCESS_KEY + ZED_SESSION_TOKEN (optional) - ZED_AWS_BEARER_TOKEN_BEDROCK - ZED_AWS_REGION Co-authored-by: Ona <no-reply@ona.com>
Improves environment variable handling to match the pattern used by Anthropic provider: - Use LazyLock<EnvVar> for all environment variables - Environment variables are cached and lazy-loaded - Cleaner code with .value and .name accessors - More consistent with other providers in the codebase This provides better performance (cached reads) and cleaner code structure while maintaining the same functionality. Co-authored-by: Ona <no-reply@ona.com>
Follow the AWS SDK Rust pattern for bearer token authentication as documented in release-2025-08-05: - Add HTTP_BEARER_AUTH_SCHEME_ID constant - Use auth_scheme_preference([HTTP_BEARER_AUTH_SCHEME_ID]) when bearer token is present - Create BedrockClient using from_conf() with service-specific config This ensures the SDK properly prefers httpBearerAuth scheme when using bearer tokens, matching the official AWS SDK pattern. Reference: https://github.com/awslabs/aws-sdk-rust/releases/tag/release-2025-08-05 Co-authored-by: Ona <no-reply@ona.com>
|
Sorry for the wait time here @5herlocked, we'll get this reviewed ASAP. |
|
Dw about it -- I know y'all are focused on git stuff! |
Resolved conflicts in: - Cargo.toml: Updated async_zip to 0.0.18, kept PR's aws-config and aws-credential-types versions - crates/language_models/src/provider/bedrock.rs: Added bearer_token_editor field following upstream pattern Co-authored-by: Ona <no-reply@ona.com>
|
No issues! I totally know you're busy. 1/ Good point -- in my mind it was open to interpretation -- but I suppose the OR is pretty descriptive 2/ Absolutely. I'll make the changes rn |
|
Tech Debt cleanup -- writeup Problem StatementThe Bedrock provider had two parallel authentication paths that created confusion and complexity:
This led to several issues:
Design Goals
Solution: Unified
|
| Auth State | Display |
|---|---|
Automatic |
"Using automatic credentials (AWS default chain)" |
NamedProfile { "prod" } |
"Using AWS profile: prod" |
SingleSignOn { "dev" } |
"Using AWS SSO profile: dev" |
IamCredentials (from env) |
"Using IAM credentials from ZED_ACCESS_KEY_ID and ZED_SECRET_ACCESS_KEY environment variables" |
IamCredentials (from keychain) |
"Using IAM credentials" |
ApiKey (from env) |
"Using Bedrock API Key from ZED_BEDROCK_BEARER_TOKEN environment variable" |
ApiKey (from keychain) |
"Using Bedrock API Key" |
Users can only reset credentials when using static credentials (not settings-derived auth).
Backward Compatibility
BedrockAuthMethodenum retained for settings mappingBedrockCredentialsstruct retained for keychain serialization (minusregionfield)- All existing settings continue to work
- Environment variables continue to work
|
Thanks for the suggestion. I'll update the tooltip as you recommended. Regarding the credential isolation approach: we've deliberately chosen to use separate I understand the concern about friction, but I think the benefits outweigh it here. That said, if we see significant pushback from the community, I'm open to revisiting the decision. For now, I'd prefer to keep it as-is given the security and auditability benefits. Worth noting too that we're actively trying to move people away from static credentials entirely, so this specific implementation detail becomes less relevant as we push toward more secure authentication patterns. |
|
I guessed it was deliberate and tried to find the discussion about it, but couldn't. Thanks for the info. |
|
Why is this being accepted when Azure Foundry PR was closed? #43742 I'm thinking whether that PR should be reconsidered in the light of this one. Or then implement this via the extension API if one for that is coming in the near future. |
It's likely because Bedrock is already a existing provider and this PR adds new functionality, while Azure Foundry is a completely new provider. |
bennetbo
left a comment
There was a problem hiding this comment.
Thank you, looks good. Any changes you want to get in @5herlocked or can we merge?
|
Go ahead merge 🚀 |


Closes #41312
Release Notes:
Also includes fix for duplicate Region field (#41341).
References: