Repository navigation
fix(engine): check a restore's TargetTableName with the restore's rules - #1247
LeeroyHannigan wants to merge 6 commits into
Conversation
RestoreTableFromBackup checked TargetTableName with CreateTable's check. So a name of two characters got CreateTable's member text, and an absent name got the text for a null member. DynamoDB answers with the restore's own texts. DynamoDB first counts the name's length in UTF-16 code units. A length outside 3 to 255 is "TableName must be at least 3 characters long and at most 255 characters long". A name within those bounds is then checked against the model's constraints at targetTableName, which count characters. An absent name is "The parameter 'TableName' is required but was not present in the request". So ab, an empty name, a*, 256 characters, one U+1F600, two U+00E9 and 128 U+1F600 get the length text. Two U+1F600 and 64 U+1F600 get the constraint text. The SourceTableName of RestoreTableToPointInTime counts its length the same way. The restore now checks TargetTableName with the check of SourceTableName, renamed check_restore_table_name. It takes the member path and counts the length in UTF-16 code units, where it counted characters. The server's name check gives the same answer for a target name outside the pattern. Measured in us-east-1 on 20 Nov 2026. Fixes #1224.
…et-name #1009 moved crates/engine/src/backup/pitr.rs to crates/engine/src/backup_requests/pitr.rs, and the pitr re-exports from backup.rs to backup_requests.rs. Git applies the pitr.rs and pitr/tests.rs changes of this branch at the new paths. Conflicts: - backup.rs: the pitr re-exports at the end of the file, which main removed. This merge drops them. - lib.rs: the pub use backup::{...} list. This merge keeps main's list. lib.rs now re-exports check_restore_table_name from backup_requests, beside refuse_point_in_time_recovery. The restore in backup.rs calls pitr::table_name_member, pitr::check_restore_table_name and table_name_bounds, which are now in backup_requests. So the pitr module, table_name_member and table_name_bounds become crate-visible, and backup.rs imports pitr and table_name_bounds from backup_requests. A crate-visible re-export of table_name_member would be an unused import in the WebAssembly build, which does not compile backup.rs.
The module doc of table_name_gate.rs listed targetTableName among the locations of the bare-name sentence. A RestoreTableFromBackup TargetTableName gets the answer of check_restore_table_name, which a later item of the list describes. The bare-name list now gives targetTableName and sourceTableName as members of RestoreTableToPointInTime.
check_restore_table_name is public and returns a Result, and clippy::missing_errors_doc asks for the section.
navareamol
left a comment
There was a problem hiding this comment.
I think the tests do not pin the deployment's table name bounds for the restore target. In crates/engine/src/backup.rs, when I replaced table_name_bounds(limits) with (3, 255), the engine lib tests (934) and the server lib tests (519) all still passed. The restore tests use the default limits, and the one bounds test calls check_restore_table_name with (5, 10) directly. On main the target name followed the configured bounds, so this would be a regression nobody sees. I measured the current code with min 5 and max 20 on SQLite and it behaves as the description says ("abcd" gets "at least 5 characters long and at most 20"). Could you add an engine test that runs restore_table_from_backup with those limits and a four character target?
The wasm check fails at this head on web_time::Instant against std::time::Instant in crates/core/src/metrics/collector.rs:60, which #1482 fixed on main. mongodb-rust fails in the auth crate on secmem::tests::init_refuses_under_a_low_memlock_limit_then_starts_unlocked, and mongodb-integration fails behind it. That secmem test failed on three other runs on 25 Nov and main's later MongoDB runs pass. I merged main 222d80a into this head locally: no conflict, the engine, server and core lib tests pass, and the two wire files plus my probes pass on SQLite. Could you merge main so CI runs on that tree?
A question on the order. With the target "ab" and an invalid BillingModeOverride, ExtendDB answers only the billingModeOverride enum fault, and with no BackupArn it answers the backupArn null fault. With the target "a*" and the same two requests it answers the length text, because the server check runs first. The description measured "ab" against an override name and another account's BackupArn. Has DynamoDB been asked "ab" with an invalid BillingModeOverride, and with no BackupArn? If it answers the name first, I think #1245 covers more than names outside the pattern.
I will approve once the bounds test is in and CI is green on a branch with main merged.
…et-name The parent branch now contains main at b3510a9.
…unds The restore tests used the default limits, and the one bounds test called check_restore_table_name with (5, 10) directly. With table_name_bounds(limits) replaced by (3, 255) in the restore, every engine test passed. The new test runs restore_table_from_backup with the bounds 5 and 20 and the names abcd and 21 x characters.
|
navareamol
left a comment
There was a problem hiding this comment.
No open points on this PR at 460ac61.
The bounds test is in. a_restore_target_name_is_checked_against_the_deployments_bounds runs restore_table_from_backup with bounds of 5 and 20 and expects the length text with those bounds and no backup read. With table_name_bounds(limits) replaced by (3, 255) in the restore it fails, because abcd then reaches the backup lookup. I also ran the server on SQLite with min 5 and max 20: abcd, an empty name and 21 x answer "at least 5 characters long and at most 20", and abcde and 20 x restore. The server's own check still names 3 and 255 for a name such as a*, which is #992.
CI is green on this head, 66 of 66 checks including wasm, mongodb-rust and mongodb-integration, and main as it is now merges into it with no conflict. The engine lib tests (982) and the server lib tests (526) pass, and so do tests/test_backup_restore_fidelity.py and tests/test_continuous_backups.py. The set of names the server refuses is unchanged over 13.3 million names.
On the order, your measurements answer my question. With no BackupArn, the BackupArn comes first in DynamoDB and in ExtendDB, and only the text differs (#1272). With ab and BOGUS, DynamoDB answers the length text and ExtendDB answers the enum fault, because the restore parses the override values at step 1, before the target length. That is the first row of #1271. The server's pattern check passes ab, so #1245 does not cover it, as you say.
I approve this PR.
Changes since the last review
864140c353merges fix(engine): check the IndexName of a restore's index override #1225's new head26dcbe1d73, which containsmainatb3510a93ee. The merge has no conflict, and the lines this PR changes stay the same.460ac61c82addsa_restore_target_name_is_checked_against_the_deployments_boundstocrates/engine/src/backup/tests.rs. It runsrestore_table_from_backupwith[limits]bounds of 5 and 20. The targetsabcdand 21xcharacters get the length text with those bounds, and the restore reads no backup. Before, the engine tests passed withtable_name_bounds(limits)replaced by(3, 255)in the restore. Now this test fails.abwith a badBillingModeOverrideand with noBackupArn. It also gives the test runs at the new head.What
RestoreTableFromBackup checked
TargetTableNamewith CreateTable's check, so most bad names got CreateTable's texts attableName. It now checks the name with the restore's own check, as DynamoDB does:TableName must be at least 3 characters long and at most 255 characters long.targetTableName, which count characters.The parameter 'TableName' is required but was not present in the request.The check is the one that
SourceTableNameof RestoreTableToPointInTime used, incrates/engine/src/backup_requests/pitr.rs. Its new name ischeck_restore_table_name. It now takes the member path, and it counts the length in UTF-16 code units, where it counted characters. The measurements ofSourceTableNameshow the same count.The server's table name check in
crates/server/src/table_name_gate.rsruns before authorization and refuses a name outside the pattern. For aTargetTableName, it now gives the answer ofcheck_restore_table_name, with the bounds 3 and 255. The set of names it refuses does not change, so a name with U+0000 still never reaches the authorization lookups. A deployment can set other table name bounds under[limits]. There the server's answer still names 3 and 255, where the engine checks the deployment's bounds. #992 covers the fixed bounds of the server's check, this answer among them.The server's check passes an empty
TargetTableNameand one that starts witharn:and has no U+0000. It answers every other name outside the pattern. The engine refuses an empty name for its length, so only anarn:name can get the engine's pattern clause attargetTableName. No test sends one, because DynamoDB's answer to it for a caller with the target's permissions is not measured. On 25 November 2026, a caller withoutdynamodb:Scanontable/<TargetTableName>gotAccessDeniedExceptionfor it, so DynamoDB checks the permissions on that resource first.The base of this PR is #1225, which changes the same step of the restore.
Why
DynamoDB's answers, measured in us-east-1 on 20 November 2026. Each request went out twice and got the same answer both times. Each
BackupArnnames a backup that does not exist.LENGTHstands forTableName must be at least 3 characters long and at most 255 characters long.TargetTableNameabLENGTH1 validation error detected:with the length clause attableNameLENGTH1 validation error detected:withMember must have length greater than or equal to 1attableNamea*LENGTH2 validation errors detected:with the length clause and the pattern clause attargetTableNameLENGTH1 validation error detected:withMember must have length less than or equal to 255attableNameLENGTHtargetTableNameLENGTHtargetTableNameLENGTHtargetTableNameab, with a GSI override or an LSI overrideLENGTHtableNameThe parameter 'TableName' is required but was not present in the request1 validation error detected: Value null at 'targetTableName' failed to satisfy constraint: Member must not be nulltargetTableNamea btargetTableNametargetTableNameBackupNotFoundExceptionBackupNotFoundExceptionWith this change, ExtendDB answers each of the 14 rows as DynamoDB does.
Fixes #1224
Merge of 25 November
On 25 November #1137 merged
main, where #1009 movedcrates/engine/src/backup/pitr.rstocrates/engine/src/backup_requests/pitr.rs. So this branch conflicted with #1137 and withmainincrates/engine/src/backup.rsandcrates/engine/src/lib.rs.2964ee548merges #1225's head and resolves them:pitr.rsandpitr/tests.rsat their new paths.backup.rsdrops itspub use pitr::...lines, as main did, and importspitrandtable_name_boundsfrombackup_requests.lib.rskeeps thepub use backup::{...}list of main and re-exportscheck_restore_table_namefrombackup_requests, besiderefuse_point_in_time_recovery.backup_requests.rs, thepitrmodule andtable_name_boundsbecome crate-visible, and so doestable_name_memberinpitr.rs. A crate-visible re-export oftable_name_memberwould be an unused import in the WebAssembly build, which does not compilebackup.rs.At this head, the conflicts with other open PRs:
table_name_boundsto core. They conflict withmainincrates/engine/src/backup_requests.rs. If one of them merges first, importtable_name_boundsfrom core inbackup.rs.check_restore_table_nameincrates/engine/src/backup_requests/pitr.rs.Testing done
At
460ac61c82, each cargo command with--locked:cargo +1.97.0 test -p extenddb-core -p extenddb-engine -p extenddb-server -p extenddb-storage --lib: core 1259 passed and 1 ignored, engine 982 passed, server 521 passed and 5 failed, storage 294 passed. On this host 5backup_store::testsfail on every branch, because uid 65534 owns/local/home.cargo +1.97.0 fmt --all -- --checkis clean.cargo +1.97.0 clippyof the four crates with--all-targets -- -D warningsis clean, and so is the same command with--features extenddb-engine/backup-test-hooks.cargo +1.94.0 checkof the four crates with--all-targetsis clean.cargo +1.97.0 test -p extenddb-wasm-adapter: the 3 unit tests pass, and the parity test passes over the 279 cases of the corpus. The clippy step of the WebAssembly workflow, run on this branch, is clean.pitr/tests.rs,backup/tests.rsand the table name check's tests. With the change reverted, they fail.table_name_bounds(limits)replaced by(3, 255)in the restore,a_restore_target_name_is_checked_against_the_deployments_boundsfails atabcd, which then getsBackupNotFoundException.tests/test_backup_restore_fidelity.pypassed 37 tests andtests/test_continuous_backups.pypassed 9. In the first file, 13 rows of thecasestable are new. The test that holds them fails against a server built frome56f70205, the fix(engine): check the IndexName of a restore's index override #1225 commit that this branch started from. It fails first onabwith a GSI override.pytest --collect-only -qcollects 7301 tests intests/and 820 intests/python, with no error.9444edca4. The later commits changed only comments intable_name_gate.rs.TargetTableNamewith U+0000, an ARN among them, got HTTP 400ValidationException, and the server log had no internal error. This also ran on9444edca4.Line counts: production +61 -27, tests +88 -11.
Not in this PR, each in an open issue:
BackupArnand the shape of an index override before aTargetTableNameoutside the pattern. ExtendDB's server answers the name first.TargetTableNamethat is not a JSON string withSerializationException. ExtendDB now gives such a value the text of an absent member.TargetTableNamebefore the override values. On 3 December 2026 the targetabwithBillingModeOverrideBOGUSgot the length text, where ExtendDB answers the enum clause. With noBackupArn,abgotInvalid Backup ARN, so theBackupArncomes first, as in ExtendDB (RestoreTableFromBackup answers a missing or malformed BackupArn with other texts than DynamoDB's Invalid Backup ARN #1272 covers the text).For a
SourceTableNameof two U+1F600, DynamoDB lists the two clauses in either order, andcheck_restore_table_namelists the length clause first. ExtendDB refuses every RestoreTableToPointInTime before this check, so no answer shows it.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: n/a
Breaking changes
A RestoreTableFromBackup
TargetTableNamethat DynamoDB refuses gets DynamoDB's text, as the table in Why shows, and an absent one getsThe parameter 'TableName' is required but was not present in the request. A client that matches the old texts sees the new ones. The set of target names that ExtendDB refuses does not change.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.