Skip to content

SigV4 signing, behind a feature - #136

Merged
fylorn merged 1 commit into
mainfrom
feat/sigv4-in-upstream
Sep 23, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/sigv4-in-upstream

Conversation

@fylorn

@fylorn fylorn commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Follows #135. Second of the two things the enterprise gateway needs before tw-provider can 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-types drag in aws-smithy-* and a second major version of http. With the feature off:

tw-upstream v0.31.0
├── http v1.5.0
└── reqwest v0.13.4

Error type

SignError, not GatewayError. 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 enterprise json_secret.rs states for the crypto move.

Tests

Three, pinning what the signature must cover: an authorization header, 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 warnings clean with and without the feature; full suite green.

🤖 Generated with Claude Code

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>
@fylorn
fylorn merged commit cc056f0 into main Sep 23, 2026
2 checks passed
@fylorn
fylorn deleted the feat/sigv4-in-upstream branch September 23, 2026 11:04
@fylorn fylorn mentioned this pull request Sep 23, 2026
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