Skip to content

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

Closed

Description

@scttfrdmn

ServerOptions.Credentials does two unrelated jobs, and there is no way to ask for one without the other.

What is coupled

In Server.ServeHTTP the registry is what maps an access key to an account (emulator/server.go, step 1.5):

if s.opts.Credentials != nil {
    if entry, ok := s.opts.Credentials.Lookup(accessKey); ok {
        reqCtx.AccountID = entry.AccountID
        registryHit = true
    }
}

and immediately after, step 1.6 runs SigV4 verification gated on the same field being non-nil. An access key the registry does not know is then InvalidClientTokenId 403 (emulator/credentials.go, VerifySigV4).

So Credentials non-nil means two things at once: "resolve accounts from this table" and "enforce signatures on every request". The resolvePrincipal doc comment already notes the coupling; this issue is about removing it.

Why it matters

StartTestServer (emulator/testing.go) does not wire a registry, so every in-repo test authenticates as either 123456789012 (any AKIA… key) or 000000000000 (anything else) via extractAccount in emulator/parser.go. A test that needs to be a third account — or a specific vended member account — has no route.

Wiring a registry into StartTestServer to fix that would switch signature verification on for the whole repository in one step, since the two are the same flag. That is a repository-wide behaviour change, and it does not belong inside whatever feature happens to need multi-account tests.

Where this came from

#623 needs to authenticate as a vended member account. It works around this by adding a separate opt-in entry point (StartTestServerWithAccounts) that wires its own registry, leaving StartTestServer untouched. That is the right call for one feature but it is a second door, not a fix: the repository ends up with two test servers whose auth behaviour differs, and the difference is not the one a reader would guess from the names.

What it would take

Give signature verification its own ServerOptions field, so the four combinations are all expressible:

Credentials Verify signatures Meaning
nil off today's StartTestServer — keys map by prefix heuristic
set off the missing one — real multi-account identity, unsigned requests fine
set on today's behaviour when Credentials is set
nil on nothing to verify against; must be rejected at construction

Then StartTestServer can wire a registry for everyone, StartTestServerWithAccounts collapses into it, and a test that wants signature enforcement asks for it explicitly.

The last row is the one to get right: Verify: true with no registry has no key material to check against, so it should be a construction-time error rather than a server that 403s everything.

Acceptance criteria

  • Signature verification is controlled by its own ServerOptions field, independent of Credentials
  • Verify without Credentials is refused at construction, not at request time
  • StartTestServer wires a CredentialRegistry with verification off; no existing test changes behaviour
  • StartTestServerWithAccounts is folded back into StartTestServer (or kept as a thin wrapper), so there is one test server whose auth behaviour is described in one place
  • A test asserts the set/off combination: a registered key resolves to its account, and an unsigned request with that key is not a 403
  • A test asserts the set/on combination still 403s an unregistered key with InvalidClientTokenId

Activity

  1. added
    type: feature
    priority: medium
    on Aug 14, 2026
  2. scttfrdmn commented on Aug 14, 2026

    @scttfrdmn
    OwnerAuthor

    A data point from v0.99.0's live verification gate, worth recording here because it widens the issue's consequence beyond tests.

    substrate server wires no ServerOptions.Credentials at all, and it has no flag or config key to supply one. So account resolution for the standalone server is entirely extractAccount (emulator/parser.go:730): any AKIA… key is 123456789012, everything else is 000000000000. There are exactly two reachable identities.

    That means v0.99.0's member-account behaviour — #623's reverse index and #619's DescribeResourcePolicy asymmetry — cannot be exercised against a running server at all, only through StartTestServerWithAccounts in-process. The live run confirmed the two identities it can drive (management reads its policy; a non-AKIA caller auto-creates its own organization and reads ResourcePolicyNotFoundException for it), but the AccessDeniedException path — a member of management's organization with no delegation — is unreachable from the CLI, because there is no way to be one.

    So this is not only "a test cannot have a registry without SigV4 enforcement". It is also "a server operator cannot map keys to accounts at all", and the two are the same coupling: the only way to supply a registry today is to accept signature verification, which for a server pointed at by arbitrary SDKs and CLIs is a much larger behaviour change than a test opting in. Decoupling the two would let substrate server grow a credential map without becoming a SigV4 gate, which is what would make the member-account paths reachable outside Go tests.

  3. scttfrdmn commented on Aug 22, 2026

    @scttfrdmn
    OwnerAuthor

    #734 (PR #740) touches this and deliberately does not land the cmd/substrate/main.go half that the v0.108.0 plan had assigned to it. Recording why, because the reasoning is the argument for this issue.

    The plan's premise was that the shipped binary is permanently stuck on the access-key sniff: main.go builds ServerOptions without Credentials, so server.go can never take the registry path, so the account can never be anything but whatever the sniff decided. Wiring a registry looked like the fix.

    That premise no longer holds. #734 makes the account come from account.default in substrate.yaml, resolved before any credential is consulted, so the binary is configurable without a registry. What a registry would add is per-credential accounts — which is a real feature, but not the one that was blocking.

    And wiring one now would be a regression. Server gates both step 1.5 (registry account lookup) and step 1.6 (signature verification) on s.opts.Credentials != nil, so a registry parsed from config would switch SigV4 enforcement on for the whole server. Substrate's own documented test/test credentials are in no registry, so every call in every quickstart would start answering InvalidClientTokenId 403.

    That is exactly the coupling this issue is about, and it now blocks a second thing: #736, which is substrate.yaml's credentials: section being documented but never parsed. auth: in the same file is independently wireable — AuthController.CheckAccess treats a caller resolving to no IAM entity as unenforced — but credentials: cannot move until identification and enforcement are separable.

    The same coupling is already documented in emulator/testing.go, which is why StartTestServerWithAccounts is a separate entry point from StartTestServer rather than an option on it, and in resolvePrincipal's doc comment, which reads state rather than the registry for the same reason. #734 adds a third mention in docs/services.md under "Which account a request is attributed to".

    Staying open. The shape of the fix is two independent switches — "which account does this key belong to" and "must signatures verify" — rather than one nil check standing in for both.

  4. added this to the v0.109.0 milestone on Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumtype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions