test(testutil): stage a root key for the boot tests (S04-A required encryption block plan: 8/16)
Summary
Every boot test now has a root key to read. So the encryption block can go
into the test fixtures before Step 12 makes it required. Nothing reads the
key yet: wireEncryption reads no secret while the block is absent, so no
test changes behavior.
internal/testutil: a newwithRootKeystage writes a fresh random key atencryption/root-key.SetupIsolatedTestDBandSetupIsolatedPostgresAndRedisapply it, so integration boots have a key.SetupIsolatedRedisdoes not: its onecmdcaller builds a cache client and never boots the app. No key is committed to the repository.cmd/artifact-registry:withoutInfrastructure, the shared config the unit boots use, now serves thetestRootKeyspair. Parallel tests only read it.TestWireEncryption_NilSecretsProviderFailsBootpasses its own empty config, becausewithoutInfrastructurenow has a secret.
Nothing reads the key until the block lands, so two new tests pin it:
TestSetupHelpers_ServeARootKey (integration) and
TestWithoutInfrastructure_ServesTheTestRootKeys (unit).
The two helpers' doc comments now say they serve the key. Two older comments
in testdb.go were shortened: they defended a Postgres-only config that no
helper builds any more, and said LabKit rejects non-file secret providers,
which is not true at LabKit v2.63.1.
Governing ADRs
None. The change touches test fixtures only. ADR-007 (encryption keys) and
ADR-024 (infrastructure delivery) say nothing about test keys.
./scripts/adr-freshness.sh reports the mirror one commit behind, on
ADR-003's upload-session cap paragraph, which this change does not touch. The
two internal ADRs were not checked at their source.
Testing
go test -racepasses forcmd/artifact-registryandinternal/testutil.- The
internal/testutilintegration package passes against a local PostgreSQL and Redis, including bothTestSetupHelpers_ServeARootKeysubtests. golangci-lint --build-tags=integration ./internal/testutil/reports 0 issues. CI lint cannot see these files.
Each of these mutations was applied, re-run, and restored:
| Mutation | Fails |
|---|---|
drop .withRootKey() from either setup helper |
that helper's subtest |
| a 16-byte key, two keys, or the key under another name | both subtests |
withoutInfrastructure with no Secrets, a malformed value, or the active key alone |
TestWithoutInfrastructure_ServesTheTestRootKeys |
NilSecretsProviderFailsBoot back on withoutInfrastructure |
that test |
Spec coverage
| # | Criterion | Tests |
|---|---|---|
| AC-25 | all tests pass with -race |
the unit lane of both touched packages passes go test -race; the integration lane was not run under -race |
| AC-28 / E-1 | no encryption block fails startup, naming it | none added. The server half is Step 12's. The operator half is on main and unchanged: TestRunOperator_MissingEncryptionBlockRefusedBeforeDatabase, TestReEncryptCommand_MissingEncryptionBlockRefused, TestRetireKeyVersionCommand_MissingEncryptionBlockRefused |
| E-2 | root key file missing | TestWireEncryption_SecretReadFailureFailsBoot, on main and unchanged |
| E-3 | root key not 32 bytes | TestWireEncryption_MalformedSecretFailsBoot "a key that is not 32 bytes", on main and unchanged |
| E-4 | root key file holds zero valid keys | TestWireEncryption_MalformedSecretFailsBoot "zero usable keys", on main and unchanged |
| S-3 | key file not world-readable | the test key file is written 0600 in a 0700 directory; no test asserts the mode |
| S-4 | no key material in config | the test keys sit in Secrets only, never in a config YAML; no test asserts the absence |
Every other AC, E and S row: not this step. Other S04-A plans delivered them, and this MR changes none of their code.
Overlaps
No merge order is needed. Steps 7 and 9 edit other declarations in the same files and merge in any order. Two open MRs overlap this branch:
- !2969 (merged), in
main_test.go. It merges cleanly with this branch there. - !3226 (closed) (draft), in
main_test.go,testcomposition.go,testdb.goandtestdb_clone_integration_test.go. It already conflicts withmainin three of those files, so it needs a rebase either way. Whichever lands second resolves it.
Closes https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1484