Repository navigation
Conversation
|
Great. Upvoted +100 |
Known gap:
|
Add a new highest-priority, opt-in credential tier that routes requests through the Claude Platform on AWS gateway (which does not support OAuth), unblocking the version-controlled Managed Agents workflow on AWS. Selected only by explicit opt-in — the --aws flag or the persistent ANTHROPIC_USE_AWS toggle (not ambient AWS env vars). When active, getDefaultRequestOptions short-circuits before the first-party credential switch and builds request options from the SDK's aws/ backend (SigV4 via the default AWS credential chain, or x-api-key when --aws-api-key is set). All Stainless-generated commands work unchanged over the AWS transport. Changes are confined to hand-written files: - extras.go: register --aws, --aws-region, --aws-workspace-id, --aws-api-key and --aws-base-url global flags (each paired with its env Source). - cmdutil.go: buildAWSConfig helper (workspace falls back to the global --workspace-id), awsHost, awsClientError (adds the CLI flag names to the SDK's "no region / no workspace" errors), the AWS tier-0 short-circuit, and warnIfAWSConflict (warns when --aws overrides a first-party credential, including stdin-supplied keys and Google Cloud settings; excludes --aws-api-key, which only selects API-key mode). All read from the root command, matching the other credential flags. Like the Google Cloud tier, --base-url / ANTHROPIC_BASE_URL is not applied under --aws (a one-shot notice says so), so AWS credentials never go to a host configured for Anthropic credentials; --aws-base-url / ANTHROPIC_AWS_BASE_URL is the only gateway override. Like the Google Cloud tier, --base-url / ANTHROPIC_BASE_URL is not applied under --aws (a one-shot notice says so), so AWS credentials never go to a host configured for Anthropic credentials; --aws-base-url / ANTHROPIC_AWS_BASE_URL is the only gateway override. - cmd_auth.go: awsAuthStatus renders AWS as the tier-0 winner with the active mode label and backend-resolved base URL, redacting the API key. - apply.go: `ant apply` records the AWS gateway as the origin host, names the AWS credentials, and never treats a profile as in use under --aws. - cmd_aws_test.go: buildAWSConfig pass-through and workspace fallback, --base-url not used under --aws, client error hints, --base-url not used under --aws, client error hints, conflict warning fires/silent, auth status row, apply origin, and the cross-site precedence invariant. go.mod only records the AWS SDK transitive indirect deps that the anthropic-sdk-go aws/ subpackage newly makes reachable.
47d2c0e to
168cccb
Compare
dtmeadows-ant
left a comment
There was a problem hiding this comment.
Thanks so much for putting this up! I think with a few tweaks we should be able to get this out the door.
- Could we add a small section to the README about this?
- Could you scope out if we need to redact
X-Amz-Security-Tokenanywhere specific, eg in--debughandling?
|
|
||
| fmt.Fprintln(out) | ||
| fmt.Fprintln(out, "Credentials") | ||
| apiKey := root.String("aws-api-key") |
There was a problem hiding this comment.
We're trying to move away from supporting credentials like this as standard options. Could we move this to only support ANTHROPIC_AWS_API_KEY and --aws-api-key-stdin?
There was a problem hiding this comment.
Makes sense. --aws-api-key is gone; it's now just ANTHROPIC_AWS_API_KEY or --aws-api-key-stdin. The stdin flag goes through the same path as --api-key-stdin, so it gets the same level of checks
| } | ||
| // Credential precedence mirrors the WIF User Guide's "Credential resolution" section: | ||
|
|
||
| // Tier 0 — Claude Platform on AWS. Opt-in only (--aws / ANTHROPIC_USE_AWS, |
There was a problem hiding this comment.
I think a lot of these comments could get trimmed down a bit. Most of the code here I think can speak for itself so I don't think we need to spell out exactly what the code's doing. Maybe look at the comments for the other provider(s) we've added support for to calibrate on what the right length should be?
There was a problem hiding this comment.
Fair call, they'd got a bit out of hand (and i should have stripped Opus 5's verboseness) . I took your pointer to the Google tier further and rebuilt the AWS one to match it. It lives in pkg/cmd/aws.go, shaped like google_cloud.go (an awsPlatform with AnySet(), host(), noteIgnoredBaseURL() and requestOptions()), and the case in getDefaultRequestOptions is about as long as the Google one now. Comments are trimmed to match.
It also behaves like the Google tier now. --aws / ANTHROPIC_USE_AWS are gone. Setting --aws-region, --aws-workspace-id or ANTHROPIC_AWS_WORKSPACE_ID turns the tier on, and AWS_REGION / AWS_PROFILE on their own don't, for the same reason the Google tier ignores GOOGLE_CLOUD_PROJECT. It sits in the same place in the precedence order: an API key, auth token, named profile, federation or Google Cloud settings win over it, and it wins over the implicit profile. It also uses the shared multi-auth notice and a normal auth status row.
The two places it still differs are both down to AWS itself. There's the Console API key option. And --workspace-id isn't sent on the AWS path, because there the workspace is a header (it's in the URL on Google), so the first-party one would overwrite it. I've updated the --workspace-id help to point at --aws-workspace-id, since it used to say it was required on AWS.
There was a problem hiding this comment.
Could we add some tests asserting the actual contents of the request itself? Those are pretty necessary to ensure we're not misformatting any important headers or URLs for things like authorization. Feel free to borrow from pkg/cmd/google_cloud_test.go.
There was a problem hiding this comment.
Agreed, they were missing. Again i borrowed from the Google implementation and now have tests for
- host
aws-external-anthropic.<region>.api.awsand the path - the
Authorizationcredential scope (key, date, region,aws-external-anthropic,aws4_request), withhost,x-amz-dateandanthropic-workspace-idinSignedHeaders X-Amz-Security-Tokenwhen there's a session token- API-key mode sends
x-api-keyand noAuthorization, from the env var or--aws-api-key-stdin - the workspace header is sent once, and
--workspace-iddoesn't override it --aws-base-urlis honoured, and--base-url/ANTHROPIC_BASE_URLnever get the request
There's also a table test of what does and doesn't turn the tier on, precedence against an API key, named profile, Google and the implicit profile, TestAuthStatusAWS on the shared runStatus (same checks as the Google one), and the ant apply origin. The file's renamed to aws_test.go to pair with aws.go.
Address review on anthropics#61: - Move the tier into pkg/cmd/aws.go, shaped like google_cloud.go: an awsPlatform carrier with host(), noteIgnoredBaseURL() and requestOptions(). Comments trimmed to match. - Selection and precedence match the Google Cloud tier. --aws-region, --aws-workspace-id or ANTHROPIC_AWS_WORKSPACE_ID select AWS (AWS_REGION and AWS_PROFILE on their own don't); --aws / ANTHROPIC_USE_AWS are gone. An API key, an auth token, a named profile, federation and Google Cloud settings win over AWS; AWS wins over the implicit profile. AWS is a source in the shared multi-auth notice and a row in `ant auth status`, replacing the separate short-circuit, status view and conflict warning. - Replace the --aws-api-key flag with --aws-api-key-stdin, read through the shared stdin-credential path; ANTHROPIC_AWS_API_KEY still works. - Redact X-Amz-Security-Token in --debug output. - Tests assert the request itself (gateway host and path, the SigV4 Authorization credential scope and signed headers, the session token, x-api-key, the workspace header), plus precedence, auth status and `ant apply` origin. - README: a Claude Platform on AWS section next to the Google Cloud one.
|
Thanks heaps for the review. Everything below is in the latest push. README: there's a "Claude Platform on AWS" section straight after the Google Cloud one, same layout. It also mentions that an AWS Console API key only works in the region it was generated in, because the gateway's 401 for a mismatch ("Credential should be scoped to a valid region") doesn't make that obvious. X-Amz-Security-Token: good catch, it was leaking. With temporary creds (IRSA, SSO, an assumed role, so most CI) I also looked for anywhere else it could surface. The SDK's I've re-run everything live against a Claude Platform on AWS workspace: SigV4 with an assumed role, the Console API key through both the env var and |
Summary
Adds a Claude Platform on AWS credential tier, built the same way as the Claude Platform on Google Cloud tier that landed in 1.40.0.
Today the CLI can reach an AWS workspace only by hand-setting an AWS Console API key,
--base-url https://aws-external-anthropic.<region>.api.awsand--workspace-id. There's no way to sign requests with SigV4, so IAM roles, SSO and IRSA don't work, and that's what CI on AWS uses. This blocks the version-controlled Managed Agents workflow (ant apply,ant beta:agents create < agent.yaml) on AWS.How it works
Setting
--aws-region,--aws-workspace-idorANTHROPIC_AWS_WORKSPACE_IDselects the tier.AWS_REGIONandAWS_PROFILEon their own don't, because most AWS machines set them for unrelated reasons (the Google tier ignoresGOOGLE_CLOUD_PROJECTfor the same reason). The region falls back toAWS_REGION, thenAWS_DEFAULT_REGION.Requests go through the SDK's
aws/package, in one of two modes:AWS_PROFILE, environment keys, an IAM role).ANTHROPIC_AWS_API_KEYor--aws-api-key-stdin, sent asx-api-key. The key only works in the region it was generated in.It sits in the same place as the Google tier in the precedence order. An API key, an auth token, a named profile, federation or Google Cloud settings win over it, and it wins over the implicit profile. AWS shows up in the shared multi-auth notice and as a normal row in
ant auth status.AWS credentials are only sent to the gateway.
--base-url/ANTHROPIC_BASE_URLaren't used (a one-off notice says so), and--aws-base-url/ANTHROPIC_AWS_BASE_URLoverrides the gateway URL.Compared with the Google Cloud tier
google_cloud.goaws.go, same shape:AnySet(),host(),noteIgnoredBaseURL(),requestOptions()--google-cloud-*/ANTHROPIC_GOOGLE_CLOUD_*--aws-region,--aws-workspace-id,ANTHROPIC_AWS_WORKSPACE_IDGOOGLE_CLOUD_PROJECTAWS_REGION,AWS_PROFILE--google-cloud-base-url--aws-base-urlauth status,ant applyoriginThe differences come from AWS itself: there's a Console API key option, and the first-party
--workspace-idheader isn't sent on the AWS path because the workspace travels as a header there (on Google it's part of the URL) and would otherwise be overwritten.What changed
All hand-written files. No generated command files are touched.
pkg/cmd/aws.go(new): the tier.pkg/cmd/cmdutil.go: the AWS case in the precedence switch, and AWS inwarnIfMultipleAuthSources.pkg/cmd/extras.go:--aws-region,--aws-workspace-id,--aws-api-key-stdin,--aws-base-url. The--workspace-idhelp now points at--aws-workspace-idinstead of saying it's required on AWS.pkg/cmd/credential_stdin.go:--aws-api-key-stdinjoins the existing stdin-credential path.pkg/cmd/cmd_auth.go: the AWS row and gateway inant auth status.pkg/cmd/apply.go:awsInUse, soant applyrecords the AWS gateway as the lockfile origin and names the credentials correctly.internal/debugmiddleware:X-Amz-Security-Tokenis redacted in--debugoutput.README.md: a Claude Platform on AWS section after the Google Cloud one.go.mod/go.sum: the AWS SDK modules theaws/package pulls in. Theanthropic-sdk-goversion is unchanged.Tests
pkg/cmd/aws_test.gofollowsgoogle_cloud_test.go: it captures requests at the transport, after signing, with no network.TestAWSTier: gateway host and path, the SigV4 credential scope and signed headers,X-Amz-Security-Tokenwith temporary credentials,x-api-keyfrom the env var and from stdin, the workspace header sent once,--aws-base-urlused and--base-urlnever.TestAWSSelection: what does and doesn't turn the tier on.TestAWSPrecedence: against an API key, a named profile, Google Cloud and the implicit profile.TestAuthStatusAWS,TestAWSInUse,TestAWSCredentialsError.go test ./...passes apart from the generated command tests, which need the mock server onlocalhost:4010.Live, 14 Oct 2026
Against a Claude Platform on AWS workspace:
us-east-1)auth status,messages create200,beta:agentscreate, list, retrieve, update with optimistic locking, archive, error cases; session token redacted in--debugant apply(SigV4)--prune; lockfile origin is the regional gatewayANTHROPIC_AWS_API_KEY(ap-southeast-2)--aws-api-key-stdin--debugNot covered
ant beta:workerdoesn't work on AWS yet. The SDK's worker helper needs an environment key, and AWS workers authenticate with IAM. Details and the SDK issue are in this comment.