Skip to content

Sign Claude on Bedrock with an AWS profile or the current AWS login - #202

Open
Itay Kalfon (Itaykal) wants to merge 1 commit into
microsoft:mainfrom
Itaykal:bedrock-aws-profile
Open

Itay Kalfon (Itaykal) wants to merge 1 commit into
microsoft:mainfrom
Itaykal:bedrock-aws-profile

Conversation

@Itaykal

Copy link
Copy Markdown

Linked issue

No prior issue. Some orgs don't issue Bedrock API keys and only allow access through AWS IAM / SSO, so today Freehand can't reach Claude on Bedrock for them.

What changed (Before / After)

  • Before: Bedrock only works with a Bedrock API key (AWS_BEARER_TOKEN_BEDROCK).
  • After: a new bedrock-aws service signs Claude-on-Bedrock requests with the person's AWS sign-in, either a named profile or whatever the AWS CLI uses now (AWS_PROFILE, aws sso login, env vars, assume-role, credential_process). Freehand saves no secret.
Agent.call_model
  credentials()                       auth "aws"
    auth.aws_credentials(aws_profile)    boto3 Session -> frozen creds (cached; re-read on force_refresh)
  Anthropic.send
    anthropic_client(aws=creds)          anthropic.AnthropicBedrock, region from the bedrock-runtime host
      POST /model/{id}/invoke-with-response-stream   (SigV4)
  on 403 -> re-read the AWS sign-in once (picks up a renewed `aws sso login`)
 SERVICES
   bedrock          Claude, Bedrock API key
   bedrock-openai   Chat Completions, Bedrock API key
+  bedrock-aws      Claude, auth "aws" + optional "aws_profile"
 pyproject
+  [bedrock] = boto3, botocore     # optional, like [vertex]

This follows the existing Vertex pattern (auth: "google"): freehand login bedrock-aws [--region R] [--aws-profile NAME], the terminal /login menu, and the web Settings page (tile, region, profile field, "AWS sign-in" in Advanced). Only Claude (the Anthropic Messages route) is covered; bedrock-openai stays key-only.

Visual proof (UI / TUI / Web / Desktop / export changes)

$ freehand login bedrock-aws --region eu-west-1 --aws-profile work
New sessions use Amazon Bedrock (AWS sign-in) in eu-west-1 with the AWS profile work.
$ freehand login bedrock-aws --aws-profile nope
There is no AWS profile named 'nope' in ~/.aws/config or ~/.aws/credentials. Nothing was saved.

Web: the "Amazon Bedrock (AWS sign-in)" tile ("AWS profile or current login, no key") asks for the region and profile, and shows no key field. A browser e2e test covers this (below).

How you verified it

  • tests/test_bedrock_aws.py (new) runs the real SDK signing path against a fake Bedrock that streams AWS event-stream frames (FakeAnthropic(bedrock=True)):
    • requests carry AWS4-HMAC-SHA256 Credential=<profile's key>/…/bedrock/aws4_request, with no x-api-key, even when AWS_BEARER_TOKEN_BEDROCK is set
    • a 403 re-reads the credentials once; I checked this test fails when the retry is removed
    • unknown profile or no sign-in gives a NeedLogin that says to run aws sso login --profile …
    • region parsing for regional, FIPS and VPC endpoints; a lookalike host is rejected
    • connection validation refuses auth: "aws" anywhere but Claude on a bedrock-runtime host
    • CLI and terminal login flows
  • tests/test_web_e2e.py::test_web_e2e_bedrock_is_added_with_an_aws_profile_and_no_key (real browser)
  • tests/conftest.py now hides the machine's ~/.aws and AWS variables from every test, so a developer's own AWS login can't change results
  • Core suite: 3 shards green locally. Manual: signed in with a real SSO profile and chatted with global.anthropic.claude-opus-5-5 on Bedrock.

Merge danger

Door: two-way. A new opt-in service and auth mode. Existing bedrock / bedrock-openai connections and every other provider are unchanged.

Blast radius: small. Shared code touched: connections.identity() gains aws_profile (so two profiles are two connections), USER_SETTINGS/PROVIDER_SETTINGS gain aws_profile, and boto3 is added to the dev extra so CI runs the real SigV4 path. src/freehand/runtime/ stays stdlib-only: boto3 is imported lazily, only when auth is aws.

AI disclosure & checklist

  • AI disclosure: AI-assisted (personally tested and verified)
  • uv run pyflakes src tests .github/scripts prints nothing and relevant tests pass locally (full suite runs in CI)
  • Left CHANGELOG.md untouched (maintainers update it at release time)
  • No change to what the model sees (prompt, tool descriptions, status line, notes), or benchmark evidence attached
  • src/freehand/runtime/ still uses only the standard library and imports on Python 3.9

🤖 Generated with Claude Code

A new bedrock-aws service (auth "aws") signs requests with SigV4 through the
Anthropic SDK's Bedrock client instead of a Bedrock API key. Credentials come
from boto3 (new optional extra freehand-ai[bedrock]): the named aws_profile,
or the AWS CLI's default chain (AWS_PROFILE, SSO, env vars) when none is set.
A 403 re-reads the sign-in once, so a renewed `aws sso login` is picked up.

Available from `freehand login bedrock-aws [--region R] [--aws-profile NAME]`,
the terminal /login menu, and the web Settings page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

Thanks for the pull request! A few friendly reminders based on the files changed:

  • Model-facing / runtime core: This PR touches benchmark-sensitive or Python 3.9 stdlib runtime files (src/freehand/runtime/agent.py, src/freehand/runtime/auth.py, src/freehand/runtime/providers.py). Please make sure Python 3.9 stdlib imports still pass and attach benchmark evidence if model-visible behaviour changed.

(This comment updates automatically when you edit the PR description or push new commits.)

@Itaykal

Copy link
Copy Markdown
Author

Itay Kalfon (@Itaykal) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
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.

1 participant