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: {}}.
  • up and restart write a root key to labkit/secrets/encryption/root-key (mode 0600, one line of openssl rand -base64 32), but only when the file is missing. The Postgres container survives down, 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_keys still has rows that are not crypto-shredded, the driver stops and suggests down --all. up stops before AR starts. restart stops after it stops AR. Shredded rows do not count, because their wrapped_key is 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_regclass query, 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, sourcing driver.sh now only defines its functions.
  • SKILL.md documents all of this: the boot list, openssl in 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 sourcing driver.sh runs 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.sh checks, with driver.sh smoke as 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_uri names, so the driver keeps the root key while rows exist. Skipping shredded rows follows the ADR-007 tombstone (wrapped_key emptied, shredded_at set). The driver reads only the public parent of the hash-partitioned namespace_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 image python:3.13-slim. Each of ten deliberate breaks makes it fail (table below).
  • driver.sh smoke: 103 passed, 0 failed, from down --all, after this branch merged main at 14bfda31f, 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 TestRigs passes. Its TestRigsCarryTheDevelopmentMode reads driver.sh.
  • The last commit, 33ffce5b3, only rewords comments and docs. driver_test.sh and TestRigs ran again on it. smoke and the checks below ran before it.

Checked by hand on the ars04a1-* rig:

  • The first up on new containers wrote a 0600 key and logged encryption tier wired.
  • down then up, and restart, kept the key byte for byte, with the same root_key_uri.
  • A Maven remote created with credentials returned 201 and wrote one row to namespace_encryption_keys.
  • With the key removed, up exited 1 before AR started, and restart exited 1 after stopping it. Both printed the error about rows that are not crypto-shredded (count 1), which points at down --all.
  • After that row was marked shredded (shredded_at set, wrapped_key emptied), up wrote a new key and booted.
  • down --all removed the run dir and the containers. The next up wrote a new key with a new root_key_uri.
  • After a refused up, down --all removes the containers but keeps the run dir, because the earlier down already deleted ar.pid and ports.env. The next up still writes a key and boots. SKILL.md notes 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.yml and .pre-commit-config.yaml: both add a job and a hook next to lint: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 into up. Whoever lands second should also update the ensure_root_key comment 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

Edited by Dzmitry (Dima) Meshcharakou

Merge request reports

Loading
Loading