Skip to content

feat(auth): wrap the credential encryption key with a KEK kept outside the catalog - #1003

Merged
eliseong merged 6 commits into
mainfrom
v1/707-int
Nov 18, 2026
Merged

eliseong merged 6 commits into
mainfrom
v1/707-int

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What

This change implements RFC-0000 (#970) for #707. The server can keep the key that encrypts stored secrets outside the catalog, and it holds less key material in memory.

  • A new setting, [auth.encryption] key_file, gives the absolute path of a key-encryption key (KEK) file. The KEK wraps a data encryption key (DEK). The catalog holds the wrapped DEK in a new encryption_key_ring settings row. The DEK encrypts the secret of each access key and each AssumeRole session. On PostgreSQL it also encrypts the data_database_connection_string row.
  • The server refuses a KEK file that another user can read or replace. It checks the canonical path, each parent directory, the open descriptor with fstat, and on Linux the POSIX ACL. It accepts group access only on a file that root owns.
  • Under a DEK, the additional authenticated data (AAD) of AES-GCM binds each stored secret to its row. The AAD holds the catalog id, the table, the access key ID, the account, the principal, the session name and the expiry. The AAD of each wrapped DEK covers every field of the ring.
  • The credential cache holds one SigV4 signing key per access key and scope date, and the SHA-256 of each session token. It holds no plaintext secret or token. The key for a new scope date and the identity that it answers with come from one read.
  • A locked key store holds the DEK, or the catalog key, and the signing keys. It uses memfd_secret where the kernel has it, and otherwise mlock with MADV_DONTDUMP and MADV_WIPEONFORK.
  • Six commands under extenddb encryption-key: status, switch, rewrap, rotate, reset and set-data-connection. rewrap changes the KEK while the server runs. switch, rotate and reset run while every server is stopped, under the migration lock.
  • rewrap, rotate and reset write the ring only while its row holds the ring they read. A new SettingsStore::replace_setting does this write on each of the four backends.
  • On Cassandra the commands read and write the key rows at ALL. On SQLite, switch, rotate and reset end with a VACUUM under secure_delete, so no free page keeps a ciphertext they replaced.
  • At startup the server refuses a catalog whose key state does not match its configuration. The message names the command or the restore that fixes it.
  • The docs cover the KEK file, the delivery routes, the commands, rollback, restore and a troubleshooting entry for each refusal.
  • The change carries fix(storage): refuse a damaged encryption key at startup #863, which this PR replaces. Each backend refuses to start when the catalog key is not base64 or does not decode to 32 bytes, with BackendError::InvalidEncryptionKey and the cipher's reason. Each extenddb backup command refuses it too. ADR-0026 says that the MongoDB driver builds its TLS configuration with rustls::crypto::ring.

Without key_file, the stored format and the catalog key stay as they are. The catalog key and the signing keys move into the locked key store. When locking fails, the server logs a warning and starts.

Why

#707 is the 1.0 release blocker. A copy of the catalog holds the catalog key next to the secrets it encrypts. The credential cache holds the plaintext secret of every active key. RFC-0000 (#970) is the design, and its review asked for the memory changes in the 1.0 scope.

The key check of #863 comes from #776. With a 16-byte key the server started and reported healthy, then failed every signed request with a 500. The startup loader of this change runs that check before it reads the key ring.

Refs #707
Refs #776

#707 closes when the team accepts the file key source as its scope (RFC-0000, #970). #1071 tracks the other key sources that #707 names: a key management service or an HSM, a passphrase, and a pluggable provider.

Merge of #945

92ef4967a merges main at 51cb18cff (#945) into 4e139f8d4. #945 sets the level of every Cassandra statement in cassandra_util.rs, and a test scans the crate for statements that bypass it. The follow-up commits:

  • 0e132eff5 moves the eight key statements of this PR onto that policy. The reads use Stmt::ReadAll, and two new kinds, Stmt::WriteAll and Stmt::LwtAll, keep the writes at ALL.
  • e2b467f2b adds the two kinds to the direct level test and to a unit test. It also says in docs/cassandra-setup.md that the encryption-key commands need every replica of the catalog keyspace.
  • c3530edd1 adds a direct test of the secret store. On a keyspace with too few replicas, its page read, its rewrite and the write-time read of each delete fail with an error that names ALL.
  • 41a1bfe65 merges main at 674463271 (fix(storage-cassandra): use LWTs to delete and update admin users #1010). Only crates/storage-cassandra/tests/common/mod.rs conflicted, and the merge keeps the helpers of both sides.

Testing done

Local test counts from 16 and 17 Nov, on Linux, with the SQLite backend unless named otherwise. PostgreSQL 16, MongoDB 7 as a one-member replica set, and Cassandra 4.1 each ran in a container. These counts predate the last review rounds. CI runs the workspace tests and the backend integration suites at each head.

Suite Result
cargo test -p extenddb-storage --features test-util 281 passed
cargo test -p extenddb-auth 550 passed
cargo test -p extenddb-config -p extenddb-app 130 passed
cargo test -p extenddb-server --lib 508 passed, 5 failed for a host condition
cargo test -p extenddb-storage-sqlite --lib 316 passed, 2 failed for a host condition
cargo test -p extenddb-backup-store 105 passed, 65 failed for a host condition
PostgreSQL, the 37 test binaries of extenddb-storage-postgres 453 passed, 5 failed for a host condition
MongoDB, the 12 test binaries of extenddb-storage-mongodb --features test-hooks 286 passed, 84 ignored
Cassandra, the 6 test binaries of extenddb-storage-cassandra --features test-hooks 525 passed, 1 failed for a host condition

Each failure in the table reads the owner of each ancestor directory of a backup root or a write lock. On this host /local/home is owned by uid 65534, which the check refuses. The binaries that hold those tests pass in public.ecr.aws/ubuntu/ubuntu:24.04, with the worktree mounted read only: 7 runs, 90 passed, 0 failed.

Gates: cargo fmt --all --check, and cargo clippy --workspace --all-targets -- -D warnings under the toolchain CI pins, in both of CI's feature configurations. All 66 CI checks pass at 41a1bfe65, after two reruns of the Test workflow for flaky tests.

New tests for the key commands and the key ring:

  • 15 startup states of the loader, each refusal text pinned.
  • The KEK file check: the canonical path, each parent directory, the descriptor and the POSIX ACL. The check accepts group access on a file that root owns, and refuses it on any other file. The configuration refuses a relative key_file.
  • switch, rotate, rewrap, reset and set-data-connection, over 30 catalog states: the preview, the run, a second run, a resumed run, and each refusal of section 7.
  • On PostgreSQL, through the release binary: status, rewrap and set-data-connection with the KEK that key_file names, and set-data-connection on a row that does not open.
  • On PostgreSQL, rewrap and set-data-connection read the migration status of the catalog database before they write. With an unknown breaking migration in the ledger, both exit 4 and leave their rows as they were.
  • A ring that changed between the read and a write of rewrap, rotate or reset stops the run. One table checks the three answers of replace_setting on each backend.
  • The AAD of a stored secret: a row moved in any one field does not open. The fields are the table, the access key ID, the account, the principal, the session name, the expiry and the catalog.
  • A delete that reports success and leaves the row stops the command with every key kept.
  • On SQLite, after a switch over 80 access keys, the files hold no old ciphertext. A failed rebuild names the next step, and a run of the command again rebuilds the file.
  • On Cassandra: a row written an hour ahead of this host's clock, and a session row whose policy carries a later timestamp still. The pass rewrites both rows. After the delete, neither row is there. A table pins which settings statements run at ALL, and a direct test checks that three of the secret store's statements run at ALL.
  • The credential cache under a full key store, and two requests that wait on one credential read at once. A read for a new scope date, after the key's owner changed, answers with the new owner.

Open items: #1004 holds the review items that this PR defers. Two open PRs touch the same code. #690 rewrites the catalog-check read of the connection string row, which this change encrypts. #737 documents a PostgreSQL restore that writes that row as plain text. In each case, the PR that merges second must handle the change of the other.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: RFC-0000, docs/rfcs/0000-credential-encryption-key.md (#970, not yet accepted)

Breaking changes

  • A catalog whose encryption key is not base64, or does not decode to 32 bytes, now stops serve at startup. Each extenddb backup command refuses to run on it (from fix(storage): refuse a damaged encryption key at startup #863). Before, the server started and failed each signed request with a 500. The key that init writes passes the check.
  • An older release refuses a configuration with [auth.encryption], because it rejects unknown fields in [auth]. Delete the section before a rollback (upgrade manual).
  • With key_file set, the server refuses to start when it cannot lock the key store, unless require_locked_memory = false. Hosts on a kernel before 5.16 need a higher memlock limit.

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

@LeeroyHannigan LeeroyHannigan added v1 Needed for the 1.0 release release-blocker Must ship for its milestone's release labels Nov 16, 2026
@LeeroyHannigan LeeroyHannigan added this to the 1.0 milestone Nov 16, 2026
@eliseong eliseong self-assigned this Nov 16, 2026

@eliseong eliseong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeeroyHannigan The envelope design holds up. I built the branch and checked it on all four backends. The data encryption key wraps and unwraps, each stored secret binds to its row through the AES-GCM AAD, and a row moved to another account, user, session name or expiry does not open. The key file check refuses a file another user can read, and an ancestor directory another user owns, so the directory-swap path is closed. The locked key store keeps the keys out of a core dump and zeroes them on drop. The startup check now refuses a key that is not 32 bytes, where main started and then failed every signed request.

I will approve once the rewrap and rotate data loss is fixed.

rewrap and rotate each write the key ring with an unconditional set, and rewrap takes no migration lock, because it runs while servers serve. So a rewrap that overlaps a rotate overwrites the ring the rotate wrote, and drops a data encryption key that stored secrets are under. I reproduced this on a live MongoDB catalog: rotate wrote a ring with two keys, an overlapping rewrap wrote a ring with one, and 200003 secrets were then under a key that no ring holds. Those secrets do not open again without a catalog copy. The ring write is shared code in crates/storage/src/key_commands.rs, so the three server backends share the exposure. Please make the ring write a compare-and-set against the value it read, or have rewrap refuse while the migration lock is held.

Two more items in this change:

  1. Add the per-field negative cases for the stored-secret AAD. The tests check the AAD encoding and one field, so dropping a field from the secret AAD still passes every test. A test that moves the account, the principal, the session name and the expiry, each asserting the row does not open, would cover the binding.
  2. Linking. The key file route and the rotation path are delivered, so they close their parts of #707. The other routes #707 names, a key management service, a hardware security module, a passphrase, and a pluggable key source, are deferred by the design and have no tracking issue. Please change Closes #707 to Refs #707 and file a follow-up for the deferred routes, unless the team records the file-only scope as closing #707. The design, RFC #970, is still open, so that scope is not recorded yet.

Not blocking:

  • A key file at mode 0640 or 0660 is accepted when its group is the server's group. On a host whose server runs under a broad group, the whole group can then read the key file. A docs line to run the server under a dedicated group would help.

@LeeroyHannigan
LeeroyHannigan force-pushed the v1/707-int branch 2 times, most recently from 0f6cfe5 to fcfea07 Compare November 17, 2026 02:33
LeeroyHannigan added a commit that referenced this pull request Nov 17, 2026
The file rule accepts group access only on a file that root owns, and
key_file must be an absolute path. rewrap, rotate and reset write the
ring only while its row holds the ring they read, through a new
SettingsStore::replace_setting. On Cassandra every ring write and the
commands' key row reads run at ALL. On SQLite, switch, rotate and
reset end with a VACUUM under secure_delete.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@eliseong Thanks. Each item is in 6ce157b4d.

  • The ring write is now a compare-and-set against the text read. SettingsStore::replace_setting does it on all four backends: one UPDATE ... WHERE value = ... on SQLite and PostgreSQL, a filtered update_one on MongoDB, and a lightweight transaction at ALL with a read-back on Cassandra. rewrap, both ring writes of rotate, and reset use it. When the ring changed, rewrap and rotate refuse before they write anything. reset refuses before its ring write and says what it left.
  • The AAD: a_secret_does_not_open_for_a_row_moved_in_any_field moves each field of a stored session row in turn, and the catalog id too. Each moved row fails to open. With the account dropped from the AAD, the test fails.
  • Linking: the body now says Refs #707, and Credential encryption key: the other key sources of #707 (KMS or HSM, passphrase, pluggable provider) #1071 tracks the other key sources. Credential encryption key: keep it outside the catalog and add a rotation path #707 closes when the team accepts the file key source as its scope.
  • The key file group: the rule now accepts group access only on a file that root owns, which is the Kubernetes fsGroup route. The admin guide says that the server's group must have no other members.

@eliseong eliseong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeeroyHannigan The data loss is fixed, and it holds under the attack. I ran the overlap again on live MongoDB and Cassandra catalogs, in both orders, and with sixteen rewrap processes against one ring. The ring write is a compare-and-set now, so the second writer refuses with "the key ring changed while extenddb encryption-key rewrap ran, so nothing was written" and writes nothing. No DEK is dropped, every secret still opens, and status shows none under a missing DEK. A kill mid-pass and a resume keep every key. The per-field AAD test covers each field: with the account, the expiry or the catalog id dropped from the secret AAD, the test fails. The body reads Refs #707, and #1071 tracks the other key sources.

I will approve once the PostgreSQL commands work again.

On a PostgreSQL catalog that has a key ring, status, rewrap and set-data-connection all refuse, even with the configured key file that names the ring's KEK:

the catalog has a key ring, so its data_database_connection_string row is encrypted; run the command with the configuration whose [auth.encryption] key_file names the KEK of the ring

The prior head runs status and the rewrap preview on the same catalog. This head refuses both. The cause is the catalog status read that Stores::open now runs in crates/app/src/cmd_encryption_key.rs: the Status, Rewrap and SetDataConnection arms do not put the configured KEK on the target, so the PostgreSQL status read reaches the encrypted connection row and refuses. The one online KEK change is unusable on PostgreSQL this way, and so is the status command that each refusal names. Please put the configured KEK on the target before Stores::open for these three arms, or skip that status read for them. Please also add a PostgreSQL test that runs these commands through the CLI: the key-ring tests build the target with the KEK directly, and the app tests run on SQLite, so this path has no PostgreSQL coverage.

One nit in the AAD test: unwrap_err panics before the {field} label prints, so a failure does not name the field. Match the result and assert on the error so the message survives.

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@eliseong Thanks. Each item is in f0a8bfbfd.

  • Stores::open skips the catalog status read on PostgreSQL, so status, rewrap and set-data-connection run again with the configured key file. SQLite, MongoDB and Cassandra keep the read. On those backends, opening the stores of a path that holds no catalog creates an empty database there. On PostgreSQL the open connects a pool and creates nothing.
  • The KEK on the target is not enough for status and set-data-connection. With it, status on PostgreSQL would still refuse a damaged ring and a ring under another KEK. It would also refuse an unfinished switch whose row is still in plaintext, and a row that does not open. status exists to report these four states. set-data-connection would still refuse a catalog whose row is missing or does not open. It could not write the row that it exists to repair.
  • On PostgreSQL the three commands no longer check that the migrations are current. switch, rotate and reset keep that check under the lock. RFC-0000 lists the refusal for switch (section 8.1), and not for rewrap or set-data-connection (sections 8.2 and 8.7). On a database that holds no catalog, the three commands now fail with storage error: Database error and write nothing. The log line before it names the missing settings relation.
  • tests/test_cli_encryption_key.py runs the release binary on PostgreSQL. It runs switch, status, the rewrap preview and run, status under the new KEK, set-data-connection and verify. Then it writes the connection string into the row in plaintext, as a psql UPDATE would. verify reports that the row does not open, status still runs, and set-data-connection repairs the row. The CLI lifecycle step of the PostgreSQL integration job runs the file. With the status read restored, the test fails at the first status with the error you quoted.
  • The AAD test matches each result now. When a secret opens for a moved row, the panic message names the field.

@eliseong eliseong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeeroyHannigan The round-2 items are fixed, and I verified each on a real PostgreSQL 16 catalog. The three commands (status, rewrap, set-data-connection) now work on a key-ring catalog with the configured key file, where the prior head refused them. The new PostgreSQL CLI test exercises that path and fails on the prior binary. The per-field AAD test now names the field it checks. The five code-scanning findings are all in test code and none writes a secret to a log. The compare-and-set ring write still holds under overlapping and concurrent runs on SQLite, PostgreSQL and MongoDB, and the per-field secret binding fails closed on every field I moved.

I will approve once two defects are fixed. Both are in this change's own code.

  1. The key-encryption key stays in ordinary memory of a running server. I read two full core images of a server started with a key file. In each one the raw 32 bytes of the KEK appear four times, outside the locked key store: once on a thread stack and three times in the heap. A random control of the same length appears zero times, and the images are taken after traffic and an idle wait, so this is not a startup moment that clears. The data encryption key is correctly confined to the locked store; the KEK is not. So the KEK can reach swap and a core dump, which is the exposure the locked store exists to prevent, and key_file.rs states that every buffer holding the file bytes or the key is wiped when it drops. The likely cause is a by-value move of the key that leaves an un-wiped copy, which I did not confirm. Please keep the KEK in the locked store for its whole lifetime, or wipe every copy once the DEK is unwrapped.

  2. On PostgreSQL, set-data-connection and rewrap write to a catalog whose migrations this binary refuses. The round-2 change dropped the catalog status read for the status, rewrap and set-data-connection arms, and that read was also the migration-current check. With a breaking migration in the ledger that this binary does not know, migrate and rotate both refuse with exit 4 and the message to run migrate first, but set-data-connection --yes returns 0 and rewrites the connection row, and rewrap --yes returns 0 and rewrites the ring. I reproduced both twice. Please keep a migrations-current check on these arms that does not open the connection row, so they refuse an unknown breaking migration the way rotate does.

Smaller items, not blocking:

  • A reset that loses the ring compare-and-set on PostgreSQL leaves the connection row under a key no ring holds, so a server then refuses to start until set-data-connection or another reset runs. The refusal says so and recovery works, so this is a note, not a fix request.
  • The key file length message counts a trailing newline, so a 43-character file reports 44.
  • The lock-failure hint for the key commands suggests lowering a cache setting that does not apply to them.

LeeroyHannigan added a commit that referenced this pull request Nov 18, 2026
crates/auth/src/lib.rs keeps the cached signing key of main (#1003) and the request's path and query string of this branch in the call to verify_signature.

crates/auth/tests/sigv4_differential/harness.rs keeps the provider over a pass-through credential cache from main and the path and query string arguments of authenticate_at from this branch.
LeeroyHannigan added a commit that referenced this pull request Nov 18, 2026
… of main

Main (#1003) removed the store type parameter of BuiltinAuthProvider, so BuiltinAuthProvider<MockCredentialStore> no longer names a type. The unit tests in tests.rs build each provider through provider_over, over a pass-through CachedCredentialStore.

The shim that sends the unit tests' requests to authenticate with the path / and no query string is now an impl block on BuiltinAuthProvider. Its body does not change.
LeeroyHannigan added a commit that referenced this pull request Nov 18, 2026
crates/auth/src/lib.rs keeps the test_support module from main (#1003) and the scope_tests module from this branch.

crates/auth/src/tests.rs keeps the cache-backed provider and provider_over helpers from main, and the move of the scope and check order tests to scope_tests.rs from this branch. Main's change to provider_without_credentials, in a moved test helper, goes to scope_tests.rs with the move.
LeeroyHannigan added a commit that referenced this pull request Nov 18, 2026
Main (#1003) removed the store type parameter and the region argument of BuiltinAuthProvider::new. The provider now takes a CachedCredentialStore, which holds the region, and CachedCredentialStore::new also takes a worker count. Main's tests build each provider through provider_over in tests.rs.

provider_with_a_session_expiring_at now builds its provider through provider_over. The session still reaches the expiry check of CachedCredentialStore::lookup, which runs after check_scope in authenticate. That check refuses a session past expires_at with ExpiredTokenException, with or without a cached entry.
LeeroyHannigan added a commit that referenced this pull request Nov 18, 2026
crates/config/src/lib.rs keeps the environment(None) source of main (#1003) in load and load_builtin_defaults, in place of the environment_source() of this branch, which builds the same source.

extenddb.sample.toml keeps the two [auth.encryption] variable examples from main and the list key example from this branch.
LeeroyHannigan added a commit that referenced this pull request Nov 18, 2026
…of main

Main (#1003) added environment(vars) to crates/config/src/lib.rs. It builds the EXTENDDB__ source with the __ separator, and vars replaces the process environment in tests. The merge keeps it in load and load_builtin_defaults.

This branch's environment_source() built the same source with no vars, and config_from in tests.rs added the map with .source(Some(env)). The commit deletes environment_source(), and config_from calls environment(Some(env)), so the tests still read the source that load uses.
LeeroyHannigan added a commit that referenced this pull request Nov 18, 2026
crates/app/src/cmd_catalog_check.rs keeps the comparison through the storage backend from this branch in place of the direct read of the data database by main (#1003). It keeps main's data_connection_text below the command.

crates/storage/src/diagnostics.rs keeps the key argument of test_data_database_connection from main and the check_storage_relations and drop_orphaned_relations methods from this branch.
LeeroyHannigan added a commit that referenced this pull request Nov 18, 2026
Main (#1003) encrypts the data_database_connection_string row of a PostgreSQL catalog with a key ring under the ring's DEK. Main's catalog-check read the row and opened it in data_connection_text. Without a ring the command takes the row as stored. With a ring the KEK of [auth.encryption] key_file opens it, and the command refuses a ring when key_file is not set. test_data_database_connection takes the key and reads the row through data_connection_string, with the same rules.

This branch reads the row in the PostgreSQL store, in data_pool, for check_storage_relations and drop_orphaned_relations. The plain read gave ciphertext in a catalog with a ring. The two methods now take the key as test_data_database_connection does. data_pool reads the row through data_connection_string with that key. catalog-check passes the key source of [auth.encryption] (the KEK with key_file set, else the catalog key). data_connection_text has no caller now, so the commit deletes it. A missing or empty row in a catalog without a ring still gets the message of this branch. The catalog_check tests pass the catalog key, as the command does without key_file.
LeeroyHannigan added a commit that referenced this pull request Nov 18, 2026


On this branch, serve checks the catalog before it sets up the locked key store. Under catalog_upgrade = "apply" it also migrates the catalog first. On PostgreSQL with key_file set, the check reads the KEK file and unwraps the DEK into unlocked memory to open the connection string row. The troubleshooting entry on the locked key store said that serve sets up the store before it reads the catalog. It now gives the order of this branch. The security model said that the server reads the KEK file once at startup. It now names the read for the catalog check and the memory that holds the DEK during that check.
robinnsc added a commit that referenced this pull request Nov 18, 2026
Moves the workspace version from 0.1.15 to 1.0.0 on every surface that
carries it: the root Cargo.toml version and its 13 exact pins, the 14
workspace entries in Cargo.lock (no third-party entry changes),
packaging/npm/package.json (version and the five platform pins), the
four licence-notice files (regenerated with cargo-about 0.9.0), and the
example `extenddb version` and `serve` output in docs/getting-started.md
and docs/manuals/04-quickstart-setup-guide.md.

RELEASED_THROUGH stays 12: migration 12 is still the last one, so 1.0.0
carries the catalog of 0.1.15 and freezes nothing new.

Upgrade manual:

- Behavior Changes by Release gets a v1.0.0 entry for #945: the
  Cassandra backend reads and writes at LOCAL_QUORUM where 0.1.15 ran
  many of them at ONE, so a request fails with HTTP 500 while fewer
  than a quorum of its keyspace's replicas are up. It says what to do
  before upgrading: a replication factor of 3, as cassandra-setup.md
  describes.
- A v1.0.0 entry for #1003. Without key_file the stored format and the
  catalog key stay as they are, and 0.1.15 and 1.0.0 each read the
  access keys the other wrote. serve and the backup commands refuse a
  catalog key that is not 32 bytes in base64, where 0.1.15 started and
  failed every signed request with HTTP 500; the entry says how to
  check the key before upgrading. The key moves into a locked key
  store, with a warning when the memlock limit is too low. key_file and
  the encryption-key commands are opt-in and link to the admin guide.
- The rollback section of #1003 now gives the PostgreSQL refusal of
  0.1.15 on a switched catalog: the encrypted connection string row
  stops it with exit status 1 before the missing key does.
- Current Status, the General Upgrade Procedure and the Rollback
  Procedure cover 0.1.15 to 1.0.0, with the Cassandra step, the key
  check, and the rollback after encryption-key switch. Current Status
  says which of its paragraphs are for 0.1.14 and earlier and that the
  backup store notes apply to every deployment.
- A v0.1.15 entry for the request validation of #619, #620, #830 and
  #1000, which had none. It says the expression depth limit is
  ExtendDB's own.
- The rollback to 0.1.14 or earlier states what a binary of those
  releases does on a migrated catalog, as measured on PostgreSQL with
  0.1.14 and 0.1.10: exit status 1, "invalid catalog version '12'".

docs/versioning.md: the 0.1.x releases get no more fixes. The Docker Hub
pages name 0.1.15 as the first keyless-signed release.
docker/README-mongodb.md ran extenddb/extenddb-mongodb:0.1.8; it now
runs X.Y.Z, as the other image READMEs do.

doc_version_literals now reads docker/ as well, so a stale image tag
there fails it. It reports each image tag once, and skips another
project's image tag and a link to a release. The npm launcher test now
checks that the launcher refuses the release line before an X.0.0
launcher, which it skipped at patch 0.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>
@robinnsc robinnsc mentioned this pull request Nov 18, 2026
6 of 8 tasks
amrith pushed a commit to amrith/extenddb that referenced this pull request Nov 20, 2026
Moves the workspace version from 0.1.15 to 1.0.0 on every surface that
carries it: the root Cargo.toml version and its 13 exact pins, the 14
workspace entries in Cargo.lock (no third-party entry changes),
packaging/npm/package.json (version and the five platform pins), the
four licence-notice files (regenerated with cargo-about 0.9.0), and the
example `extenddb version` and `serve` output in docs/getting-started.md
and docs/manuals/04-quickstart-setup-guide.md.

RELEASED_THROUGH stays 12: migration 12 is still the last one, so 1.0.0
carries the catalog of 0.1.15 and freezes nothing new.

Upgrade manual:

- Behavior Changes by Release gets a v1.0.0 entry for ExtendDB#945: the
  Cassandra backend reads and writes at LOCAL_QUORUM where 0.1.15 ran
  many of them at ONE, so a request fails with HTTP 500 while fewer
  than a quorum of its keyspace's replicas are up. It says what to do
  before upgrading: a replication factor of 3, as cassandra-setup.md
  describes.
- A v1.0.0 entry for ExtendDB#1003. Without key_file the stored format and the
  catalog key stay as they are, and 0.1.15 and 1.0.0 each read the
  access keys the other wrote. serve and the backup commands refuse a
  catalog key that is not 32 bytes in base64, where 0.1.15 started and
  failed every signed request with HTTP 500; the entry says how to
  check the key before upgrading. The key moves into a locked key
  store, with a warning when the memlock limit is too low. key_file and
  the encryption-key commands are opt-in and link to the admin guide.
- The rollback section of ExtendDB#1003 now gives the PostgreSQL refusal of
  0.1.15 on a switched catalog: the encrypted connection string row
  stops it with exit status 1 before the missing key does.
- Current Status, the General Upgrade Procedure and the Rollback
  Procedure cover 0.1.15 to 1.0.0, with the Cassandra step, the key
  check, and the rollback after encryption-key switch. Current Status
  says which of its paragraphs are for 0.1.14 and earlier and that the
  backup store notes apply to every deployment.
- A v0.1.15 entry for the request validation of ExtendDB#619, ExtendDB#620, ExtendDB#830 and
  ExtendDB#1000, which had none. It says the expression depth limit is
  ExtendDB's own.
- The rollback to 0.1.14 or earlier states what a binary of those
  releases does on a migrated catalog, as measured on PostgreSQL with
  0.1.14 and 0.1.10: exit status 1, "invalid catalog version '12'".

docs/versioning.md: the 0.1.x releases get no more fixes. The Docker Hub
pages name 0.1.15 as the first keyless-signed release.
docker/README-mongodb.md ran extenddb/extenddb-mongodb:0.1.8; it now
runs X.Y.Z, as the other image READMEs do.

doc_version_literals now reads docker/ as well, so a stale image tag
there fails it. It reports each image tag once, and skips another
project's image tag and a link to a release. The npm launcher test now
checks that the launcher refuses the release line before an X.0.0
launcher, which it skipped at patch 0.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>
rlunar pushed a commit to rlunar/extenddb that referenced this pull request Nov 23, 2026
… the catalog (ExtendDB#970)

* docs(rfc): wrap the credential encryption key with a key kept outside the catalog

Add a draft RFC for ExtendDB#707. Under a new key source, file, a key-encryption
key in a file on the server host wraps the data encryption key. The data
encryption key encrypts the stored access key and session secrets, and
the catalog then holds it only in wrapped form.

A new offline command, extenddb encryption-key rotate, moves a
deployment to the file source and later replaces the data encryption
key. It re-encrypts every stored secret and changes no access key ID or
secret.

The default source, catalog, keeps today's behavior. No key source uses
a network key service.

Refs ExtendDB#707

* docs(rfc): reuse existing code in the credential encryption key design

- One function in crates/storage loads the key. It reads both key rows
  through SettingsStore::get_setting, in place of four factory queries
  and four calls of the key check.
- Two functions beside secret_cipher pick the key for the nine encrypt
  and eight decrypt call sites.
- The rotation pass is one driver in crates/storage with two store
  methods per backend, as the pass of migration 2 is.
- One check in crates/storage holds the test cases, and each backend
  runs it, as each backend runs metrics_conformance.
- key_file expands a leading ~ through expand_tilde.
- The server logs its key source at startup.

The false statements that this design does not touch move to ExtendDB#972.
ExtendDB#971 covers the expired sessions that the rotation pass reads.

Refs ExtendDB#707

* docs(rfc): propose catalog migration 12 for the key id columns

ExtendDB#833 merged as ce3a51a and takes catalog migration 11 for the
attribute name escape on PostgreSQL. The key_id columns of this RFC
are now migration 12. On main, the 1.0 release pull request now raises
RELEASED_THROUGH to 11, and the unresolved question cites that line.

Refs ExtendDB#707

* docs(rfc): find each row's key by trial and drop migration 12

- A stored secret records no key id. The server holds one key, and the
  rotation command opens each row with the target DEK first. Migration
  12, the key_id column and the two new cipher functions go.
- One setting, key_file, replaces key_source.
- The KEK file check reuses the TLS key check. rotate applies it to the
  target file, and refuses a KEK that equals the catalog key.
- Writes go by primary key with no condition, because the migration
  lock keeps every server out. Cassandra reads and writes at ALL, for
  the key ring and the key delete as well.
- Before the old key goes, rotate reads every row and the target file
  again.
- On SQLite, rotate sets secure_delete and ends with a WAL checkpoint.
  A file copy taken after the move then holds no catalog key.
- A new section lists ways to deliver the KEK file: systemd credentials
  sealed to a TPM, Kubernetes, swarm, Podman and sops. Another compares
  Rust key-management crates with aws-lc-rs.
- Every line reference now points at main at ce3a51a.

Refs ExtendDB#707

* docs(rfc): revise credential encryption key RFC to v5

v5 answers the review of v4 on ExtendDB#970.

The RFC now states a requirement that the server holds the least key
material it can, in locked memory. Section 6 replaces the plaintext
secret cache with a signing-key cache. It adds a locked key store built
on memfd_secret with an mlock fallback, and plans a later key process.
The signing-key cache and the locked key store are in the 1.0 scope.

A Terms section defines each term once before use. "Move" is replaced by
"the switch", and "stored secret" names the thing that is encrypted. The
Summary states that ExtendDB encrypts only stored secrets and never
table data. Each section opens with the problem it solves.

Section 1 adds a threat model and states that a catalog writer is out of
scope.

The key ring records the KEK source, a format version and the id of the
retiring catalog key. The AAD of each wrapped DEK covers every ring
field other than the wrapped values, and the ids of every DEK in the
ring. A changed field or an added or deleted entry then makes the DEKs
fail to unwrap. The parser refuses unknown fields. Each stored secret's
AAD binds the catalog id, table, access key ID, account, principal,
session name and expiry. AAD fields are length-prefixed.

The file rule checks the canonical path, each parent directory, the open
descriptor through fstat, and the POSIX ACL, in that order. The file
format is exact: 44 base64 characters and at most one newline. The
Kubernetes route uses fsGroup, with runAsGroup 10001. The swarm and sops
routes state a recommendation.

The single rotate command is split into status, switch, rewrap, rotate,
reset and set-data-connection. rewrap changes the KEK with the server
up. switch runs before key_file is set, and the startup checks run in a
stated order. A catalog key that appears after a finished switch is
refused unless the operator passes --accept-catalog-key. A rerun with
nothing to do exits 0. Every summary prints counts and access key IDs,
never a secret, and says that a rotation revokes no credential. The pass
re-encrypts expired sessions too, and on Cassandra it names ALL on each
statement.

The PostgreSQL connection string row is encrypted under the DEK, with
the commands that then need the KEK file listed. On PostgreSQL the
migration backend decrypts that row before it parses it. Section 11 says
that table backups need no KEK, and adds reset for a lost KEK. reset
deletes every access key and session. The server warns when the KEK file
and a SQLite catalog share a file system.

Alternatives now gives the costs of an online DEK replacement, and
Unresolved questions drops it. The DEK replacement is offline in 1.0.
Section 15 splits the work into three pull requests with estimates.

Refs ExtendDB#707

* docs(rfc): match RFC-0000 to the implementation in ExtendDB#1003

The file rule accepts group access only on a file that root owns, and
key_file must be an absolute path. rewrap, rotate and reset write the
ring only while its row holds the ring they read, through a new
SettingsStore::replace_setting. On Cassandra every ring write and the
commands' key row reads run at ALL. On SQLite, switch, rotate and
reset end with a VACUUM under secure_delete.

* docs(rfc): name reset among the users of replace_setting

* docs(rfc): name the commands that open the migration backend with the KEK
parsnips added a commit to parsnips/extenddb that referenced this pull request Nov 24, 2026
One conflict, in server_components_factory
(crates/storage-postgres/src/lib.rs): ExtendDB#1003 replaced
PostgresEngine::new(...) with PostgresEngine::open(...,
DataConnection::Opened(...)) and a drop(data_connection). The factory now
has main's open(...) with .with_create_only_puts(...) chained after it,
before the drop.

tests/key_ring_rows.rs, which main added, builds PostgresStorageConfig as
a struct literal. It gets ..Default::default() for the create_only_puts
field, as tests/backup_restore.rs has.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012kcReu8W93hWBjX8JAwW8P
Signed-off-by: michael parsons <michael@twisp.com>
amrith pushed a commit to amrith/extenddb that referenced this pull request Nov 24, 2026
…eps live tables (ExtendDB#690)

* fix(storage-postgres): check data relations against the catalog by id

Add DiagnosticsStore::check_storage_relations and drop_orphaned_relations
with default implementations that report the backend does not support
them. The PostgreSQL store implements both from the catalog's table_id,
index_id and vector index ids through the crate's own naming functions,
so the expected names match what the engine creates. Rows in every
status count as live. The drop takes SHARE locks on tables, indexes and
vector_indexes, reads the catalog again under them, and drops only the
reported relations that no row names.

* fix(app): compare data relations with the catalog through the storage backend

catalog-check expected relations named _ddb_{account}_{table} and
_ddb_{account}_{table}__gsi__{index}, while the storage layer names them
_ddb_{table_id}, _ddb_{index_id} and _ddb_vec_{index_id}. On PostgreSQL
every live relation was reported orphaned, every live table missing, and
--fix dropped the data tables of ACTIVE tables.

Checks 1 and 2 now call the backend's DiagnosticsStore, which derives the
expected names from the catalog ids with the engine's own naming
functions and re-checks each candidate under catalog locks before it
drops it. Missing relations are reported with the table or index that
owns them. Checks 3 and 4 are unchanged.

* test(storage-postgres): cover catalog-check against the relations the engine creates

On a deployment with a separate data database, a table with a GSI, an LSI
and a vector index is neither orphaned nor missing; a planted relation no
catalog row names is dropped alone while an unrelated table and a table
created after the check are kept; a renamed index relation is reported
missing with its owner; rows in CREATING, UPDATING and DELETING count as
live. The binary is listed with the other PostgreSQL storage-level tests.

* docs: describe catalog-check and --fix for data relations without a catalog row

The troubleshooting entry told operators not to use --fix because the
command expected a different relation-naming scheme. It now describes
what the check compares, how --fix re-checks each relation under catalog
locks before dropping it, and keeps the manual comparison for inspection.

* fix(storage-postgres): wait only for index writers in catalog-check

The drop locked tables, indexes and vector_indexes in SHARE mode in one
statement and kept the locks until every drop had finished. An
UpdateTable adding a GSI on a new attribute writes indexes and then
tables, so the two could deadlock and the client got a 500. A drop
waiting on a relation another session held kept every catalog write on
the server waiting for up to 30 seconds. Under REPEATABLE READ the
re-read after the lock wait used a snapshot taken before it, and the
drop removed a live GSI relation.

Only a GSI add creates a relation before its catalog row commits, and it
holds ROW EXCLUSIVE on indexes from its insert to its end; every
relation name comes from an id generated when its row is inserted. A
SHARE lock on indexes alone therefore covers every path. It is taken in
attempts of 200 ms, 50 ms apart, within the 30 second budget, in a READ
COMMITTED transaction whose first statements take no snapshot, and it is
released right after the catalog read. Each drop then runs in its own
transaction with a 1 second lock timeout and without IF EXISTS: a
relation another session dropped first is reported as already gone, one
another session holds as failed, and no notice reaches the output.

The report waits for the index writers the same way before the catalog
read that decides orphans, and reports a relation orphaned only when a
second listing still has it. It reads the catalog a second time after
that listing and reports a relation missing only when both reads expect
it and the listing lacks it. Rows in CREATING are no longer expected to
have relations.

A catalog without data_database_connection_string, or with an empty
one, is refused again with the message the command gave before.

* test(storage-postgres): cover catalog-check against changes in flight

Split the catalog_check test binary into report, fix and support
modules, keeping its name for CI. The new tests cover a GSI add whose
relation exists and whose row has not committed, against the drop at the
default isolation and at REPEATABLE READ and against the check, with the
add's table write and another index write timed; an orphan another
session holds, with a CreateTable sent while the drop waits; a relation
another session dropped first; rows in CREATING or DELETING whose
relations are gone; a catalog without the data database setting; and a
DeleteTable, a dropped orphan and a new orphan landing between the
check's first catalog read and its second listing, held there by a
test-hooks pause.

* docs: state what catalog-check reports and drops while a server runs

The troubleshooting entry now says that the check reads the data
database's current schema and refuses a catalog without the data
database setting, that rows in CREATING are not reported missing, and
which reports can still be wrong while a server on another host changes
tables. The --fix paragraph describes the wait for GSI additions in
flight, the one second lock wait of each drop, the Already gone outcome,
and that every _ddb_ relation in the schema is taken as this
deployment's. The manual query filters on the current schema, as the
command does.

* test(storage-postgres): bound the held-orphan drop in its test

The holder session is released only after the drop returns, so a drop
without a lock timeout of its own would keep the test waiting. A 10
second timeout around the drop makes that case fail instead.

* fix(storage-postgres): lock indexes in catalog-check only for an unnamed relation

The report took the SHARE lock on indexes on every run. While that
request waits behind an open writer, every new write to indexes queues
behind it for up to one attempt, the index rows of a CreateTable
included. The check now reads the catalog first and waits for the index
writers only when a listed relation is unnamed, which outside a GSI add
in flight means a relation no row will name, so a check that finds every
relation named holds up no write. An attempt now lasts 100 ms instead of
200 ms.

* test(storage-postgres): check the catalog-check lock wait holds nothing else

The drop test against a GSI add in flight now reads pg_locks while the
drop waits for its SHARE lock on indexes, and asserts that the waiting
session holds no lock on tables or vector_indexes. Before, a lock of all
three tables passed the test: each attempt's 100 ms lock timeout ends
the wait before PostgreSQL's deadlock check runs, so the add's table
write still finished in time.

* test(storage-postgres): commit the GSI add while catalog-check waits

The drop test committed the add after a fixed 600 ms, which fell in the
50 ms pause between two lock attempts about a third of the time. The next
attempt then started after the commit, and a snapshot taken before the
lock still saw the row, so the REPEATABLE READ case passed without the
isolation fix. The test now commits only once pg_locks shows a SHARE
request on indexes that began less than 20 ms earlier, so the commit
lands while that attempt waits.

* docs: state that catalog-check waits for index writers only when needed

The troubleshooting entry still said the check always waits for the GSI
additions in flight and that each lock attempt lasts 200 ms. The check
waits only when it finds a relation no row names, and an attempt lasts
100 ms. A write to indexes that queues behind the granted lock also
waits for the one catalog read the lock is held for; the entry and the
comment on the attempt length now say so.

* docs: drop the count from the catalog-check wrong-report sentence

The troubleshooting entry opened its list of the reports that can be
wrong while a server runs with a count of them. It now states the
condition and lists them.

* fix(app): open the encrypted connection string row in catalog-check

Main (ExtendDB#1003) encrypts the data_database_connection_string row of a PostgreSQL catalog with a key ring under the ring's DEK. Main's catalog-check read the row and opened it in data_connection_text. Without a ring the command takes the row as stored. With a ring the KEK of [auth.encryption] key_file opens it, and the command refuses a ring when key_file is not set. test_data_database_connection takes the key and reads the row through data_connection_string, with the same rules.

This branch reads the row in the PostgreSQL store, in data_pool, for check_storage_relations and drop_orphaned_relations. The plain read gave ciphertext in a catalog with a ring. The two methods now take the key as test_data_database_connection does. data_pool reads the row through data_connection_string with that key. catalog-check passes the key source of [auth.encryption] (the KEK with key_file set, else the catalog key). data_connection_text has no caller now, so the commit deletes it. A missing or empty row in a catalog without a ring still gets the message of this branch. The catalog_check tests pass the catalog key, as the command does without key_file.

* test(storage-postgres): set warm_throughput in the catalog_check GSI input

Main (ExtendDB#474) added the warm_throughput field to GsiInput. The CreateTableInput of the catalog_check test deployment in support.rs builds gsi1 with a GsiInput literal, which did not compile after the merge. The literal now sets warm_throughput to None, as the other PostgreSQL storage tests do, so the test creates gsi1 as before.

* fix(app): set up the locked key store before catalog-check reads the KEK

catalog-check read the KEK of [auth.encryption] key_file with key_file::key_source and did not set up the locked key store first. The DEK that the KEK unwraps was then held in heap memory. verify and migrate read the KEK through util::status_key_source, which sets up the locked key store before the read, and catalog-check now uses that helper too. With key_file set, on a host where memory locking fails and require_locked_memory is true, catalog-check now refuses to run, as verify and migrate do there.

* test(storage-postgres): run the catalog-check relation check on a catalog with a key ring

No test ran check_storage_relations on a catalog whose data database connection string row is encrypted under the DEK of the key ring. set_data_connection_writes_the_row_under_the_ring now runs it after set_data_connection writes the row. With the KEK the check opens the row, and with the catalog key it returns an error.

* docs: state the DeleteTable order of main's ExtendDB#504 in the catalog-check texts

On a separate data database, main's ExtendDB#504 keeps the catalog row of a table DELETING until the drop of its data tables commits. It deletes the row after that drop. The catalog-check texts of this branch still said that a synchronous DeleteTable deletes the row before its drop. The lists of orphan reports in catalog_check.rs and troubleshooting.md no longer name that case, and troubleshooting.md no longer names a table among them. The example of a relation that another session drops first is now an UpdateTable that deleted a GSI. That change is in diagnostics.rs, in the fix test and in troubleshooting.md. The description of the report test no longer gives the old order.

* test(storage-postgres): fail the catalog_check tests when a job needs a server and has none

The catalog_check tests skipped when EXTENDDB_TEST_PG_CONNECTION_STRING was not set, also with EXTENDDB_TEST_PG_REQUIRED=1. With that setting and no connection string, all 13 tests passed. base_conn in tests/catalog_check/support.rs now makes the check that iam_leftovers.rs and stream_commit_order.rs make. When EXTENDDB_TEST_PG_REQUIRED has a value other than 0 and the connection string is not set, the test fails. The comment at integration.yml:772 gives this behaviour for every test of the crate.

* test(storage-postgres): create pgvector in the catalog_check data database

Deployment::new in tests/catalog_check/support.rs did not create the pgvector extension in the data database. Neither create_data_db nor migrations::migrate runs CREATE EXTENSION vector, and template1 of the pgvector/pgvector:pg16 image has only plpgsql. So pgvector() was false on both CI images and no test created vec1. With named_relations changed to name no vector index relation, all 13 tests passed.

Deployment::new now calls try_create_vector_extension on the data database. The run-postgres-storage-tests job sets EXTENDDB_EXPECT_VECTORS=1, and with that setting Deployment::new fails when the data database has no pgvector. Now 8 of the 13 tests fail with that change.

* test(storage-postgres): cover the end of the catalog-check index lock budget

No test reached the end of the 30 second wait for the index writers in flight. All tests passed without the deadline check in read_after_index_writers, and also without the budget message in catalog_check_error.

PostgresCatalogStore now keeps the budget in a field that new and with_secret_keys set to INDEX_LOCK_BUDGET. with_index_lock_budget, compiled only with test-hooks, makes a store with a shorter budget. The new test holds ROW EXCLUSIVE on indexes past a budget of 2 seconds. Then it asserts the error of the check and of the drop, and that the orphan is still there. Without the deadline check the test fails at its 10 second timeout. Without the budget message it fails on the error text.

* fix(storage-postgres): give the catalog-check index lock text only for the indexes lock

catalog_check_error gave the text "index changes in progress kept the index catalog locked for more than 30 seconds" for each error that lock_wait_failed accepts. Those are SQLSTATE 55P03, 40P01 and 57014. A 55P03 from read_catalog can come from a lock on tables or vector_indexes. With statement_timeout=50ms on the catalog sessions, the check gave that text after the first lock attempt. With ACCESS EXCLUSIVE held on vector_indexes and no index change in flight, it gave that text when the budget ran out.

check and drop_orphaned now return a CheckFailure. read_after_index_writers gives CheckFailure::IndexLock when the last attempt timed out on the SHARE lock on indexes after the deadline. Every other error is CheckFailure::Sql, and catalog_check_error gives its text unchanged. A new test runs both cases, and the store gives the server's own error in each.

* fix(storage-postgres): list the data relations that the search path reaches in catalog-check

storage_relations listed the relations in current_schema() only. The server and the drop resolve unqualified names through the search_path. With search_path = alt, public set for the role on the data database, the server kept serving the table in public. The check then reported its relations missing, because current_schema() was alt. A listing of every schema also passed all tests.

The listing now reads pg_class and keeps the relations for which pg_table_is_visible is true, which resolves names as the server's statements and the drop do. The new test sets that search path and plants a relation with the prefix in a schema off the path. It checks that nothing is missing or orphaned. Without the fix the test reports the 4 relations of the table missing. Without the visibility filter it reports the planted relation orphaned. troubleshooting.md now gives that scope, and its query by hand uses the same filter.

* fix(storage-postgres): refuse a key ring row that the key does not open as not configured

data_pool mapped every error of data_connection_string to DiagError::QueryFailed. Without the KEK, catalog-check refused a catalog with a key ring. It printed "Cannot compare data relations with the catalog: Query failed: the catalog has a key ring, ...". No query failed. data_pool now maps MigrationError::Refused to DiagError::NotConfigured, as for the absent setting. catalog-check then prints the refusal on its own, as it did before the check moved to the storage backend.

In key_ring_rows.rs, the check without the KEK passed on any error, also on a connection failure. It now asserts NotConfigured with the start of the refusal text. At the previous commit that assertion fails with the QueryFailed error.

* docs: state the catalog-check report stop after 30 seconds and the wait of each indexes write

troubleshooting.md gave the outcome of a wait for index writers that runs past 30 seconds for --fix only. The report without --fix stops there too. It prints the error that says so and no result of any check, and exits with status 1. The paragraph on the check now says so.

The paragraph on --fix said that a server's write to indexes waits at most 100 ms plus the one catalog read. That bound holds for each write. One CreateTable with a GSI writes indexes more than once and can wait that long at each write. The paragraph now says "Each write to indexes" and names that case.

The sentences that the search path commit changed in the same section are now split into shorter ones. The lead-in to the query by hand now says that the query lists the relations that no catalog id names, which is what it returns.

* test(app): run catalog-check as the binary against a PostgreSQL deployment

No test covered cmd_catalog_check.rs, and no workflow ran catalog-check against PostgreSQL. The store tests stop at PostgresCatalogStore. So nothing tested the call of status_key_source, the mapping of NotConfigured, the lines the command prints or its exit code.

crates/bin/tests/catalog_check.rs runs the extenddb binary on the deployment of the catalog_check storage tests, through their support module. The deployment has one orphaned relation and one missing GSI relation. The test asserts the whole output and exit status 1 of catalog-check --fix and of the report without --fix. Then it removes the data database setting and asserts the refusal alone on stderr. With the NotConfigured message prefixed as the other errors are, the test fails on that last line. The run-postgres-storage-tests job runs the test with EXTENDDB_TEST_PG_REQUIRED=1. The bin crate gets dev-dependencies on extenddb-core and on extenddb-storage-postgres with test-hooks, which exports the naming functions that the support module uses.

* fix(storage-postgres): turn off statement logging on the diagnostics store's catalog pool

The diagnostics store connected to the catalog with statement logging on. A catalog read that waited on a lock for more than 1 second then printed a slow statement line. That line held the full CATALOG_ROWS text and came between the lines of the catalog-check report. The binary writes its log to stdout. The diagnostics store factory now connects with disable_statement_logging, as data_pool does for the data database.

In the catalog-check binary test, the report without --fix now runs while another session holds ACCESS EXCLUSIVE on vector_indexes for 1.5 seconds. At the previous commit, the output then has a line "WARN sqlx::query: slow statement: execution time exceeded alert threshold". The line comes after "Connected to catalog.", and the test fails. With this change the output has no log line.

* style: format the catalog-check tests with rustfmt

The rustfmt check of fmt.yml reported four test files that the earlier commits of this round changed: crates/bin/tests/catalog_check.rs, and fix.rs, support.rs and key_ring_rows.rs under crates/storage-postgres/tests. This commit applies cargo fmt to them. No code changes.

* test(storage-postgres): check pgvector on the built catalog_check deployment

Deployment::new checked the pgvector setting before it built the Deployment. When the check failed, Drop did not run and the two scratch databases stayed on the server. The check now runs on the built Deployment through pgvector(), so a failure drops the databases as any other test failure does.

* test(storage-postgres): run the drop in the catalog-check failure test too

No test covered the locked flag in read_after_index_writers. Row 2 of other_catalog_failures_do_not_report_index_changes holds ACCESS EXCLUSIVE on vector_indexes. The check stops in read_catalog there, before it requests any lock on indexes. The drop calls read_after_index_writers at once. So its read under the SHARE lock is the path that the flag guards.

Each row of the test now also runs drop_orphaned_relations on the planted orphan and asserts the same error text as for the check. With the flag removed from the IndexLock arm, the test fails on row 2's drop. That drop then gives the text "index changes in progress kept the index catalog locked for more than 2 seconds, so nothing was dropped".

* docs: drop the catalog-check sentence on waits at each indexes write

troubleshooting.md said that a request can write indexes more than once, as a CreateTable with a GSI does. It said that such a request can then wait behind the command at each write. A CreateTable inserts all its indexes rows in one catalog transaction (create_table.rs, from the begin at line 161 to the commit at line 555). PostgreSQL does not make a transaction wait again for a lock that it holds already. So a CreateTable waits on the command once. This commit deletes that sentence. The sentence before it stays: each write to indexes waits behind the command for at most 100 ms plus the one catalog read.

* test: one helper for the catalog-check sessions that hold a lock

Four places in the catalog-check tests opened a session, ran BEGIN and then ran one lock statement. These were hold_relation in support.rs, the budget test in fix.rs, the failure test in report.rs and the binary test. support.rs now has one helper, hold(url, statement), that does this and returns the session. hold_relation and the three tests use it.

* refactor(storage-postgres): map the diagnostics store's connect errors once

The diagnostics store factory mapped the parse error and the connect error to ConnectionFailed with two identical closures. It now parses and connects in one async block and maps the block's error once.

* ci: set the PostgreSQL test settings once for the storage test job

Both test steps of run-postgres-storage-tests set EXTENDDB_TEST_PG_CONNECTION_STRING, EXTENDDB_TEST_PG_REQUIRED and EXTENDDB_EXPECT_VECTORS to the same values. The job's env now sets them once, with the comments that the first step had.

* refactor(storage-postgres): drop the unused Debug derive of CheckFailure

Nothing formats a CheckFailure with {:?}. catalog_check_error matches on it, and no caller unwraps a Result that holds one. This commit removes the derive.

* test(storage-postgres): use the hold helper in the open index write test

a_check_that_finds_every_relation_named_does_not_wait_for_index_writers
opened a catalog session, began a transaction and ran its UPDATE of
indexes inline. The hold helper in the support module does the same, so
the test now calls it.

* test(storage-postgres): check an ACTIVE index of a settling table in catalog-check

CreateTable inserts the GSI, LSI and vector index rows ACTIVE under a
table row that can be CREATING. DeleteTable leaves them ACTIVE under a
DELETING table row. named_relations expects an index relation only when
neither the index row nor its table row is CREATING or DELETING. No test
covered the table half: with "table_settled &&" removed from the index
rows, all 16 catalog_check tests passed.

rows_being_created_or_deleted_are_not_reported_missing now sets the
index and vector index rows back to ACTIVE before it moves the table to
DELETING and CREATING. With "table_settled &&" removed, the test fails
with the gsi1, lsi1 and vec1 relations reported missing.

* refactor(storage-postgres): classify undefined_table beside lock_not_available

The catalog-check drop compared the SQLSTATE of its error with its own
42P01 constant, through a copy of the sqlstate function of
migrations/connect.rs. data/ddl.rs already classifies lock_not_available
with sqlstate_is. It now has undefined_table beside it, and the drop
calls that. catalog_check.rs no longer has the constant or the copy.

* refactor(storage-postgres): share the data database read and connect of the diagnostics store

data_pool repeated three steps of test_data_database_connection: the
PostgresTarget for the catalog, the data_connection_string read and the
pool connect. data_connection_row and connect_data now do them for both.
Each caller keeps its own errors: test_data_database_connection reports
a failed read as "Query failed", and data_pool reports a refused row as
not configured.

The connect of test_data_database_connection now has the options of the
data_pool connect: two connections at most and statement logging off. It
opens one connection and runs no statement on it, so extenddb verify
prints the same lines.

* test(storage-postgres): assert the full catalog-check messages

Four asserts of the catalog-check tests compared only the start or the
end of a message. One is the key ring refusal in key_ring_rows.rs. Three
are in catalog_check/fix.rs: the Kept reason of a later table, the lock
text of a held orphan and the index lock budget text. Each message has a
fixed text, so each assert now compares the whole text.

* test(app): remove the catalog-check config directory when the test fails

The binary test removed its config directory only after its last
assert, so a failed run left the directory under CARGO_TARGET_TMPDIR.
A ConfigDir guard now removes it on drop, as Deployment drops its
databases.

* docs: say catalog-check waits for the index changes in flight

The troubleshooting entry said that the check and --fix wait for the
GSI additions in flight. The SHARE lock on indexes waits for every open
write to indexes, and the error text says "index changes in progress".
The entry now says "index changes in flight".

* style: put PostgreSQL and GetItem in backticks in the catalog-check docs

clippy::pedantic gave doc_markdown warnings on five doc comment lines
that this branch adds: four name PostgreSQL and one names GetItem. The
names are now in backticks, and the pedantic run of the touched crates
gives no warning on a line of this branch.
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
No conflicts. Main changed 13 of the files this branch touches, among
them the Cassandra read path (#945, LOCAL_QUORUM), the Cassandra and
PostgreSQL engine constructors (#1003) and the admin guide, in lines this
branch does not change.
rlunar pushed a commit to rlunar/extenddb that referenced this pull request Nov 25, 2026
…xtendDB#949)

* test(auth): move the scope and check order tests to scope_tests.rs

crates/auth/src/tests.rs held 613 lines. Lines 293 to 613 move to a new
file, crates/auth/src/scope_tests.rs, which lib.rs declares beside mod
tests. They hold nine tests of the request timestamp and credential
scope checks and of the order of the checks. The helpers that only
these tests use move with them: provider_without_credentials,
make_date_stale, SCOPE_DATE_MESSAGE, yesterday, signed_with_scope and
refusal.

The helpers that both files use stay in tests.rs and become pub(super):
MockCredentialStore and its fields, make_headers_with_auth, SECRET,
signed_headers and provider. rustfmt wraps the signature of
signed_headers, which is now longer than 100 columns.

No test body, assertion or name changes. The moved lines are
byte-identical to lines 293 to 613 of the old tests.rs. Before and
after the move, cargo test for extenddb-auth lists and passes the same
515 unit tests, nine of them now under scope_tests. tests.rs now has
296 lines and scope_tests.rs has 331.

* test(auth): the scope date is compared before the token expiry

DynamoDB compares the credential scope date before it checks whether a
session token has expired. Measured on 2026-11-10 in us-east-1 with
signed ListTables requests and temporary credentials, two sends per
case and the same answer each time:

- expired token, scope date of the X-Amz-Date day: 400
  ExpiredTokenException, "The security token included in the request
  is expired"
- expired token, scope date one day earlier: 400
  InvalidSignatureException, "Date in Credential scope does not match
  YYYYMMDD from ISO-8601 version of date from HTTP. " (the message
  ends with a space)

ExtendDB answers both cases the same way. authenticate() runs
check_scope before lookup_credential, and the lookup checks the session
expiry. The new test in scope_tests.rs checks that order for both
cases. It reads the session through CachedCredentialStore, so the
ExpiredTokenException type and message come from the expiry check in
CachedCredentialStore::lookup_credential. The same request with a
matching scope date authenticates through a CachedCredentialStore built
the same way when the session ends an hour from now. The expiry is the
only fault in the matching case. The measurement recorded the error
type after the "#" only, so the test does not compare the prefix.

signed_with_scope_and_token is signed_with_scope with an optional
session token, sent and signed. It sorts the signed header list, so
x-amz-security-token comes before x-amz-target, as in the measured
requests. signed_with_scope calls it with no token, so its existing
callers sign the same requests as before. credential() in tests.rs
becomes pub(super) for the new test.

* docs(security): list the SigV4 checks in the order the code runs them

The SigV4 section of the security model manual says its steps run in
the order listed. It listed the access key lookup before the X-Amz-Date
check and the credential scope check. BuiltinAuthProvider runs
validate_timestamp, then check_scope, then lookup_credential, and its
doc comment gives that as the service's order.

The list now follows the code. The X-Amz-Date check is step 3, the
scope check is step 4 and the key lookup is step 5. The scope step
names the date comparison that check_scope makes. The lookup step says
that the lookup checks the session expiry and refuses an expired
session at once with ExpiredTokenException, before the signature check.
The storage layer checks the expiry on a cache miss, and
CachedCredentialStore checks it on a cache hit. The lookup step also
says that the lookup reads whether the key is active, and that step 9
applies that decision. Step 9 now refers to steps 5 and 6 for the
deferred decisions.

DynamoDB checks the scope date before the session expiry (measured on
2026-11-10 in us-east-1). With an expired session token, a scope date
one day earlier answers InvalidSignatureException with the scope date
message. The same token with a matching scope date answers
ExpiredTokenException. The order of the X-Amz-Date, scope and key
lookup checks was measured on 2026-10-23, as the comment above
validate_timestamp records.

* test(auth): build the expiring session provider through provider_over

Main (ExtendDB#1003) removed the store type parameter and the region argument of BuiltinAuthProvider::new. The provider now takes a CachedCredentialStore, which holds the region, and CachedCredentialStore::new also takes a worker count. Main's tests build each provider through provider_over in tests.rs.

provider_with_a_session_expiring_at now builds its provider through provider_over. The session still reaches the expiry check of CachedCredentialStore::lookup, which runs after check_scope in authenticate. That check refuses a session past expires_at with ExpiredTokenException, with or without a cached entry.

* test(auth): import HeaderMap from http in the scope tests

ExtendDB#1009 removed axum from the dependencies of extenddb-auth. After the merge
of main, the lib tests stopped building at the axum import of HeaderMap and
HeaderValue (E0433). scope_tests.rs now imports the two types from http, as
tests.rs does on main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-blocker Must ship for its milestone's release v1 Needed for the 1.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants