Skip to content

feat(config): read substrate.yaml's credentials: section (#736) - #768

Merged
scttfrdmn merged 3 commits into
mainfrom
feat/read-credentials-config-736
Aug 23, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
feat/read-credentials-config-736

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

substrate.yaml's credentials: section was documented from the beginning — an enabled flag and a list of entries carrying access_key_id / secret_access_key / account_id — and Config had no field for any of it. Viper read the keys, nothing consumed them, and a consumer who configured a registry got no registry, no verification and no error. CredentialRegistry was reachable only in-process through ServerOptions.

The fail-before run makes the point better than prose: against a main binary, all eight sections of the live script answer identically to the no-config case.

main this branch
listed key AKIAEXAMPLE00000001 → account 111122223333 123456789012 / :root 111122223333 / user/AKIAEXAMPLE00000001
same key, wrong secret 200 SignatureDoesNotMatch
key the file does not name 200 InvalidClientTokenId
account_id: "1234" starts anyway, row dropped load config: credentials.entries[0].account_id "1234" is not valid; an AWS account ID is 12 digits
duplicate access key starts anyway, row silently replaced load config: credentials.entries[1].access_key_id … duplicates entries[0]
entry appended + SIGHUP 403 before and after 403 before, 210987654321 after

verify_signatures

New, beside enabled, defaulting to true — because the section has documented enabled as "enable SigV4 signature verification" since it was written and enabled: true on its own has to keep meaning that. Setting it to false is the combination #630 opened up: resolve an account per access key without authenticating anyone, which is what a multi-account test usually wants.

It is gated on the registry in main.go rather than passed straight through. Because the default is true, a bare copy would hand NewServer verify-without-registry on every default startup and log its downgrade warning at a consumer who configured nothing.

NewCredentialRegistry seeds three credentials, not one

AKIATEST12345678901, test/test and AKIAIOSFODNN7EXAMPLE, all in the default account. Without this, turning verification on would make substrate's own quickstart wrong: a consumer who followed README.md:221, docs/endpoint-configuration.md:58 or docs/testing-guide.md:549 exactly would be answered InvalidClientTokenId 403. Their secrets are documented too, so signing with one still proves the caller holds the secret — this widens who may sign, not what a signature has to satisfy. An entries: row reusing one of those access key IDs replaces it, which is how a test moves the built-in key into another account.

Verified live with verification on: test/test, AKIAIOSFODNN7EXAMPLE and AKIATEST12345678901 all return 200 and account 123456789012.

auth: is removed from the example file rather than wired

The issue's expectation there is wrong, and this records why. substrate server already builds an AuthController unconditionally (main.go:137), and IAMPlugin.authorize holds no controller at all — it resolves against p.state directly — so auth.enabled: false could never have meant "off". Enforcement is opt-in by existence: a request is checked only once its access key resolves to an IAM entity substrate holds. A flag would have overpromised in both directions, so the example file now says there is nothing to enable and why.

The stale claim at the top of the old credentials: block is gone too — it said enabling the section makes every request carry a valid SigV4 header, and VerifySigV4 passes an unsigned one.

Acceptance criteria

  • Config grows tags for the section and LoadConfig sets its defaults
  • cmd/substrate/main.go passes the registry through ServerOptions
  • Validate refuses a malformed entry rather than silently dropping it — four refusals, checked whether or not the section is enabled
  • The section left unwired is marked as such — auth: now states it is always on, with the mechanism
  • A test asserts a config file enabling the section produces a server that behaves accordingly — emulator/config_credentials_test.go, including properly signed requests so a 200 means the signature verified rather than that verification was skipped

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.689s

Compatibility

credentials.enabled ships false, which wires no registry, attributes every caller to account.default and checks no signature — nothing changes for an existing deployment. On turning it on with verification, expect one visible difference: a verified key IAM does not know names itself as the principal, so GetCallerIdentity reports arn:aws:iam::111122223333:user/AKIAEXAMPLE00000001 rather than …:root. That is #630's rule, the ARN still resolves to no policies, and verify_signatures: false keeps the …:root answer.

Closes #736

The section was documented from the beginning — an `enabled` flag and a list of
`entries` carrying access_key_id / secret_access_key / account_id — and Config
had no field for any of it. Viper read the keys, nothing consumed them, and a
consumer who configured a registry got no registry, no verification and no
error. The subsystem was reachable only in-process through ServerOptions.

CredentialsCfg / CredentialEntryCfg / ToCredentialRegistry / RegisterInto now
carry it, and cmd/substrate passes the result through ServerOptions.

verify_signatures joins enabled and defaults to true, because the section has
documented `enabled` as "enable SigV4 signature verification" since it was
written and `enabled: true` alone has to keep meaning that. Setting it false is
the combination #630 opened up: attribution without authentication, which is
what a multi-account test usually wants.

Validate refuses an empty access_key_id, an account_id that is not twelve
digits, a duplicated key, and a missing secret while verification is on —
whether or not the section is enabled, so a typo does not stay hidden until
someone flips the flag. SIGHUP adds newly listed entries to the live registry;
enabled and verify_signatures are startup-only and changing either warns.

NewCredentialRegistry seeds all three credentials substrate's own documentation
tells a caller to use — AKIATEST12345678901, test/test and AKIAIOSFODNN7EXAMPLE
— rather than only the first. Without that, turning verification on would make
the quickstart wrong: a consumer following README.md exactly would be answered
InvalidClientTokenId 403. Their secrets are documented too, so this widens who
may sign, not what a signature must satisfy.

The auth: section is removed from substrate.yaml.example rather than wired, and
the issue's expectation there is recorded as wrong: an AuthController is always
built, IAMPlugin.authorize holds no controller at all, and enforcement is opt-in
by existence. A flag would have overpromised in both directions.

Closes #736
@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

❌ Patch coverage is 85.13514% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/substrate/main.go 54.16% 11 Missing ⚠️

📢 Thoughts on this report? Let us know!

The CLI's RunE closure is untestable, so both decisions it was making —
what ServerOptions.Credentials and VerifySignatures should be, and which
part of the section a reload cannot apply — move into CredentialsCfg
methods that a test can call.
newCredentialWiring and reloadCredentials follow newFaultController's
precedent — a RunE closure cannot be called from a test, so the decision
lives in a function beside it and main_test.go asserts both halves.
@scttfrdmn
scttfrdmn merged commit 32e1a0f into main Aug 23, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/read-credentials-config-736 branch August 23, 2026 06:46
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.

config: substrate.yaml's credentials: and auth: sections are documented but never parsed

1 participant