Skip to content

feat(server): give signature verification its own option, separate from the credential registry (#630) - #767

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/decouple-credentials-verification-630
Aug 23, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/decouple-credentials-verification-630

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

ServerOptions.Credentials answered 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 answer InvalidClientTokenId 403.

ServerOptions.VerifySignatures makes all four combinations expressible:

Credentials VerifySignatures Behaviour
nil false Default. Every request resolves to the default account; nothing is refused.
set false New. A registered key resolves to its own account; no signature is checked. This is what every test server now uses.
set true The prior meaning of a non-nil registry: accounts resolve and signatures are enforced.
nil true Nothing to verify against — logs a warning and downgrades to off.

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 StartTestServer would make AKIATEST12345678901 a hit, flipping Principal from nil to …:user/AKIATEST12345678901 — which changes GetCallerIdentity's ARN off :root (asserted verbatim at account_single_test.go:323), turns GetUser/CreateAccessKey/ListAccessKeys from ValidationError into a NoSuchEntity lookup, and rewrites the event store's Principal. 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 45 StartTestServer files and 12 StartTestServerWithAccounts files.

Test-server half

StartTestServer now takes options — WithAccounts(…) and WithSignatureVerification() — a registry is always wired so RegisterAccount works on any test server, and StartTestServerWithAccounts is 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 VerifySignatures without Credentials be refused at construction. NewServer returns *Server with no error, and changing that signature reaches ~42 test files plus cmd/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 in CHANGELOG.md. Two tests pin the downgrade, including a nil-logger non-panic test (NewServer touched 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 only NotEqual(500), with a dead capture variable) and TestServer_CredentialRegistry_UnknownKey_Returns403 (its helper wired a registry without verification, which is exactly the combination that must no longer 403).

Verification

gofmt -l . && go build ./... && go vet ./... && golangci-lint run ./...   # 0 issues
make test                                                                 # exit 0, no FAIL
make coverage                                                             # emulator 83.4%, total 82.8%
make docs-reference docs-reference-check docs-versions                    # exit 0
npm --prefix docs run build                                              # exit 0, anchor diff empty
go vet -C test/e2e ./... && go test -C test/e2e ./...                     # ok 0.718s

Live sanity against a built binary confirms the shipped CLI is unaffected — it never set Credentials, so it never had verification either. test, AKIAIOSFODNN7EXAMPLE, AKIATEST12345678901 and an unminted AKIANEVERMINTED00001 all still resolve to 123456789012 / arn:aws:iam::123456789012:root, and an IAM-minted key still resolves to its user (user/u630).

Closes #630

…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
@scttfrdmn scttfrdmn added this to the v0.109.0 milestone Aug 23, 2026
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit e52c263 into main Aug 23, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/decouple-credentials-verification-630 branch August 23, 2026 06:07
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.

Server: ServerOptions.Credentials couples account resolution to SigV4 enforcement, so a test cannot have one without the other

1 participant