Skip to content

fix(server): refuse a restore's TargetTableName of another JSON type first - #1267

Open
LeeroyHannigan wants to merge 6 commits into
fix/1224-restore-target-namefrom
fix/1246-restore-target-type
Open

LeeroyHannigan wants to merge 6 commits into
fix/1224-restore-target-namefrom
fix/1246-restore-target-type

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

  • 94e2ad729d: the module doc of crates/server/src/table_name_gate.rs now gives the text of this check, as What does. It also names the members of the restore that get each form of the text. Before, it said that the text is the one the restore's other members of another JSON type get. That is not true for a BillingModeOverride or a ProvisionedThroughputOverride.
  • In What, the sentence on those two members now says "that its parse refuses", as the doc does. The list of conflicts names the PRs that conflict with the new head in that doc. Testing done gives the runs at the new head.

What

A RestoreTableFromBackup TargetTableName that is neither a JSON string nor null now gets a SerializationException, as DynamoDB answers. This answer comes before the checks of the value of BackupArn and of the overrides. Before this change, ExtendDB read such a value as an absent member. Some requests got The parameter 'TableName' is required but was not present in the request. In others an earlier check answered first: a ValidationException for an absent or malformed BackupArn or a bad override, or an AccessDeniedException for another account's backup.

The check is at the start of the RestoreTableFromBackup arm of check_table_name_chars in crates/server/src/table_name_gate.rs. That function runs first in authorize_request, ahead of the cross-account refusal and the engine. A null target still passes, so the engine answers it as an absent member, as DynamoDB does.

The text is Start of structure or map found where not expected: TargetTableName. The engine writes the same form for a GlobalSecondaryIndexOverride, LocalSecondaryIndexOverride, OnDemandThroughputOverride or SSESpecificationOverride of another JSON type. A BillingModeOverride or ProvisionedThroughputOverride of another JSON type that its parse refuses gets the same prefix with the parse's own text, for example invalid type: integer `5`, expected string or map. The parse takes a BillingModeOverride object of one key with a null value and a ProvisionedThroughputOverride list of two integers (#1106). The server crate has no helper for this text that it can call, so the gate writes it once. DynamoDB's own texts belong to #1012.

The base of this PR is #1247, which changes how the restore reads TargetTableName.

Fixes #1246

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 request names a backup that does not exist in the caller's account, unless the row says otherwise. SE is SerializationException.

TargetTableName and the other members DynamoDB ExtendDB on #1247
5, 5.5, true, false, {}, {"S": "a"}, [] or ["a"] SE The parameter 'TableName' is required but was not present in the request
5, no BackupArn SE Value null at 'backupArn'
5, BackupArn "x" SE Invalid Request: BackupArn is not valid
5, a BackupArn with U+0000 in its table name SE Invalid Backup ARN
5, the BackupArn of another account SE AccessDeniedException
5, BillingModeOverride "X" SE the enum clause at billingModeOverride
5, after a BackupArn of {} SE Value null at 'backupArn'
null The parameter 'TableName' is required but was not present in the request the same

With this change, ExtendDB gives each of these requests DynamoDB's exception type.

In one case the answer no longer follows DynamoDB. When an override of another JSON type comes before the target in the body, DynamoDB answers the override's fault. ExtendDB on #1247 answered the override's fault too, and it now answers the target's. This holds for GlobalSecondaryIndexOverride, LocalSecondaryIndexOverride, ProvisionedThroughputOverride, OnDemandThroughputOverride, BillingModeOverride and SSESpecificationOverride of 5 before a target of another JSON type. The exception type is SE on DynamoDB and on both trees. #1012 covers DynamoDB's texts, and so the member that each text names.

Testing done

94e2ad729d changes only the module doc, so no wire file ran again. At 94e2ad729d, with --locked: cargo +1.97.0 fmt --all -- --check is clean, and so are cargo +1.97.0 clippy -p extenddb-server --all-targets -- -D warnings and the same command with --features extenddb-engine/backup-test-hooks. cargo +1.97.0 test -p extenddb-server --lib gave 522 passed and 5 failed, the same 5 backup_store::tests as below.

At e4d210f6a4, 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 522 passed and 5 failed, storage 294 passed. On this host 5 backup_store::tests fail on every branch, because uid 65534 owns /local/home.
  • cargo +1.97.0 fmt --all -- --check is clean. cargo +1.97.0 clippy of the four crates with --all-targets -- -D warnings is clean, and so is the same command with --features extenddb-engine/backup-test-hooks. cargo +1.94.0 check of the four crates with --all-targets is 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.
  • The unit test a_restore_target_name_of_another_json_type_is_refused_before_the_backup_arn_value_checks sends 5, true, {} and [] with a BackupArn that the gate refuses, and a null target, which passes. It checks the text by equality. With the text naming another member, it fails.
  • Against ExtendDB on SQLite built from this head, tests/test_backup_restore_fidelity.py passed 37 tests. Its table of restore names gets the 8 measured values and the four rows with another fault. Against a server built from 9444edca4, the fix(engine): check a restore's TargetTableName with the restore's rules #1247 commit that this branch started from, each of these 12 rows gets an answer other than SerializationException. pytest --collect-only -q collects 7301 tests in tests/ and 820 in tests/python, with no error.

Line counts: production +21 -3, tests +43 -2, docs +3 -1.

This PR adds a conflict with #1127 and #1130 in one sentence of the doc of check_table_name_chars. Both PRs add an exception to "A missing, non-string or empty name passes", and so does this PR. On a rebase, keep both exceptions.

#1284 contains e4d210f6a4 and merges with this head with no conflict. #1291 and #1327 contain e4d210f6a4 too, and so do #1353, #1358, #1359, #1365, #1367 and #1373, which sit on #1327. #1291 rewrites the bullet of the module doc that 94e2ad729d changes, so each of these eight PRs conflicts with this head in that bullet. When one of them merges this head, it keeps its own bullet. Its sentence that starts "The text is the one" then takes the text of this head.

Not in this PR, each in an open issue:

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: n/a

Breaking changes

A RestoreTableFromBackup TargetTableName that is neither a JSON string nor null gets SerializationException before the checks of the value of BackupArn and of the overrides. Before this change, such a request got a ValidationException or an AccessDeniedException, as the table in Why shows. A string or null target gets the same answer as before.


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.

…first

RestoreTableFromBackup read a TargetTableName of another JSON type than
string as an absent member. With the caller's own BackupArn, the answer
was ValidationException. With an absent, malformed or another account's
BackupArn, or a bad BillingModeOverride, it was that member's error.

DynamoDB answers SerializationException for a number, a boolean, an
object or a list (measured in us-east-1 on 20 Nov 2026, each request
twice). It answers before the checks of the value of BackupArn and of
the overrides. Both treat a null as an absent member.

The server now checks the member's type at the start of
check_table_name_chars. That runs before every BackupArn check and
before the engine reads the overrides. A member of another JSON type
written before TargetTableName is answered first by the service, which
this check does not follow. The text is the one the restore's other
members of another JSON type get. The service's texts and its member
order are #1012.

Fixes #1246.
The unit test matched only the SerializationException variant, so a
change to the text passed every table_name_gate test. The test now
checks the text by equality. The text is ExtendDB's, and DynamoDB's
texts for each JSON type belong to #1012.

The test name and doc said that DynamoDB answers the target before its
BackupArn. When a BackupArn of another JSON type comes first in the
body, DynamoDB answers the BackupArn first. The name and doc now use the
words of the module doc: before the checks of the value of BackupArn.

@navareamol navareamol 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.

I think the README still describes the old server check. In README.md, the section "Checks the server makes that this build does not" says "The table names and index names checks pass a name that is empty, missing or not a string", and the TargetTableName row says "the server checks the BackupArn first". With this change the server answers a TargetTableName of 5, true, {} or [] with SerializationException before the BackupArn check. I measured it on SQLite with a BackupArn of "x", one of another account and one with U+0000 in its table name. The PR updates the same sentence in the doc of check_table_name_chars. Could you update the README sentence and that row, or add a row for the new check?

Two sentences of the description do not match what I measured. It says #1291, #1327, #1353, #1358, #1359, #1365, #1367 and #1373 conflict with this head in the unit test. #1291 and #1327 already contain 6fdc2cb and merge with this head with no conflict; the other six conflict in the new test as described. It also says the text is "the form the engine writes for the restore's other members of the wrong JSON type". On the head of #1247, a GlobalSecondaryIndexOverride or SSESpecificationOverride of 5 gets that form, while a BillingModeOverride of 5 gets "Start of structure or map found where not expected: invalid type: integer 5, expected string or map" and a ProvisionedThroughputOverride of 5 gets the same with "expected struct ProvisionedThroughput". Could you adjust those two sentences?

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. The branch holds main at 5252eda and main is 14 commits ahead. I merged main 222d80a into this head locally: no conflict, the engine (979), server (527) and core (1242, 1 ignored) lib tests pass, and tests/test_backup_restore_fidelity.py plus my probes pass on SQLite. Could you merge main through the stack so CI runs on that tree?

I will approve once the README and the two description sentences match the code and CI is green on a branch with main merged.

docs/webassembly.md said that the table names check passes a name that
is not a string, and its TargetTableName row put the BackupArn check
first. For a TargetTableName that is neither a string nor null, the
server now answers SerializationException first. That answer comes
before the BackupArn, the overrides and the accounts answer. A member
types row gives the check.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol

@navareamol

Copy link
Copy Markdown
Collaborator

One point is left on this PR at e4d210f, a comment that still says what the description no longer says. In crates/server/src/table_name_gate.rs the module doc (lines 63 and 64) reads "The text is the one the restore's other members of another JSON type get." I think that is not right for two of the six members. On the e4d210f binary, a GlobalSecondaryIndexOverride, LocalSecondaryIndexOverride, OnDemandThroughputOverride or SSESpecificationOverride of 5 gets "Start of structure or map found where not expected: ". A BillingModeOverride of 5 gets "...: invalid type: integer 5, expected string or map", and a ProvisionedThroughputOverride of 5 gets "...: invalid type: integer 5, expected struct ProvisionedThroughput". The description now says this, so could the doc comment say the same?

The rest of my earlier points are resolved. The README text now lives in docs/webassembly.md, and the new member types row matches the code: the server refuses a TargetTableName that is neither a string nor null before the BackupArn, the overrides and the accounts answer. The row for a string TargetTableName that says the server checks the BackupArn first is still right. The conflict list now matches git merge-tree on the current heads: #1291 and #1327 contain this head, and #1353, #1358, #1359, #1365, #1367 and #1373 conflict in the unit test of table_name_gate.rs. CI is green on this head, 66 of 66 checks including wasm, and main as it is now merges into it with no conflict.

I ran the head on SQLite. A target of 5, 5.5, true, false, {} or [] answers SerializationException before a BackupArn of "x", one of another account and one with U+0000, and before a BackupArn of {}. A null or absent target still gets the required member text. The new unit test fails when the check is removed, when it runs after the BackupArn check, when it refuses null, and when the text names another member. The new wire rows fail on the previous head of #1247.

I will approve once the doc comment matches the description.

… type

The module doc of table_name_gate.rs said that a TargetTableName of
another JSON type gets the text that the other members of the restore
get. That is wrong for two of them. A BillingModeOverride or
ProvisionedThroughputOverride of another JSON type gets the same prefix
with the text of the parse error. The doc now gives the text of the gate
and says which members get each form, as the description does.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol 94e2ad7 changes the module doc of crates/server/src/table_name_gate.rs (now lines 63 to 69). It now gives the text, Start of structure or map found where not expected: TargetTableName, and says that the engine writes the same form for a GlobalSecondaryIndexOverride, LocalSecondaryIndexOverride, OnDemandThroughputOverride or SSESpecificationOverride of another JSON type. A BillingModeOverride or ProvisionedThroughputOverride of another JSON type that its parse refuses gets the same prefix with the parse error's text.

The doc and the description both say "that its parse refuses", because the parse takes some of these values. On SQLite at this branch's code, a BillingModeOverride of {"PAY_PER_REQUEST": null} and a ProvisionedThroughputOverride of [5, 5] get past it to BackupNotFoundException, where 5 gets the texts you quoted. #1106 tracks those shapes.

@navareamol navareamol 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.

The module doc in crates/server/src/table_name_gate.rs (lines 63 to 69) now matches the code. I built 94e2ad7 on SQLite and sent RestoreTableFromBackup with a string TargetTableName and a missing BackupArn, once for each of the six override members and each of these values: 5, 5.5, true, false, "x", {}, [], [5, 5], {"PAY_PER_REQUEST": null}, {"S": "a"} and ["a"].

For the target itself: 5, 5.5, true, {}, [] and {"S": "a"} all answer SerializationException "Start of structure or map found where not expected: TargetTableName", as the doc says.

For GlobalSecondaryIndexOverride and LocalSecondaryIndexOverride, every value that is not a list answers with the member's name, as the doc says. A list with a wrong element, [5, 5] or ["a"], answers with the parse text instead ("invalid type: integer 5, expected struct GsiInput"). The doc says "of another JSON type", and a list is the right type, so I do not count this as a mismatch.

For OnDemandThroughputOverride and SSESpecificationOverride, every value that is not an object answers with the member's name. An object, even {"S": "a"} or {"PAY_PER_REQUEST": null}, gets past the check to BackupNotFoundException.

For BillingModeOverride and ProvisionedThroughputOverride, a value the parse refuses answers with the same prefix and the parse's text: "invalid type: integer 5, expected string or map" for a billing mode of 5, and "invalid type: integer 5, expected struct ProvisionedThroughput" for a throughput of 5. A billing mode of {"PAY_PER_REQUEST": null} and a throughput of [5, 5] get past the parse to BackupNotFoundException, as you wrote, and #1106 covers them. A billing mode of "x" answers the ValidationException for the enum, as before.

The change since e4d210f is the 7 added and 3 removed comment lines of this doc and nothing else, so I did not rerun the earlier unit and wire results.

All 64 checks pass on 94e2ad7, so I approve.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants