Repository navigation
fix(storage-postgres): store attribute names containing U+0000 in the catalog - #833
Conversation
… catalog DynamoDB accepts U+0000 in a key attribute name, an index key attribute name and a projected attribute name. DescribeTable returns each name byte for byte (measured on 2026-09-18 and 2026-10-24, and again on 2026-11-04). PostgreSQL jsonb refuses U+0000, so CreateTable with such a name answered 500 on PostgreSQL. catalog_json stores U+0000 in the jsonb documents that carry attribute names as U+0001 U+0001, and U+0001 as U+0001 U+0002. Each read applies the inverse. A name without either character keeps its stored form. The documents are tables.key_schema, tables.attribute_definitions, indexes.key_schema, indexes.projection, backups.key_schema, backups.attribute_definitions, backups.vector_indexes, backup_definitions.definition, vector_indexes.vector_attribute, vector_indexes.search_schema and vector_indexes.projection in the catalog database, and gsi_pending.index_context in the data database. Item data does not go through the escape. Migration 6, attribute_name_escape, applies the escape once to each stored PostgreSQL document that holds U+0001. It has a catalog body and a data body, and each body runs in one transaction with its ledger row. It writes one note for each column that it changed. It is breaking, because a binary without the decoder reads an escaped name as another name. It is not convergent, because an escaped U+0001 and a raw U+0001 U+0002 are the same bytes. It does not apply to SQLite and Cassandra, which store these documents as JSON text, or to MongoDB, whose BSON strings hold U+0000. The upgrade manual, ADR-0023, CONTRIBUTING.md and the sample outputs name migration 6. The CONTRIBUTING.md example becomes migration 7. The no-pgvector CI job also runs the new migrations_name_escape tests. Closes #367
Main added migration 6, backup_catalog_index, which this branch had used for attribute_name_escape. The merge keeps main's migration 6 as it is and moves attribute_name_escape to id 7 in the registry, in the PostgreSQL module (the file, module, SOURCE and FINGERPRINT are now m0007_attribute_name_escape), in the golden fixture, which is now 0007_attribute_name_escape.txt, and in the SQLite, MongoDB and Cassandra NotApplicable arms. The RELEASED_THROUGH comment names 7. crates/storage/src/migrations/registry.rs: both sides added an entry at id 6. The result keeps main's BackupCatalogIndex at 6 and adds AttributeNameEscape at 7. crates/storage-postgres/src/migrations/mod.rs: both sides added an arm in migration() and an id in the transactional arm of runs_in(). The result has both arms and both ids. crates/storage-sqlite, storage-mongodb and storage-cassandra src/migrations/mod.rs: both sides added an arm. The result has main's BackupCatalogIndex arm followed by this branch's NotApplicable arm. crates/storage-mongodb/tests: main replaced the literal catalog version with MigrationId::LATEST.number(), which this branch had moved to 6. The result keeps main's form. migrations_fresh.rs lists id 7 as a not-applicable step and ledger row and names it in the reconverge comment, the later-binary rows use id 8, and the step counts in migrations_locks.rs and migrations_released.rs are 8. CONTRIBUTING.md: both sides renumbered the table_note example to 7. The result renumbers it to 8, the next free id after attribute_name_escape, and lists both new ids in the runs_in() example. docs/manuals/07-upgrade-manual.md: the result keeps main's sentence on migration 6 and its section on the backup catalog index, this branch's sentence that each migration is breaking on every backend it applies to, and this branch's description of the escape as migration 7. The sample outputs in the getting started guide, the quickstart, the admin guide and the install guides, and the row in the differences table, name migration 7. crates/storage-postgres/tests/catalog_nul_names.rs and migrations_name_escape.rs: main replaced BackupEngine with LegacyBackupReader, whose create and restore take a JobPermit. The two tests call create, describe, restore_source and restore with JobPermit::detached().
test_a_migration_6_that_fails_in_its_backfill_stays_pending_and_resumes expected migration 6 to be the only pending migration of a catalog at migration 5. This branch adds migration 7, so such a catalog has 6 and 7 pending. The check now asks for migration 6 among the pending migrations and for no pending migration below it.
|
General: you'll want to merge and resolve conflicts, and it may expand the scope of this PR. After merging from main, a restore will read the escaped names as the literal names, so a restored GSI keyed on a U+0001 name will have no items. crates/storage-postgres/src/restore_engine.rs:64-91 and crates/storage-postgres/src/backup_engine.rs:76-97 (on main) #740 added the new restore job, and #700 added the new backup job. They merged after this PR's base. There are three places where escaped columns are read or written "raw": restore_target_shape (restore_engine.rs:64-91 on main) reads tables.key_schema and tables.attribute_definitions with serde_json::from_value. |
|
The migration number is also going to need to be bumped again. Ping me after you merge with main, and I can approve. |
jcshepherd
left a comment
There was a problem hiding this comment.
Needs to be synced from main and conflicts fixed; additionally main will bring down a couple new areas where escaping will be needed. Once that is taken care of and the migration number refreshed, I can approve.
Main added migrations 7 (stream_pending), 8 (restore_progress) and 9 (warm_throughput). This branch used id 7 for attribute_name_escape. The merge keeps main's ids and moves attribute_name_escape to id 10. The registry, the PostgreSQL module and the SQLite, MongoDB and Cassandra NotApplicable arms use the new id. The module file is now m0010_attribute_name_escape.rs, with SOURCE and FINGERPRINT to match. The golden fixture is now 0010_attribute_name_escape.txt. The RELEASED_THROUGH comment names 10. crates/storage/src/migrations/registry.rs: both sides added an entry at id 7. The result keeps main's entries at 7, 8 and 9 and adds AttributeNameEscape at 10. crates/storage-postgres/src/migrations/mod.rs: both sides added arms in migration() and ids in the transactional arm of runs_in(). The result has main's three arms, then this branch's arm, and all four ids. crates/storage-sqlite, storage-mongodb and storage-cassandra src/migrations/mod.rs: both sides added arms. The result has main's arms, then this branch's NotApplicable arm. crates/storage-sqlite/src/migrations/tests.rs and released_tests.rs: both sides changed two tests to count only the migrations that have a body on SQLite. The result is main's form of each test. In tests.rs, main checks the applied and not_applicable counts, where this branch checked the applied count and the total. In released_tests.rs, both forms count the convergent migrations that have a body on SQLite. The Migration import that this branch added is no longer used, so the result drops it. crates/storage-mongodb/tests/migrations_fresh.rs: the result lists id 10 as a not-applicable step and ledger row, and the reconverge comment names it. The later-binary ledger rows use id 11, and the LATEST assertion is 10. migrations_locks.rs and migrations_released.rs count 11 steps. crates/storage-postgres/src/create_table.rs: main added the warm throughput record of each global secondary index. This branch writes the key schema and projection of that index through to_catalog_json. The result keeps both. crates/storage-postgres/src/backup_engine.rs: main moved the index read of the legacy restore copy into restore_indexes(). This branch read the key schema and projection in that copy through from_catalog_json. The result calls restore_indexes() from the copy, and restore_indexes() reads both documents through from_catalog_json. The import line keeps main's RestoreSource and this branch's catalog_json functions. CONTRIBUTING.md: main renumbered the table_note example to 10. The result renumbers it to 11, the next free id after attribute_name_escape. The runs_in() example lists main's three ids and AttributeNameEscape. docs/manuals/07-upgrade-manual.md: the result keeps main's text on migrations 6 to 9. This branch's sentences on the escape follow the paragraph on migration 9 and name migration 10. The sentence on kinds is main's, with migration 10 added to the breaking migrations. Step 4 of the general upgrade procedure names migration 10. docs/getting-started.md, docs/manuals/04-quickstart-setup-guide.md, 08-install-linux.md and 09-install-macos.md: the sample outputs show migration 10. The admin guide example and the row in the differences table also name migration 10. crates/storage-postgres/tests: main added warm_throughput to GsiInput, so the literals in catalog_nul_names.rs and catalog_nul_index_writes.rs set it to None. migrations_name_escape.rs names migration 10 in its test names, skip messages and assertions.
The backup job (#700) and the restore job (#740) merged after this branch's base. They read and write catalog documents that carry attribute names without the escape of catalog_json. - backup_catalog.rs: claim_backup and set_status bind backup_index.source_table_details_json through escape_json, and row_from_tuple reads it through unescape_json. Without the escape in claim_backup, PostgreSQL refuses a source table with U+0000 in a name, and CreateBackup fails. Without the escape in set_status, the job's last write fails, and the backup stays CREATING. Without the unescape, DescribeBackup returns the stored form of each name. - restore_engine.rs: restore_target_shape reads tables.key_schema and tables.attribute_definitions through from_catalog_json. Without it, a store-backed restore looks for the stored form of each key name on the items, and the restore fails. The merge commit before this one reads indexes.key_schema and indexes.projection through from_catalog_json in restore_indexes(), which main split out of the legacy restore copy. Migration 10 also rewrites backup_index.source_table_details_json, which migration 6 adds. The module docs of catalog_json.rs and of the migration, and step 4 of the upgrade manual, list the column. Tests: - catalog_nul_backup_jobs.rs is new. The first table has a U+0000 name and a U+0001 name in its key schema, and a GSI keyed on a U+0001 name. The backup job writes it to a filesystem store, and the restore job restores it. DescribeBackup and DescribeTable of the restored table return each name byte for byte. - The second table has items. Its key names and the key of one GSI hold U+0001, and the key of a second GSI holds U+0000. After the backup and the restore, a Query on the restored GSI returns the items. The PostgreSQL item columns cannot hold a name with U+0000 yet. So only the first table has U+0000 in its key schema, and it has no items. - The third test writes a backup_index row through claim_backup and set_status, and reads it back unchanged. It checks that the stored text holds the stored form of each name. - migrations_name_escape.rs: the golden test seeds two backup_index rows as a release before migration 10 wrote them. The fixture shows the raw names rewritten, the other row unchanged, and the note "backup_index.source_table_details_json: 1 document rewritten".
Main at 887b6e2 adds two commits since the previous merge. #842 lists what the audit log records. #840 refuses access key import unless allow_credential_import is true. Neither commit adds a migration, so attribute_name_escape stays at id 10. The merge has no conflicts. Both sides edited docs/manuals/07-upgrade-manual.md, docs/differences-from-dynamodb.md, docs/getting-started.md and docs/manuals/05-admin-guide.md. Main changed the text on credential import and audit logging, and added a v0.1.15 behavior change that needs no catalog migration. This branch changed the migration list, the sample outputs and the escape. The changes are in separate paragraphs and table rows. The Current Status section lists migrations 1 to 10. Each sample output and example still names migration 10, so the merge changes no line beyond main's.
|
@jcshepherd I merged main twice, 35edb77 in b3bd377 and 887b6e2 in cdd89ca. The migration is now 10. The three places you named now go through
Migration 10 also rewrites I searched The new test binary |
jcshepherd
left a comment
There was a problem hiding this comment.
Feedback addressed: thanks.
Main at 359718b is 13 commits ahead of the last merge. Three files conflicted. - crates/storage-postgres/src/stream_engine.rs: #515 rewrote describe_stream around stream_table_row and stream_lineage::describe_stream. The merge takes that code and decodes the key schema with from_catalog_json, as this branch did in the old describe_stream. - docs/differences-from-dynamodb.md: the U+0000 row of this branch and the stream disable and enable row of #515 both stay. - docs/manuals/07-upgrade-manual.md: the migration 10 paragraph of this branch stays, followed by the [backup.store] paragraph as #855 wrote it. The other stream code that #515 adds reads only the stream specification, which holds no attribute name. Against main, the merged tree changes the same 43 files with the same line counts as this branch did against its merge base.
#825 added insert_backup_row on main for extenddb backup sync, and the previous merge brought it into this branch. It bound backup_index.source_table_details_json as written. claim_backup and set_status write this column through escape_json, and row_from_tuple reverses the escape on every read. insert_backup_row was the one writer that skipped the escape. On PostgreSQL, sync could not adopt a store backup whose source table has U+0000 in a key, index key or projected attribute name. jsonb refuses the \u0000 escape, so the insert failed, and sync skipped the backup with a catalog error. The insert wrote a name that holds U+0001 followed by U+0001 or U+0002 as given, and row_from_tuple read it back as another name. DescribeBackup then returned other names in SourceTableDetails and SourceTableFeatureDetails for that backup. insert_backup_row now binds the document through escape_json, and the module doc of backup_catalog.rs names it among the writers of the column. catalog_nul_backup_jobs.rs has a new test. It inserts an AVAILABLE row through insert_backup_row with the source table whose names hold U+0000 and U+0001. It checks that the stored text holds the stored form of each name and no \u0000. It also checks that read_backup_row returns the document as given, with the key names of the source table unchanged.
This branch stores tables.key_schema through the escape of catalog_json. The key schema that stream_table_row returns is therefore in its stored form, and describe_stream decodes it with from_catalog_json. The doc comment of stream_table_row said only that the method returns the key schema. It now says that the key schema is in its stored form, which catalog_json::from_catalog_json decodes.
Main at cbc3680 adds #355 and #896 since the last merge. The merge is clean. Main changes the auth, server, config and app crates, the npm launcher and one line of crates/core/src/error/mod.rs. Of the files that this branch changes, main changes only docs/manuals/05-admin-guide.md, and the two edits do not overlap.
panicking_refresh_does_not_leak_inflight_flag slept a fixed 50 ms after the refresh that panics, and expected the next stale read to start a new refresh. On a busy CI runner the spawned task had not yet run and been dropped by then, so the flag was still set and the read was counted as refresh_skipped_inflight. It failed that way on main, on merge-queue runs for #827 and #833, and on this branch. A 60 ms delay before the panic reproduces it every time. Give the test a 60 s hard TTL, so a hard miss cannot hide a leaked flag, and wait with a 10 s deadline: first for the panicking refresh to run, then for a stale read to start a refresh that succeeds. With the RAII guard removed the test still fails, at the deadline.
Main at 672d07c adds #692 and #897 since the last merge. One file conflicted: docs/manuals/07-upgrade-manual.md, where #897 rewrote the [backup.store] section as several paragraphs and a list. The merge keeps the migration 10 paragraph of this branch, followed by the section as #897 wrote it. Against main, the merged tree changes the same 44 files with the same line counts as this branch did against its merge base.
Main at a55b2b6 adds #955, whose catalog migration 10, account_metrics, applies on all four backends. This branch had also taken 10, for attribute_name_escape. Main keeps 10, and attribute_name_escape is now migration 11 on every backend. These files conflicted: - crates/storage/src/migrations/registry.rs: AccountMetrics = 10 comes first, then AttributeNameEscape = 11. The RELEASED_THROUGH comment now says the v1.0 release PR raises it to 11. - crates/storage-postgres/src/migrations/mod.rs: both arms stay, and both ids are in the transactional arm of runs_in(). The arm now names the module m0011_attribute_name_escape. - crates/storage-sqlite/src/migrations/mod.rs, crates/storage-cassandra/src/migrations/mod.rs and crates/storage-mongodb/src/migrations/mod.rs: main's account_metrics arm comes first, then this branch's not applicable arm for migration 11. - crates/storage-mongodb/tests/migrations_fresh.rs: a fresh store records 10 as applied and 11 as not applicable. On a reconverge, 10 runs again and 11 does not apply. The rows that stand for a later binary's migration move to id 12, and the LATEST assertion expects 11. - CONTRIBUTING.md: the table_note example moves to 12, the next free id. Its runs_in() arm lists both new ids. - docs/manuals/07-upgrade-manual.md: main's migration 10 paragraph comes first, then this branch's paragraph as migration 11. The other places that named this branch's migration 10 now say 11: - The PostgreSQL module is renamed m0011_attribute_name_escape.rs. Its SOURCE, FINGERPRINT and doc comment name 11. - The golden fixture is renamed 0011_attribute_name_escape.txt. The tests in migrations_name_escape.rs read the ledger notes of 11 and expect "Skipped 11 attribute_name_escape". Their test names and scratch database names say 11. - The doc comment of catalog_json.rs names migration 11. - The upgrade manual lists migrations 1 to 11 and calls 1 to 7 and 9 to 11 breaking. Its step 4 paragraph calls the rewrite migration 11. - docs/differences-from-dynamodb.md names catalog migration 11. The step counts and the sample output now reflect 11 migrations: - MongoDB's migrations_locks.rs expects 12 steps, and migrations_released.rs expects 12 pending steps on a released catalog. - The sample output in docs/getting-started.md and manuals 04, 08 and 09 shows catalog migration 11. - The example in docs/manuals/05-admin-guide.md is a catalog at migration 10 that needs migration 11. Against main, the merged tree changes the same 44 files, with the same line counts, as this branch did against its merge base. Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
jcshepherd
left a comment
There was a problem hiding this comment.
Re-approved as merge conflicts are fixed.
Main at 06534e1 adds #228, #923, #475, #732 and #900 since the last merge. One file conflicted: crates/storage-postgres/src/backup_catalog.rs. #900 moves the insert statement of insert_backup_row into a new function, insert_unowned_row. The legacy reader's replace_with_index_row runs that function inside its own transaction. On this branch, the same insert stores source_table_details_json through escape_json. The merge keeps main's function and adds the escape to it, so both callers store the escaped form that row_from_tuple reads back. The module comment now names insert_unowned_row in place of insert_backup_row. Main adds no other write of a catalog document that carries attribute names. #900's legacy reader takes the source table from restore_source, which reads the stored documents through from_catalog_json and unescape_json. Against main, the merged tree changes the same 44 files, with the same line counts, as this branch did against its merge base. In backup_catalog.rs the escape of the unowned insert is in insert_unowned_row, and the module comment names that function.
The merge of main gives insert_unowned_row the escape of source_table_details_json. #900's replace_with_index_row calls that function, and its tests use ASCII names, for which the escape changes nothing. The catalog round trip now replaces its in-catalog backup by the index row that backup migrate-legacy writes. It checks that the stored document holds every name in its escaped form, and that read_backup_row returns the key names byte for byte.
Main took #833, which adds catalog migration 11, attribute_name_escape. It applies on PostgreSQL and does not apply on the other backends. This branch's migration, unique_access_key_ids, moves to id 12. The merge changes these to match: - The registry entry, the MongoDB code body (now m0012_unique_access_key_ids.rs), its fingerprint and its golden file. - The MongoDB test step lists, step counts and LATEST, and the ledger rows that stand for a later binary, now id 13. - The names and database tags of this migration's MongoDB tests. The two tests that stop at the migration before this one now migrate through migration 11. - The upgrade manual, the admin guide example and the sample output lines that name the latest migration. - CONTRIBUTING's worked example, which moves to migration 13. Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
Brings in main at ce3a51a (#833), 63 commits past the main that #399's head carries. docs/differences-from-dynamodb.md conflicted in two tables where both sides added rows after the same line. The Storage and Infrastructure table keeps #399's CancellationReasons row and main's BatchWriteItem and MongoDB single-item write rows. The Control Plane table keeps #399's Table ARN row and main's U+0000 and stream disable rows. #399 added creation_date_time to TableKeyInfo. Two test fixtures that main added since build a TableKeyInfo without it: the scripted BatchWriteItem engine fixture (crates/engine/src/batch_write_item/ scripted.rs, #475) and the isolated account fixture of the Cassandra integration tests (crates/storage-cassandra/tests/common/mod.rs). Both now set it to 0.0, as the other fixtures in those crates do. Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
* fix(storage): delete what a principal or account owns with it Inline policies and permissions boundaries are stored by principal name with no foreign key to the principal, and MongoDB and Cassandra link no IAM record to its principal or account. A delete left them behind, and a principal created later with the same name, or an account with the same id, got them and their permissions (ExtendDB#693, ExtendDB#694). - SQLite, PostgreSQL: a user, group or role delete also deletes its inline policies and boundary, in the principal's transaction. - MongoDB: a user delete also deletes its boundary and tags, a group delete its policies and memberships, a role delete its policies, boundary, tags and sessions. Errors are returned, not ignored. - Cassandra: a group delete also deletes its policies and memberships, a user delete its boundary, a role delete its policies, boundary, tags and sessions. - MongoDB, Cassandra: an account delete deletes the account's users, groups, roles and all they own. What a principal or account owns goes before its own record, so a failure leaves less, never more. - Every backend: a user, group or role create, after its own insert, also deletes rows stored under its name, so rows an earlier release left are cleared. MongoDB and Cassandra do the same for an account id. MongoDB now refuses a taken account id on create. - MongoDB, Cassandra: a user, access key, session or role of an account that no longer exists is unknown when signing in or assuming a role. extenddb_storage::iam_leftovers_conformance (feature test-util) checks this against a real database; each backend's suite runs it. Fixes ExtendDB#693. Fixes ExtendDB#694. * fix(management): refuse a policy or boundary on a missing principal Putting an inline policy or a permissions boundary on a user, group or role that does not exist answered 204 and stored it under the name, so it waited for the next principal created with that name. The management API and the console now answer 404 "IAM <type> not found", as IAM answers NoSuchEntity. A create also clears such rows, which covers a put that races a delete. * test: check that a deleted principal or account leaves nothing behind Each test gives a role, user, group or account everything it can own, deletes it, checks that its credentials stop working, creates it again with the same name or id, and checks that it starts empty. Two more check that a policy or boundary put on a missing principal is refused with 404. * docs: say what a delete removes, and the 404 for a missing principal The getting-started and admin guides list what a user, group, role or account delete removes. The upgrade manual has a v0.1.15 entry, the differences document compares the delete and the put with IAM's DeleteConflict and NoSuchEntity, and the storage guide states the cascade rules a backend must follow. * fix(storage-sqlite): roll back a principal write before returning A principal's create or delete returned an error, such as AlreadyExists or NotFound, by dropping its BEGIN IMMEDIATE transaction. Dropping a SQLite transaction only queues its rollback, and a BEGIN IMMEDIATE on the connection before the rollback ran failed with "attempted to call begin_with at non-zero transaction depth", so the next write on that connection answered 500. The creates and deletes now commit or roll back through one helper before they return. * test(cache): wait for the panicked refresh instead of sleeping 50 ms panicking_refresh_does_not_leak_inflight_flag slept a fixed 50 ms after the refresh that panics, and expected the next stale read to start a new refresh. On a busy CI runner the spawned task had not yet run and been dropped by then, so the flag was still set and the read was counted as refresh_skipped_inflight. It failed that way on main, on merge-queue runs for ExtendDB#827 and ExtendDB#833, and on this branch. A 60 ms delay before the panic reproduces it every time. Give the test a 60 s hard TTL, so a hard miss cannot hide a leaked flag, and wait with a 10 s deadline: first for the panicking refresh to run, then for a stale read to start a refresh that succeeds. With the RAII guard removed the test still fails, at the deadline. * test: generate the passwords in the account-delete tests The Cassandra and MongoDB tests that sign in a user of a deleted account hashed and checked a password written in the source, which CodeQL reports as a hard-coded cryptographic value (4 alerts). Generate it per run instead; the tests check the same thing. * fix(iam): clear a user's failed logins with its delete and create Failed logins are recorded under the sign-in name, account_id/user_name, with no link to the user. A user created with the name of a deleted one started with its failures: after five wrong passwords, a delete and a create of the same name, the right password got 429 from that address for up to 15 minutes. A user's delete and create now delete the failed logins under its sign-in name, and an account's delete those under every account_id/ name, on all four backends. SQLite and PostgreSQL do it in the same transaction as the principal, MongoDB and Cassandra with the rest of what the principal or account owns. The account prefix is matched literally (substr, starts_with, an escaped anchored regex, a filtered read of the partition keys), so another account whose id starts with the same digits keeps its failures. The conformance check covers the user's delete, a create over a name with failures, and the account's delete, including the other account. Three wire tests send the reviewer's sequence. Both fail without the change. The per-address limit is unchanged. * test(storage-mongodb): move the IAM delete tests to tests/ The two MongoDB tests that check a deleted principal or account leaves nothing behind lived in src/management_store/live_tests.rs, ignored unless run with --ignored. Move them to tests/iam_leftovers.rs as direct integration tests: they call the catalog store against a live replica set with no ExtendDB server in between, as the Cassandra crate's tests/direct_integration.rs does. They use the migration tests' Deployment for their scratch databases, and skip without EXTENDDB_TEST_MONGODB_URI unless EXTENDDB_TEST_MONGODB_REQUIRED is 1, which run-mongodb-tests sets. The one crate-private item they need, MongoCatalogStore::on_database, is reached through on_database_for_tests, compiled only with the test-util feature that the crate's test builds enable. * test(storage): check failed logins as present, and log no sign-in names On Cassandra, login_attempts is keyed by (principal, attempted_at) with attempted_at in milliseconds, so the conformance check's three back-to-back failures can land in one millisecond and overwrite each other: cassandra-storage counted 2 where the check expected 3. The check is about failures going away, so it now asserts they are present before the delete and in the other account afterwards, and absent where a delete or create clears them. The assertion and panic messages named the sign-in name, which carries the account id; CodeQL reports that as cleartext logging. They now name a fixed label instead. --------- Co-authored-by: Hitesh Sharma <hts@amazon.com>
…g name tests Main's #833 added two storage tests that add a GSI with UpdateTable and expect UpdateTable to build the index before it returns. On this branch UpdateTable returns while the new index is CREATING, and a task of its own backfills the index and flips it to ACTIVE. - catalog_nul_index_writes::a_backfill_and_the_recovery_sweep_read_the_names_from_the_catalog read the rows of by_u1 right after UpdateTable and found none, because the build task had not yet backfilled the index. It now waits for the index to be ACTIVE before it reads the rows. Its comment on the ownership lock now names the build task that UpdateTable starts. - catalog_nul_names::names_with_u0000_and_u0001_round_trip_through_the_catalog called DeleteTable right after the UpdateTable that adds gsi2. DeleteTable refuses a table with a CREATING index, so the call failed with IndexesInUse. It now waits for gsi2 to be ACTIVE first. Both tests use wait_active from catalog_nul_support. It now waits for the table and each of its indexes to be ACTIVE. Its other caller waits for a restored table, and the restore flips the table and its indexes to ACTIVE in one transaction. This commit keeps every assertion of both tests.
This merge brings in 98 commits of main through 2ef5613. They include the 0.1.15 and 1.0.0 releases, which freeze catalog migrations 1 to 12 (#1069), and the store-backed backup and restore jobs (#671, #700, #740). The stream_pending table (#819, migration 7) holds a stream record until its write commits. The PostgreSQL catalog stores attribute names through an escape (#833, migration 11). The escape migration of this branch becomes migration 13, escape_control_chars, the next free id after the released migrations. The change covers the registry entry, the module m0013_escape_control_chars and the fingerprint 0013_escape_control_chars/postgres/1. It also covers the golden file 0013_escape_control_chars.txt, the arms on SQLite, MongoDB and Cassandra, the transactional arm of runs_in() and the test names. The worked example in CONTRIBUTING.md moves to migration 14. Conflict resolutions: - registry.rs and the four migration() tables: main's ids and arms 6 to 12, then 13. - PostgreSQL migrations/mod.rs: main's modules, arms and target fields, and the other_sessions_allowed field of this branch. The store that a status read of the catalog alone opens does not check sessions. - gsi_queue.rs: the item images go through item_to_json and json_to_item. The index context goes through main's to_catalog_json and from_catalog_json. worker_partition() gives the partition. - tx_helpers.rs: the stream record goes to stream_pending as the text of its escaped form, and record_bytes is the length of that text. - stream_engine.rs: main's write_stream_record stub. Every write stores its stream record in its own transaction. - snapshot_engine.rs: main's page reader decodes each row with decode_row(). The tests of both sides stay. - backup_engine.rs, data/index.rs and data/vector_index.rs: the imports of both sides. - tests/backup_restore.rs: main's file. The restore test of this branch moves to tests/backup_restore/control_chars.rs and calls create() in place of create_backup(). - tests/migrations_golden.rs: main's shared golden() and notes(). The migration 13 tests migrate the fixture through migration 12 first. - The MongoDB and SQLite migration tests: main's side, with migration 13 in the counts. - CONTRIBUTING.md, the upgrade manual and the install guides: main's side, with migration 13 added. One writer and one reader of item documents on main now use the escape. The store-backed restore writes item_data through item_to_json, and the legacy backup reader decodes backup_items through json_to_item.
Migration 11 (#833) escapes gsi_pending.index_context once, with the mapping that migration 13 uses. The data body of migration 13 also rewrote that column. A store upgraded through both migrations then held the context escaped twice, and a name with U+0001 read back as U+0001 U+0002. Migration 13 now rewrites only the item images of gsi_pending, old_item and new_item. Its worker_partition recompute reads the context through from_catalog_json, as the index worker reads it. catalog_json.rs had its own copy of the escape. It now calls escape_json_strings and unescape_json_strings from extenddb_storage::util. Its round trip test over the five-character alphabet goes, because control_chars.rs tests the same alphabet. Migration 11 keeps its frozen copy. The new test migrations_11_and_13_escape_a_queued_index_update_once queues an index update with U+0001 in its names, as a release before migration 11 wrote it. It runs migrations 11 and 13 in one upgrade. Then it checks that the context and the item image each hold the escape once and read back as written.
… 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
What
This PR lets a PostgreSQL deployment store attribute names that hold U+0000 in its catalog. DynamoDB accepts U+0000 in a key attribute name, an index key attribute name and a projected attribute name.
DescribeTablereturns each name byte for byte (measured on 2026-09-18 and 2026-10-24, and again on 2026-11-04). PostgreSQLjsonbrefuses U+0000. So on main at 25ee109,CreateTablewith such a name answers 500 on PostgreSQL.The stored form
crates/storage-postgres/src/catalog_json.rsdefines the stored form of thejsonbdocuments that carry attribute names. The server stores U+0000 as U+0001 U+0001, and U+0001 as U+0001 U+0002. It stores every other character as itself, so a name without these two characters keeps its old stored form. Every write of these documents goes through the escape, and every read goes through the inverse. The documents are:tables.key_schema,tables.attribute_definitions,indexes.key_schema,indexes.projection,backups.key_schema,backups.attribute_definitions,backups.vector_indexes,backup_definitions.definition,backup_index.source_table_details_json,vector_indexes.vector_attribute,vector_indexes.search_schemaandvector_indexes.projectiongsi_pending.index_context, which holds the index context of the queued index updatesThe item documents do not go through the escape. #368 covers U+0000 in item data.
Migration 10,
attribute_name_escapeThe migration uses the framework of ADR-0023. On PostgreSQL it applies the escape once to each stored document that holds U+0001. Releases before migration 10 stored the names raw. Without the migration, a stored name with U+0001 followed by U+0001 or U+0002 would read back as another name.
tables.key_schema: 1 document rewritten.Kind::Breaking. A binary without the decoder reads an escaped name as another name.migrate --yes --reconvergeskips it.The backup and restore jobs
#700's backup job writes the source table, attribute names included, to
backup_index.source_table_details_jsonthroughclaim_backupand its status write. #825'sextenddb backup syncwrites the same column throughinsert_backup_rowwhen it adopts a store backup.row_from_tuplereads that column for everybackup_indexread. Without the escape, the insert for a source table with a U+0000 attribute name fails on PostgreSQL. #740's restore job readstables.key_schemaandtables.attribute_definitionsinrestore_target_shape, andindexes.key_schemaandindexes.projectioninrestore_indexes. Withrestore_indexesraw, a restored GSI keyed on a U+0001 name has no items. Withrestore_target_shaperaw, the restore of a table with a U+0001 key name removes its target.7739167 escapes both writes and decodes the reads in
row_from_tupleandrestore_target_shape. bfeee77 escapes theinsert_backup_rowwrite. That function reached the branch in the merge c31bc91 and bound the document without the escape. The module doc ofbackup_catalog.rsnow names the three writers of the column.restore_indexesgets its decode in the merge commit b3bd377. Main moved the index read into that function. This PR decodes that read, so the merge moved the decode with it. Migration 10 rewritesbackup_index.source_table_details_jsontogether with the other catalog documents.Migration 3,
sort_key_definitions, is convergent, somigrate --yes --reconvergeruns it again on a catalog at migration 10. There it reads the stored form. Itsrepair_tablesstep compares and writes stored names, so it stays consistent. Itsrepair_backupsstep looks up a missing sort key name in the item data, which holds raw names. That lookup misses a sort key name that holds U+0000 or U+0001. The case needs a backup that lost its sort key definition to theUpdateTablefault of #259, written to a migrated catalog by an older release. This PR does not change migration 3.Documentation and CI
docs/manuals/07-upgrade-manual.mddescribes migration 10 in step 4 of the general upgrade procedure, withbackup_index.source_table_details_jsonin its list of documents.docs/differences-from-dynamodb.mdhas a row for these names.docs/adr/0023-catalog-migrations.mdstates that each migration is breaking on every backend it applies to. Before this change, it named five migrations. The upgrade manual keeps main's sentence, which now says that migrations 1 to 7, 9 and 10 are breaking.CONTRIBUTING.mdrenumbers its example migration from 10 to 11.catalog migration 10..github/workflows/integration.ymlalso runs the new test binarymigrations_name_escape.This PR replaces the catalog part of #531. #531 added catalog version 0.0.5 with its own migration code. Main migrates through the ADR-0023 framework, so this PR builds its migration on that framework.
Main now runs migrations 1 to 9: #671 took 6,
stream_pendingis 7, #740 took 8 and #474 took 9. So this PR's migration is now 10. #368, #819 and #823 add migrations too. Each pull request that merges after another one of them must take the next free id.The merges with main
The merge of main at 38992eb (5a0de15) moved this PR's migration from 6 to 7. It also ported
catalog_nul_names.rsandmigrations_name_escape.rstoLegacyBackupReader, which replacedBackupEnginein #671. The assertions did not change.The merge of main at 35edb77 (b3bd377) moves the migration from 7 to 10. It keeps main's migrations 7 to 9 in the registry, in each backend's migration list, and in the MongoDB and SQLite migration tests. It also sets main's new
GsiInput.warm_throughputfield in this PR's tests. The merge of main at 887b6e2 (cdd89ca) has no conflicts.The merge of main at 359718b (c31bc91) has three conflicted files. In
crates/storage-postgres/src/stream_engine.rs, #515 rewrotedescribe_streamaroundstream_table_rowandstream_lineage::describe_stream. The merge takes that code and decodes the key schema withfrom_catalog_json, as this branch did in the olddescribe_stream. Indocs/differences-from-dynamodb.md, the U+0000 row of this branch and the stream disable and enable row of #515 both stay. Indocs/manuals/07-upgrade-manual.md, the migration 10 paragraph of this branch stays, and the[backup.store]paragraph of #855 follows it.The other stream code that #515 adds reads only the stream specification, which holds no attribute name. 7f24956 updates the doc comment of
stream_table_row. The key schema it returns is in its stored form, whichcatalog_json::from_catalog_jsondecodes. The merge of main at cbc3680 (d821cb5) is clean. Of the files that this branch changes, main changes onlydocs/manuals/05-admin-guide.md, and the two edits do not overlap. The merge of main at 672d07c (9b4519b) has one conflict, indocs/manuals/07-upgrade-manual.md, where #897 rewrote the[backup.store]section. The merge keeps the migration 10 paragraph of this branch, followed by that section as #897 wrote it.Why
Closes #367. The issue reports two faults on PostgreSQL. #830, now merged, fixes the table name fault. This PR fixes the attribute name fault.
Testing done
On 2026-11-10. cdd89ca, the tip before the merge c31bc91, differs from 7739167 only by main's #842 and #840, which change docs and
crates/server. The runs marked "escape commit" ran on 7739167 before its last change, which adds deadlines to two waits incatalog_nul_backup_jobs. After that change the binary passed again, 3 of 3, in apostgres:16container.cargo fmt --all -- --check: clean on each of the three new commits.cargo +1.97.0 clippy --locked --all-targets -- -D warnings: clean on b3bd377 forextenddb-storage,extenddb-storage-sqlite,extenddb-storage-mongodb,extenddb-storage-cassandraandextenddb-storage-postgres. Clean on 7739167 forextenddb-storage-postgres, the one crate that commit changes.cargo check --locked --workspaceon cdd89ca: clean.extenddb-storage240,extenddb-storage-postgres84,extenddb-storage-sqlite283,extenddb-storage-mongodb172 (66 ignored),extenddb-storage-cassandra129 andextenddb-engine636 passed. Two SQLitebackup_catalog::write_lock_testsfailed on the test host. There the filesystem backup store refuses its root, because a parent directory belongs to another user. Both pass in a container.cargo test --locked -p extenddb-storage-postgres --testson the escape commit, againstpgvector/pgvector:pg16: 409 passed and 2 ignored, in the library and 30 test binaries. 5 more tests failed on the test host for the same store root reason: 3store_identitytests inbackup_restorefrom main, and 2 tests of the newcatalog_nul_backup_jobs. Both binaries pass in apostgres:16container, 3 of 3 each.postgres:16without pgvector: 50 passed, 0 failed. By binary:migrations_crash9,migrations_fresh6,migrations_golden7,migrations_guards7,migrations_name_escape2,migrations_released12 andmigrations_runs7.mongo:7replica set) on the escape commit:migrations_fresh8,migrations_locks11 andmigrations_released5 passed.At 7739167 the new binary
catalog_nul_backup_jobshas three tests:backup_indexrow keeps such names throughclaim_backupand the status write.One at a time, a raw
restore_target_shape,restore_indexes,row_from_tupleor status write fails at least one of these tests. The code of the merge commit b3bd377 fails all three. The golden test of migration 10 covers abackup_indexrow that holds U+0001.bfeee77 adds a fourth test. A
backup_indexrow thatinsert_backup_rowinserts keeps such names. The stored text holds the stored form of each name and no escaped U+0000, andread_backup_rowreturns the document as given.With the
insert_backup_rowchange of bfeee77 reverted in the working tree, the fourth test fails at the insert. PostgreSQL answersunsupported Unicode escape sequence. On the test host the test ran alone, 0 of 1 passed. In the container the whole binary ran, 3 of 4 passed, and only the fourth test failed.On the commits after the merge c31bc91, on 2026-11-10 and 2026-11-11:
cargo fmt --all -- --check: clean on c31bc91, 7f24956, d821cb5 and 9b4519b.cargo +1.97.0 clippy --locked -p extenddb-storage-postgres --all-targets -- -D warnings: clean on c31bc91, 7f24956, d821cb5 and 9b4519b.cargo test --locked -p extenddb-storage-postgres --lib: 84 passed on c31bc91, and 84 passed again on 7f24956.catalog_nul_backup_jobson 7f24956, againstpgvector/pgvector:pg16: 2 passed and 2 failed on the test host. The two tests that calldispatchfail there. The filesystem backup store refuses its root, because a parent directory belongs to another user. In apostgres:16container, 4 passed and 0 failed.backup_restorethat callinsert_backup_row, on 7f24956: 2 passed.Earlier, on the branch at base 25ee109, before the merges of main:
cassandra:4.1):--test migrations21 passed, and--test migrations_stopped7 passed.tests/python/test_nul_attribute_names.py(5 rows),test_tablesandtest_gsi.cassandra:4.1)mongo:7replica set)The 5 new rows against a main 25ee109 PostgreSQL binary: 4 failed with 500
InternalServerErroronCreateTable, and the U+0001 row passed.Against Amazon DynamoDB in us-east-1 on 2026-11-04, from 22:45 to 22:56 UTC: the 5 new rows passed.
CI at 9b4519b: 57 of 57 checks passed. The MongoDB workflow passed on its second attempt. On the first,
test_all_writers_succeedgot InternalServerError, which #577 tracks.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: ADR-0023, catalog migrations. This PR adds migration 10 under it.
Breaking changes
Migration 10 is breaking on PostgreSQL. A binary without migration 10 refuses a PostgreSQL catalog that has it, with exit status 4. To roll back, restore the backup taken before
extenddb migrate --yes. SQLite, Cassandra and MongoDB record migration 10 as not applicable, which is additive.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.