PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
1. Pin the container request with a unit test
- 1.1 In
agent/verification/internal/features/container/dockerengine.go, move the construction ofcontainer.Configandcontainer.HostConfigout ofCreateContainerinto a pure function that takes aSpawnSpec, and makeCreateContainercall it. Add a table-driven test indockerengine_test.gothat asserts, for a hardened spec:CapDropis exactly["ALL"],CapAddequalsminimalCaps,SecurityOptcontainsno-new-privileges,BindsandMountsare empty, the memory, process and CPU limits are copied, a zeroNanoCPUsstays zero, and port 5432 is published only on127.0.0.1. Verify withjust testinagent/verification.
2. Delete the runtime read-back
- 2.1 Delete
Manager.assertSecurityand its call inManager.Spawn,dockerEngine.InspectSecurityandsecuritystate.go. LeavebuildSpec,minimalCapsand the hardening fields ofSpawnSpecunchanged. Update any comment that names the read-back. Verify thatgrep -rn "assertSecurity\|InspectSecurity\|SecurityState\|hardening regression" agent/verificationfinds nothing, and thatjust buildandjust testinagent/verificationpass.
3. Check the applied privileges end to end
- 3.1 Add
POST /mock/set-stream-delaywith a body{"seconds": N}toagent/verification/e2e/mock-server/main.go.handleBackupStreamwaits that long before writing the response, and/mock/resetclears the delay. Verify withjust lintinagent/verification, which covers./e2e/.... - 3.2 Add
agent/verification/e2e/scripts/test-container-privileges.sh. It sets a 30-second stream delay, claims a job forgood-pg18.dump, waits until a running container labeled with the test's agent ID exists, and reads/proc/1/statusthroughdocker exec. It fails unlessCapBndis00000000000000cbandNoNewPrivsis1. It then waits for theCOMPLETEDreport and runsleak_check. Add the script toTESTSinrun-all.sh. Verify withjust e2einagent/verification, which must report every test passed.
4. Run the end-to-end subset on Podman
- 4.1 In
agent/verification/e2e/docker-compose.yml, mount the runner's engine socket from${E2E_ENGINE_SOCKET:-/var/run/docker.sock}and update the runner's comments. Addagent/verification/e2e/scripts/run-podman.sh, which runstest-container-privileges.sh,test-restore-success.sh 18andtest-restore-broken.shand reports results the wayrun-all.shdoes. Add ane2e-podmanrecipe toagent/verification/Justfilethat prepares artifacts ase2edoes and runs the runner withE2E_ENGINE_SOCKETdefaulting to/run/podman/podman.sockand the commandbash /opt/agent/scripts/run-podman.sh. Verify withE2E_ENGINE_SOCKET=$XDG_RUNTIME_DIR/podman/podman.sock just e2e-podmaninagent/verification, which must report every test passed, and withjust e2estill passing. - 4.2 Add the job
e2e-verification-agent-podmanto.github/workflows/ci-release.yml, with the same trigger condition, runner image, timeout,needsand tool setup ase2e-verification-agent. Beforejust e2e-podmanit runssudo systemctl start podman.socketand printspodman versionandpodman info --format '{{.Host.OCIRuntime.Name}}'. Its cleanup step also removes leftover Podman containers labeled by the agent. Add the job to theneedsofdetermine-version. Verify withactionlint .github/workflows/ci-release.yml, which must report no new findings compared with the file before the change.
5. Final checks
- 5.1 Run
just lintinagent/verificationand fix every finding until it passes. - 5.2 Search the repository for mentions of the deleted read-back and of the e2e entry points (
run-all.sh,just e2e,docker.sockin the agent's e2e) and bring every affected comment and document in line with the change. Verify thatgrep -rn "hardening regression" .outsideopenspec/finds nothing.
6. Make the restore container reachable on rootful Podman in CI
The first run of e2e-verification-agent-podman failed all three tests: the restore container started, but the agent could not reach Postgres through its published port for 60 seconds. The tasks below diagnose it; the fix and the green CI run belong to start-restore-containers-unprivileged.
- 6.1 In
agent/verification/internal/features/container/manager.go, makewaitForReadyreturn the readiness deadline together with the error of the last ping that finished before the deadline, so a refused port, an unanswered connection and a rejected login read differently in the verification report. AddTest_WaitForReady_WhenPortRefusesConnections_ReturnsDeadlineWithLastPingErrortomanager_test.go. Verify withjust testinagent/verification. - 6.2 Temporary: add
agent/verification/e2e/diagnose-podman-ports.shand the stepDiagnose Podman port publishingwithcontinue-on-error: truebeforejust e2e-podmanine2e-verification-agent-podman. The script repeats the agent's connection path with plain Postgres containers and varies the bind address and the target address. It then creates containers through the Docker-compatible API with the agent's own request, turning off one of the image, the capability drop and no-new-privileges per variant, and prints each container's processes, capabilities and log. When the agent's path fails for plain containers, it repeats the checks with Docker's firewall rules removed. Verify withbash -n agent/verification/e2e/diagnose-podman-ports.shandactionlint .github/workflows/ci-release.yml, which must report no new findings.
The cause turned out to be AppArmor denying signals between the container's processes under no-new-privileges, not port publishing. The change start-restore-containers-unprivileged fixes it and removes the temporary diagnostics, replacing the former tasks 6.3 and 6.4.
Change verification
just --justfile agent/verification/Justfile test