Repository navigation
feat(config): read substrate.yaml's credentials: section (#736) - #768
Merged
Merged
Conversation
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
Codecov Report❌ Patch coverage is
📢 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.
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.
substrate.yaml'scredentials:section was documented from the beginning — anenabledflag and a list ofentriescarryingaccess_key_id/secret_access_key/account_id— andConfighad 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.CredentialRegistrywas reachable only in-process throughServerOptions.The fail-before run makes the point better than prose: against a
mainbinary, all eight sections of the live script answer identically to the no-config case.mainAKIAEXAMPLE00000001→ account111122223333123456789012/:root111122223333/user/AKIAEXAMPLE00000001SignatureDoesNotMatchInvalidClientTokenIdaccount_id: "1234"load config: credentials.entries[0].account_id "1234" is not valid; an AWS account ID is 12 digitsload config: credentials.entries[1].access_key_id … duplicates entries[0]SIGHUP210987654321afterverify_signaturesNew, beside
enabled, defaulting to true — because the section has documentedenabledas "enable SigV4 signature verification" since it was written andenabled: trueon its own has to keep meaning that. Setting it tofalseis 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.gorather than passed straight through. Because the default istrue, a bare copy would handNewSerververify-without-registry on every default startup and log its downgrade warning at a consumer who configured nothing.NewCredentialRegistryseeds three credentials, not oneAKIATEST12345678901,test/testandAKIAIOSFODNN7EXAMPLE, all in the default account. Without this, turning verification on would make substrate's own quickstart wrong: a consumer who followedREADME.md:221,docs/endpoint-configuration.md:58ordocs/testing-guide.md:549exactly would be answeredInvalidClientTokenId403. 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. Anentries: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,AKIAIOSFODNN7EXAMPLEandAKIATEST12345678901all return 200 and account123456789012.auth:is removed from the example file rather than wiredThe issue's expectation there is wrong, and this records why.
substrate serveralready builds anAuthControllerunconditionally (main.go:137), andIAMPlugin.authorizeholds no controller at all — it resolves againstp.statedirectly — soauth.enabled: falsecould 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, andVerifySigV4passes an unsigned one.Acceptance criteria
Configgrows tags for the section andLoadConfigsets its defaultscmd/substrate/main.gopasses the registry throughServerOptionsValidaterefuses a malformed entry rather than silently dropping it — four refusals, checked whether or not the section is enabledauth:now states it is always on, with the mechanismemulator/config_credentials_test.go, including properly signed requests so a 200 means the signature verified rather than that verification was skippedVerification
Compatibility
credentials.enabledshipsfalse, which wires no registry, attributes every caller toaccount.defaultand 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, soGetCallerIdentityreportsarn:aws:iam::111122223333:user/AKIAEXAMPLE00000001rather than…:root. That is #630's rule, the ARN still resolves to no policies, andverify_signatures: falsekeeps the…:rootanswer.Closes #736