feat(parser_http_server): validate X-Stamp in the enclave - #451
Draft
pepe-anchor wants to merge 1 commit into
Draft
feat(parser_http_server): validate X-Stamp in the enclave#451pepe-anchor wants to merge 1 commit into
pepe-anchor wants to merge 1 commit into
Conversation
Turnkey's gateway authenticates callers against their DB and we lose that when the pivot becomes the front door. Keep the X-Stamp wire shape, move validation into the pivot against a pubkey allowlist pinned via pivotArgs (same delivery as --gateway-signing-pubkey-hex, so rotation is a redeploy and nothing new to build). Verification runs against the raw body bytes. A Json<T> round-trip re-serializes and changes them, so the seam PR 3 cut (handlers take Bytes) is what makes this correct; there is a test that pins it. What we give up versus the DB check: per-org identity, activity policy, instant revocation. Acceptable while the caller set is small and known; the signed-allowlist option is the follow-up if rotation gets painful. Co-Authored-By: Claude <noreply@anthropic.com>
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.
Why
Today Turnkey's gateway authenticates every caller: it validates
X-Stampagainst Turnkey's own DB before the request reaches us. When the pivot becomes the front door, we lose that, and the pivot currently has zero authentication (the runbook's smoke test is a plaincurl).This keeps the
X-Stampwire shape and moves validation into the enclave, against a pubkey allowlist pinned at deploy time.What
stamp.rs:Allowlist,StampError, andverify(&HeaderMap, &[u8], &Allowlist). Header value is base64url-no-pad JSON{publicKey, signature, scheme},publicKeyhex compressed SEC1,signaturehex DER, over the raw body. Both P256 and secp256k1 schemes.--allowed-stamp-pubkeys-hex/ALLOWED_STAMP_PUBKEYS_HEX, delivered throughpivotArgs, the same mechanism that already pins the gateway signing pubkey. Rotation costs a redeploy but no rebuild and no new trust root.subtle. A timing signal here leaks which keys are allowlisted.bootProoflike every other response, and the error text is deliberately coarse ("invalid or missing X-Stamp") so it cannot be used to probe the allowlist.Test evidence
Stamps in tests are produced by
turnkey_api_key_stamperitself, so the real producer is exercised rather than our own re-implementation of it.One thing worth flagging in review: the raw-bytes test initially passed for the wrong reason. This workspace builds
serde_jsonwithpreserve_order(it pullsindexmap), so an alphabetically-ordered fixture round-trips byte-identical throughValueand the test proved nothing. The fixture now differs by insignificant whitespace, which compact output always drops regardless of key ordering, so the test has real teeth.Open questions before this merges
request_hash, so it cannot be redirected at a different transaction.GATEWAY_AUTH_BEARER_TOKEN: keep it. The gateway is internet-facing and sees unauthenticated x402 discovery traffic before any stamp exists on a request. It is a different trust boundary from the enclave hop this PR protects, and it is already an optional flag, so there is no cost to keeping defense in depth.Rollback
Revert the commit, or simply stop passing
--allowed-stamp-pubkeys-hex: with no allowlist configured the routes behave exactly as before this PR.Linear
PRS-581
Stacked on #450.
🤖 Generated with Claude Code