Repository navigation
feat(server): give signature verification its own option, separate from the credential registry (#630) - #767
Merged
Conversation
…om the credential registry (#630) ServerOptions.Credentials did two unrelated jobs and there was no way to ask for one without the other: non-nil meant both "resolve accounts from this table" and "enforce SigV4 on every request". So a test needing a second account had to accept that every request in it be signed with a pre-loaded key — including substrate's own documented credentials, which are in no registry and answer InvalidClientTokenId 403. ServerOptions.VerifySignatures makes all four combinations expressible. The one that did not exist before, a registry with verification off, is what every test server now uses. The decision that made this local rather than repo-wide: the buildCallerARN fallback for a registry key with no IAM entity behind it belongs to *verification*, not to account resolution. A verified key has proven the caller holds the secret; a key merely present in a table has proven nothing. Without that split, wiring a registry into every test server would flip GetCallerIdentity's ARN off :root and turn GetUser into a NoSuchEntity lookup everywhere at once, and the issue's own "no existing test changes behaviour" criterion would be unreachable. StartTestServer now takes options — WithAccounts and WithSignatureVerification — RegisterAccount works on any test server, and StartTestServerWithAccounts is a thin wrapper keeping the stricter contract its callers were written against. VerifySignatures with a nil registry logs a warning and downgrades to off. The issue asked for a construction-time refusal; NewServer returns no error and changing that signature reaches ~42 test files plus the CLI, so the criterion is recorded as rewritten rather than met. Closes #630
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
ServerOptions.Credentialsanswered two unrelated questions with one field. Non-nil meant both "resolve accounts from this table" and "enforce SigV4 on every request that carries an Authorization header". A test that needed to call as a second account therefore had to accept that every request in it be signed with a pre-loaded key — including substrate's own documented credentials (AKIAIOSFODNN7EXAMPLE,test/test), which are in no registry and answerInvalidClientTokenId403.ServerOptions.VerifySignaturesmakes all four combinations expressible:The decision that kept this local rather than repo-wide
A registry hit with no IAM entity behind it was named as a principal derived from the access key (
buildCallerARN). That fallback belongs to verification, not to account resolution: a verified key has proven the caller holds the secret; a key merely present in a table has proven nothing.Without that split, wiring a registry into
StartTestServerwould makeAKIATEST12345678901a hit, flippingPrincipalfrom nil to…:user/AKIATEST12345678901— which changesGetCallerIdentity's ARN off:root(asserted verbatim ataccount_single_test.go:323), turnsGetUser/CreateAccessKey/ListAccessKeysfromValidationErrorinto aNoSuchEntitylookup, and rewrites the event store'sPrincipal. Repository-wide, riding on an unrelated change. With it, #630's own "no existing test changes behaviour" criterion is reachable, and the suite passes unchanged across all 45StartTestServerfiles and 12StartTestServerWithAccountsfiles.Test-server half
StartTestServernow takes options —WithAccounts(…)andWithSignatureVerification()— a registry is always wired soRegisterAccountworks on any test server, andStartTestServerWithAccountsis a thin wrapper that keeps verification on, preserving the stricter contract its 12 callers were written against rather than loosening it.The acceptance criterion that is not satisfiable as written
#630 asks that
VerifySignatureswithoutCredentialsbe refused at construction.NewServerreturns*Serverwith no error, and changing that signature reaches ~42 test files pluscmd/substrate/main.go— out of proportion to a mistake a warning describes just as precisely, and a panic in an emulator library would be worse than either. It downgrades and logs; the criterion is recorded as rewritten inCHANGELOG.md. Two tests pin the downgrade, including a nil-logger non-panic test (NewServertouched the logger nowhere before).Tests
New
emulator/credentials_verify_test.go(10 tests) asserts each of the four combinations plus the test-server entry points. Three older tests are superseded and deleted:newTestServerWithCreds(helper),TestServer_CredentialRegistry_EnrichesContext(asserted onlyNotEqual(500), with a dead capture variable) andTestServer_CredentialRegistry_UnknownKey_Returns403(its helper wired a registry without verification, which is exactly the combination that must no longer 403).Verification
Live sanity against a built binary confirms the shipped CLI is unaffected — it never set
Credentials, so it never had verification either.test,AKIAIOSFODNN7EXAMPLE,AKIATEST12345678901and an unmintedAKIANEVERMINTED00001all still resolve to123456789012/arn:aws:iam::123456789012:root, and an IAM-minted key still resolves to its user (user/u630).Closes #630