Repository navigation
feat(backups): attest the offline key copy of a repository (backup.repository.attest_offline_key) - #74
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
ADR-0036 §4:
offlineCopyConfirmedAtrecords a person's statement that an offline copy of a repository's key exists.packages/backups/src/protection.tsaddsoffline_key_unconfirmedfor every repository whose cipher is notnoneand that has no such statement, so the cluster staysat_risk. No operation could set it:backup adoptdoes not take it, and the guard of the applied bundlebackup-catalograisesEXB01("a repository's declared facts change by no operation of this bundle") for any change ofoffline_copy_confirmed_at. Every encrypted repository wasat_riskfor good.What
backup.repository.attest_offline_key(plan actionbackup.repository.attest_offline_key.plan): human only, the same risk class as the other backup record changes. That meansregistry.manage, classhigh, a fresh re-authentication (300 s), and on a production or unknown-tier cluster one person's approval (rulebackup.change-prod-approval, raised to version 2 because it now covers this kind).none.backup.repository.attest_offline_keycarriesattestedBy,statement, the time andkeyRead: false.409 REGISTRY_CONFLICTwith reasonrepository_retired.noneis409with the new reasonrepository_unencrypted. The effective cipher is the observed one when the engine reported it, else the declared one, the same rule the protection state uses.nonebetween plan and apply, the plan isPLAN_STALE.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.01M6VGR6HJW1C82CC3N1ADVWVK_offline-key-attestation(additive, transactional, depends onobserved-targets). The appliedbackup-catalogbundle is not touched.offline_copy_attested_by_operation_id, with a CHECK that it andoffline_copy_confirmed_atare both set or both null.UPDATEgrant on the new column toexdb_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.POST /backup-repositories/{repositoryId}/offline-key-attestation(planBackupRepositoryOfflineKeyAttestation)exponetdb backup attest-offline-key <repository> --statement "..."bun run generate).exponetdb-docs/15-cli/reference.mdis regenerated (bun run --cwd apps/cli reference).registry.manageaction.apps/server/src/interfaces/mcp/registry.tsnever offers a human-only action, andpackages/contracts/test/registry.test.tsrequires registry plans to exclude themcpclient kind. An agent can still read the protection state throughbackups_list.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.md15-cli/README.md§10Tests (written first, red before the change)
packages/backups/test/backups.int.test.ts(the guard asexdb_worker, real PostgreSQL 17):offline_key_unconfirmed, and the time is the database'scolumn "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 withattestedByandstatement. It also covers therepository_unencryptedandrepository_retiredrefusals. A second test on nonprod covers: no approval needed, a key-like statement refused (422), and a plan made stale (409PLAN_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.503 CONTROL_PLANE_DEGRADEDfrom the readiness gate in its setup, before the code under test ran, under the full-suite load.http-backups.int.test.ts15,http-registry-tier.int.test.ts8,node-operations.int.test.ts23).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.test:e2e(Playwright; the only Web App change is a plan title string),apps/server test:conformance(the MCP catalog is unchanged;golden:historyshows 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:
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 showsoffline_key_unconfirmed.Developed by
@davdxpx