Skip to content

feat(backups): attest the offline key copy of a repository (backup.repository.attest_offline_key) - #74

Merged
davdxpx merged 1 commit into
mainfrom
feat/backup-attest-offline-key
Nov 7, 2026
Merged

davdxpx merged 1 commit into
mainfrom
feat/backup-attest-offline-key

Conversation

@davdxpx

@davdxpx davdxpx commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Why

ADR-0036 §4: offlineCopyConfirmedAt records a person's statement that an offline copy of a repository's key exists. packages/backups/src/protection.ts adds offline_key_unconfirmed for every repository whose cipher is not none and that has no such statement, so the cluster stays at_risk. No operation could set it: backup adopt does not take it, and the guard of the applied bundle backup-catalog raises EXB01 ("a repository's declared facts change by no operation of this bundle") for any change of offline_copy_confirmed_at. Every encrypted repository was at_risk for good.

What

  • Kind backup.repository.attest_offline_key (plan action backup.repository.attest_offline_key.plan): human only, the same risk class as the other backup record changes. That means registry.manage, class high, a fresh re-authentication (300 s), and on a production or unknown-tier cluster one person's approval (rule backup.change-prod-approval, raised to version 2 because it now covers this kind).
    • The plan binds the repository, the statement and the attesting identity, plus the revision as expected state.
    • At acceptance the kind checks again that the revision is unchanged, the repository is not retired and the cipher is not none.
    • The worker sets the time to the database's clock and records its own operation beside it.
    • The audit event backup.repository.attest_offline_key carries attestedBy, statement, the time and keyRead: false.
    • No key is read, and nothing in the bucket or on the host changes.
  • Refusals:
    • A retired repository is 409 REGISTRY_CONFLICT with reason repository_retired.
    • A repository whose effective cipher is none is 409 with the new reason repository_unencrypted. The effective cipher is the observed one when the engine reported it, else the declared one, the same rule the protection state uses.
    • If the engine reports none between plan and apply, the plan is PLAN_STALE.
    • A blank statement is 422. So is a statement that looks like a pasted key: a run of 32 or more letters, digits and +/=_- that holds both letters and digits. The statement stays for good in the plan and the append-only audit, which is why this is refused. The CLI checks the contract before anything is sent.
    • A later statement moves the time forward and the audit keeps both. An attestation is never taken back.
  • Bundle 01M6VGR6HJW1C82CC3N1ADVWVK_offline-key-attestation (additive, transactional, depends on observed-targets). The applied backup-catalog bundle is not touched.
    • New column offline_copy_attested_by_operation_id, with a CHECK that it and offline_copy_confirmed_at are both set or both null.
    • An UPDATE grant on the new column to exdb_worker.
    • backups.repository_guard() replaced with the same signature and trigger. It gains a fourth path: the attestation columns change only through a new, unfinished operation of this kind that is recorded on no other repository. That path must raise the revision and change nothing else. The guard sets the time itself.
    • Every other declared fact stays fixed after adoption, and a repository starts unattested.
  • Interfaces:
    • REST POST /backup-repositories/{repositoryId}/offline-key-attestation (planBackupRepositoryOfflineKeyAttestation)
    • CLI exponetdb backup attest-offline-key <repository> --statement "..."
    • a Web App plan title, so the approval page names the plan
    • Contracts, OpenAPI, catalog and SDK are regenerated (bun run generate). exponetdb-docs/15-cli/reference.md is regenerated (bun run --cwd apps/cli reference).
  • No MCP tool. The request asked for an MCP plan tool "like the other backup plans". No backup plan has an MCP tool: every backup record change is a human-only registry.manage action. apps/server/src/interfaces/mcp/registry.ts never offers a human-only action, and packages/contracts/test/registry.test.ts requires registry plans to exclude the mcp client kind. An agent can still read the protection state through backups_list.
  • Docs:
    • ADR-0036 §4 and its as-built table
    • 09-backups-and-restore/adoption.md §3.1 (the owner's steps)
    • 02-control-plane/control-database.md §5 (the bundle)
    • 02-control-plane/policy-engine.md (rule version 2; active plans of the five backup change kinds go stale once at acceptance after the deploy)
    • 06-rest-api/resources.md
    • 15-cli/README.md §10

Tests (written first, red before the change)

  • packages/backups/test/backups.int.test.ts (the guard as exdb_worker, real PostgreSQL 17):
    • the attestation drops offline_key_unconfirmed, and the time is the database's
    • one operation attests one repository only
    • an ownership, retire or other operation does not attest
    • the guard refuses an attestation without its operation or without raising the revision
    • an attestation carries no other declared fact, ownership, observation or state with it
    • the other declared facts still change by no operation
    • it is never taken back, and a re-attestation moves the time forward
    • the guard refuses an attestation at adoption, together with a retirement, on a declared-unencrypted and an observed-unencrypted repository, and on a retired one
    • Red: column "offline_copy_attested_by_operation_id" of relation "repositories" does not exist.
  • apps/server/test/http-backups.int.test.ts: end to end on a production cluster, covering a blank statement (422), plan (class: high, approvals.required: 1), step-up, approval, worker, protection reasons before and after, the repository view, and the audit event with attestedBy and statement. It also covers the repository_unencrypted and repository_retired refusals. A second test on nonprod covers: no approval needed, a key-like statement refused (422), and a plan made stale (409 PLAN_STALE) when a catalog refresh then observes the stanza unencrypted, with nothing recorded.
  • apps/cli/test/backups.test.ts: the command maps to its action, and without a statement nothing is sent (exit 2).
  • packages/policy/test/backup-rules.test.ts: the kind needs an approval and a re-authentication on prod and on an unknown tier, with rule version 2.
  • packages/contracts/test/registry.test.ts, apps/server/test/http-auth.test.ts: the new actions and route are listed.

Local gates (no CI)

Run on this branch with the pinned toolchain (bun 1.4.4, node 24.22.1), against disposable local containers: Control Store PostgreSQL 17.11, versitygw, and targets PostgreSQL 16/17/18 plus plain.

  • bun run test (29 packages): passed. The touched packages were re-run after the last edits: contracts 222, policy 123, cli 224, server 218.
  • bun run test:integration -- --continue: passed for every package except @exponetdb/server, where 7 of 431 tests failed.
    • Every one of the 7 failed on 503 CONTROL_PLANE_DEGRADED from the readiness gate in its setup, before the code under test ran, under the full-suite load.
    • Re-run alone, the three files pass 46/46 (http-backups.int.test.ts 15, http-registry-tier.int.test.ts 8, node-operations.int.test.ts 23).
    • Other packages: backups 29, control-store 118, operations 50, migrations-engine 261, postgres 498, registry 56, diagnostics 220, auth 145, audit 48, nodes 24, secrets 11.
  • typecheck, check (Biome), verify:generated, golden:check, golden:history origin/main (21 frozen bundles byte-identical), golden:history 6e556f6b…, boundaries, secrets, third-party, licenses, ui-safety, build: all passed.
  • Not run: test:e2e (Playwright; the only Web App change is a plan title string), apps/server test:conformance (the MCP catalog is unchanged; golden:history shows 41 MCP tool versions unchanged), go:test (no Go change).

After merge and deploy (owner)

Nothing was applied to production. After the release with this bundle is deployed and the Control Store is migrated, the owner attests each encrypted production repository from a CLI session:

exponetdb backup attest-offline-key <repository> --statement "Passphrase copy in the owner's password manager, confirmed 2026-11-07"
exponetdb plan apply <plan>

Then approve the plan in the Web App (production: one approval and a fresh step-up), and check that exponetdb backup list <cluster> no longer shows offline_key_unconfirmed.

Developed by @davdxpx

…pository.attest_offline_key)

ADR-0036 §4 says offline_copy_confirmed_at records a person's statement
that an offline copy of a repository's key exists, but no operation set
it: `backup adopt` does not take it and the guard of bundle backup-catalog
refused every change of it (EXB01 "declared facts change by no operation
of this bundle"). An encrypted repository therefore kept the protection
reason offline_key_unconfirmed, and its cluster stayed at_risk, for good.

- New planned kind backup.repository.attest_offline_key: human only
  (registry.manage plan, no MCP tool, like every backup record change),
  class high with a fresh re-authentication, and on a production or
  unknown-tier cluster a person's approval (backup.change-prod-approval,
  now version 2). Plan content binds the repository, the statement and
  the attesting identity; the kind re-checks the revision and the cipher.
  The worker sets the time to the database's clock, records its operation
  beside it and writes the statement and who attested to the audit event.
  No key is read; nothing in the bucket or on the host changes.
- Refused for a retired repository (repository_retired) and for one whose
  effective cipher, observed else declared, is none (new conflict reason
  repository_unencrypted). A later statement moves the time forward; an
  attestation is never taken back. The statement stays for good in the
  plan and the append-only audit, so one that looks like a pasted key (a
  run of 32 or more letters, digits and +/=_- holding both) is refused by
  the contract, in the CLI before anything is sent.
- Bundle 01M6VGR6HJW1C82CC3N1ADVWVK_offline-key-attestation (additive,
  depends on observed-targets): column
  offline_copy_attested_by_operation_id with a CHECK tying it to the time,
  an UPDATE grant on it to exdb_worker, and backups.repository_guard()
  replaced with the same signature and trigger. Its fourth path takes
  exactly the attestation from its own new operation; every other
  declared fact stays fixed, a repository starts unattested. The applied
  backup-catalog bundle is unchanged.
- REST POST /backup-repositories/{id}/offline-key-attestation, CLI
  `exponetdb backup attest-offline-key <repository> --statement "..."`,
  Web plan title; contracts, SDK and CLI reference regenerated.
- Docs: ADR-0036 §4 and its as-built table, adoption.md §3.1,
  control-database.md §5, policy-engine.md, resources.md, CLI README.

Tests first (red before the change): the guard tests in
packages/backups/test/backups.int.test.ts failed with `column
"offline_copy_attested_by_operation_id" of relation "repositories" does
not exist`; the CLI registry test failed on the missing command; the
policy test on rule version 1; the contracts registry-tier test on the
missing actions. Green after: protection drops offline_key_unconfirmed
after an attestation; the guard still refuses other declared-fact
changes, another kind's or a reused operation, an attestation at
adoption, an unencrypted (declared or observed) and a retired repository;
REST end to end on production with plan, approval, step-up, worker and
audit; on nonprod without an approval, a key-like statement refused and
a plan made stale when the engine then reports the stanza unencrypted.

Developed by @davdxpx
@davdxpx
davdxpx merged commit 617fcd6 into main Nov 7, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant