Repository navigation
SigV4 signing, behind a feature - #136
Merged
Merged
Conversation
Bedrock is the one upstream that does not take a bearer token. Every request is signed over its own content — method, URL, time, and a hash of the body — so signing has to happen after the body is final. Change one byte and the signature is void. That constraint is why this belongs next to the transport rather than inside a provider adapter: whoever assembles the final bytes is who can sign them. The desktop app does not reach Bedrock, and `aws-sigv4` plus `aws-credential-types` bring `aws-smithy-*` and a second major version of `http` along with them. Behind a feature, `tw-upstream` is `http` and `reqwest` and nothing else. `SignError` rather than `GatewayError`: the shared layer does not know the caller's error taxonomy, and both gateways have their own. Callers convert at the boundary. Moved as-is from the Bedrock adapter, with the IMDSv2 comment written down — three steps instead of one because the v2 token is fetched with PUT, and an SSRF that can only issue GET cannot walk away with the instance's credentials. Tests pin what the signature has to cover: an authorization header, the payload hash, and a different hash for a different body. That last one is the property the whole scheme rests on. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Merged
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.
Follows #135. Second of the two things the enterprise gateway needs before
tw-providercan go.Why signing belongs next to the transport
Bedrock is the one upstream that does not take a bearer token. Every request is signed over its own content — method, URL, time, and a hash of the body — so signing must happen after the body is final. Change one byte and the signature is void.
Which means whoever assembles the final bytes is who can sign them. That is the transport, not a provider adapter holding a DTO.
Behind a feature
The desktop app does not reach Bedrock, and
aws-sigv4+aws-credential-typesdrag inaws-smithy-*and a second major version ofhttp. With the feature off:Error type
SignError, notGatewayError. The shared layer does not know the caller's error taxonomy — both gateways have their own — so callers convert at the boundary. Same rule the enterprisejson_secret.rsstates for the crypto move.Tests
Three, pinning what the signature must cover: an
authorizationheader,x-amz-content-sha256, and a different hash for a different body. That last one is the property the whole scheme rests on — without it a modified body could replay an old signature.The IMDSv2 comment is written down while moving: three steps rather than one because the v2 token is fetched with PUT, and an SSRF that can only issue GET cannot walk off with the instance's credentials.
clippy --workspace --all-targets -- -D warningsclean with and without the feature; full suite green.🤖 Generated with Claude Code