chore(skills): boot the run recipe with encryption and a root key (S04-A required encryption block plan: 1/16)
Summary
The run recipe (driver.sh) now boots Artifact Registry with column
encryption on. This is Step 1 of the S04-A required encryption block plan.
Every local rig needs the encryption block and a root key before Step 12
makes the block required.
What changes:
- The generated config gets
encryption: {local: {}}. upandrestartwrite a root key tolabkit/secrets/encryption/root-key(mode0600, one line ofopenssl rand -base64 32), but only when the file is missing. The Postgres container survivesdown, and its namespace keys open only with the root key they were wrapped under. A new key on every boot would lock them out.- If the key is missing but
namespace_encryption_keysstill has rows that are not crypto-shredded, the driver stops and suggestsdown --all.upstops before AR starts.restartstops after it stops AR. Shredded rows do not count, because theirwrapped_keyis already empty. - On a new container the table does not exist yet, because AR runs its
migrations at boot. So the check first looks for the table in a separate
to_regclassquery, and treats a missing table as zero rows. - New offline tests in
driver_test.sh, run by a new CI job (lint:skill-scripts:run-artifact-registry) and a pre-commit hook. To make this possible, sourcingdriver.shnow only defines its functions. SKILL.mddocuments all of this: the boot list,opensslin the prerequisites, a Gotchas entry on the key's lifecycle, and a validation entry.
!3051 (merged) fixes the matching spec row for a missing root key. This MR does not depend on it.
Plan and spec amendments
Review changed Step 1's plan text in this MR (see Review-driven plan and spec corrections):
- Files: adds
driver_test.sh, the CI job, and the pre-commit hook. It also notes that sourcingdriver.shruns no command. - Files and Acceptance: the refusal counts only rows that are not crypto-shredded.
- Tests: was "none added". Now it lists what
driver_test.shchecks, withdriver.sh smokeas the end-to-end check. - The dependency table, the LOC forecast (Step 1 about 350, Steps 2 to 4 about 180), and the Testing Strategy are updated to match.
Governing ADRs
./scripts/adr-freshness.sh says the local mirror is current (last change
2026-10-11). No conflict.
- ADR-007 (Database Schema, its Encryption keys section): a namespace
key opens only under the root key its
root_key_urinames, so the driver keeps the root key while rows exist. Skipping shredded rows follows the ADR-007 tombstone (wrapped_keyemptied,shredded_atset). The driver reads only thepublicparent of the hash-partitionednamespace_encryption_keys. - ADR-001, as S04-A applies it: one root key per deployment. The driver makes one random key per run dir and commits none.
- ADR-004, 009, 010, 014, 022, and 024 decide nothing this diff touches.
Testing
driver_test.sh: 21 passed, 0 failed on bash 3.2 and bash 5, and in the CI imagepython:3.13-slim. Each of ten deliberate breaks makes it fail (table below).driver.sh smoke: 103 passed, 0 failed, fromdown --all, after this branch mergedmainat14bfda31f, on an isolated rig (ars04a2-*, ports 5447, 9113, 6394). This MR adds no smoke check, so the total is main's.go test ./internal/config/ -run TestRigspasses. ItsTestRigsCarryTheDevelopmentModereadsdriver.sh.- The last commit,
33ffce5b3, only rewords comments and docs.driver_test.shandTestRigsran again on it.smokeand the checks below ran before it.
Checked by hand on the ars04a1-* rig:
- The first
upon new containers wrote a0600key and loggedencryption tier wired. downthenup, andrestart, kept the key byte for byte, with the sameroot_key_uri.- A Maven remote created with
credentialsreturned201and wrote one row tonamespace_encryption_keys. - With the key removed,
upexited 1 before AR started, andrestartexited 1 after stopping it. Both printed the error about rows that are not crypto-shredded (count 1), which points atdown --all. - After that row was marked shredded (
shredded_atset,wrapped_keyemptied),upwrote a new key and booted. down --allremoved the run dir and the containers. The nextupwrote a new key with a newroot_key_uri.- After a refused
up,down --allremoves the containers but keeps the run dir, because the earlierdownalready deletedar.pidandports.env. The nextupstill writes a key and boots.SKILL.mdnotes this.
The ten breaks that make driver_test.sh fail
Eight are in ensure_root_key, one is in the source guard, and one is in
the test file itself.
| Break | Check that fails |
|---|---|
| keep case does not return | keep: key file unchanged, sends no query |
| missing-table check removed | new container (4 checks) |
WHERE shredded_at IS NULL removed |
no live rows: count skips shredded rows |
| refusal check bypassed | live rows (4 checks) |
umask 077 removed |
new container: key file is 0600 |
| key generated after the file is opened | openssl fails (2 checks) |
| table query failure ignored | table query fails (2 checks) |
| count query failure ignored | count query fails (2 checks) |
| source guard removed | every case |
a case runs inside if (set -e off) |
openssl fails, table query fails |
Skill benchmark
Per the skill-changes convention,
I ran the /skill-creator benchmark: this branch's run-artifact-registry
against the merge base b56ce69bd. The AR code is the same in both, so
only the skill differs. One test case, one run per skill, each on its own
rig: boot, seed, create a Maven remote with upstream credentials, down
then up, read it back, down --all.
The old skill passed 2 of 7 checks (29%). This branch passed 7 of 7 (100%).
The old skill fails all five encryption checks for one reason: its config
has no encryption block. So saving an upstream credential returns 500,
and nothing that depends on it exists. Boot and teardown pass for both. On this branch, a connection
test after the restart returned passed: true, so the saved credential
still opens under the kept key.
Benchmark results
| Check | Old skill (b56ce69bd) |
This branch |
|---|---|---|
| First boot reaches ready | pass (after a retry, see below) | pass |
Boot log has encryption tier wired |
fail: encryption tier skipped |
pass |
Create with credentials returns 201, has_credentials: true |
fail: 500, datastore: encryption is not configured |
pass |
namespace_encryption_keys has a row |
fail: 0 | pass: 1 |
Secrets the same across down/up, root key at 0600 |
fail: no root key | pass |
Second boot ready, cred-remote reads back 200 with credentials |
fail: 404, never created |
pass |
Rig removed with down --all |
pass | pass |
| Pass rate | 29% (2/7) | 100% (7/7) |
| Time | 525 s | 410 s |
| Tokens | 155,658 | 165,443 |
The old run's first boot died during migrations: Docker's VM killed a Postgres process under load from other rigs. The retry booted, and the old run's time includes it.
Size
361 reviewable LOC (added plus removed) against main: 285 in the skill
(driver_test.sh 160, driver.sh 73, SKILL.md 52), 33 in CI config, and
43 in the plan.
Overlaps
No merge order is needed. Two open MRs have text conflicts with this branch, and whichever lands second resolves them:
- !3037 (closed), in
.gitlab-ci.ymland.pre-commit-config.yaml: both add a job and a hook next tolint:skill-scripts:bug-report. - !3226 (closed) (draft, not meant to merge as one MR), in
driver.sh. It moves migrations out of AR's boot and intoup. Whoever lands second should also update theensure_root_keycomment that says AR runs its migrations at boot.
!3242 (closed), !3236 (closed), !3048 (merged), !3038 (closed), !2971 (merged), !2944 (closed), and !1667 (closed) edit the same files without a conflict.
Closes https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1477