Skip to content

fix(engine): check a restore's override values in DynamoDB's order - #1353

Open
LeeroyHannigan wants to merge 6 commits into
fix/1272-invalid-backup-arnfrom
fix/1271-restore-check-order
Open

LeeroyHannigan wants to merge 6 commits into
fix/1272-invalid-backup-arnfrom
fix/1271-restore-check-order

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

The branch is at 9a7483aa04. These commits sit on 75d06b0b5, the head that the review of 2 Dec 2026 read:

What

RestoreTableFromBackup now checks its members in DynamoDB's order:

  1. An override member of another JSON type, at any depth of the override, gets SerializationException. This holds for every BackupArn and every TargetTableName. A list in place of a structure is of another type, and so is an object as VectorIndexOverride. A null, a missing member and a number with a fraction are not of another type.
  2. A BackupArn of another account gets AccessDeniedException.
  3. An absent or malformed BackupArn gets Invalid Backup ARN.
  4. An absent TargetTableName, and then the length of the name.
  5. One validation message lists the constraints of the model. It names each ProvisionedThroughputOverride member below 1 (writeCapacityUnits first), then the BillingModeOverride enum, then the pattern of the name.
  6. The id and the region of the BackupArn.
  7. The parse of the overrides and the PROVISIONED rule.

Before this change, the enum check and the throughput check ran before the checks of the BackupArn and the name. A throughput member below 1 got the text of CreateTable. A member of another JSON type came first only when the server refused the name before authorization. A member of another type inside an override came after the pattern of the name and the cross-account refusal. The engine checked the members of SSESpecificationOverride after the backup read. The parse read a ProvisionedThroughputOverride list of two numbers as a throughput.

The changes:

Where the overrides' parse refuses a member of another type, the answer keeps the parse's text (#1012). Where the parse accepts the member or refuses it with another exception, the answer is Start of structure or map found where not expected: <member>. That adds one more literal of a text that crates/ already writes in 22 places at the head of #1327. The overrides' parse writes it in private functions, and no shared constant exists.

The base of this PR is #1327.

Why

These are DynamoDB's answers to 425 RestoreTableFromBackup requests, measured in us-east-1 on 21 November 2026 with signed requests. Each request went out twice and got the same answer both times. No backup exists. The rows combine four BackupArn forms (the caller's account, x, the backup id bad, another account) with three target names (valid, ab, a b) and the override faults. The column of this PR is a SQLite server built from 75d06b0b5.

Answers compared with DynamoDB's #1327 This PR
Same exception type and text 100 211
Same exception type, other text 210 205
Other exception type 115 9

No request that #1327 answers as DynamoDB does gets another answer here.

The 9 requests with another exception type:

Of the 205 requests with the same type and another text, 174 get ExtendDB's texts for a member of another JSON type (#1012). Of the others, 30 are #1348 rows and 1 is the region row of #1326.

On 3 December 2026 DynamoDB gave the answers of the new tests, each request sent twice. A KeySchema object or a Projection list inside a GSI override entry gets SerializationException before a BackupArn of x and before a TargetTableName of a b.

Refs #1271
Fixes #1278

Testing done

At 9a7483aa04, each cargo command with --locked:

  • cargo +1.97.0 test -p extenddb-core -p extenddb-engine -p extenddb-server -p extenddb-storage --lib --no-fail-fast: core 1260 passed and 1 ignored, engine 982 passed, server 523 passed, storage 294 passed. On this host 5 backup_store::tests of the server fail on every branch, main included, because another user owns /local/home.
  • cargo +1.97.0 clippy of the four crates with --all-targets -- -D warnings, the same command with --features extenddb-engine/backup-test-hooks, cargo +1.94.0 check of the four crates with --all-targets, and cargo +1.97.0 fmt --all -- --check are clean.
  • cargo +1.97.0 test -p extenddb-wasm-adapter: the 3 unit tests pass, and the parity test passes all 281 cases of the corpus. The clippy step of the WebAssembly workflow is clean.
  • Against ExtendDB on SQLite built from this head: tests/test_backup_restore_fidelity.py 37 passed and tests/test_authz_cross_account.py 19 passed. pytest --collect-only -q collects tests/ and tests/python with no error.
  • Controls on 9a7483aa04: with the kind check limited to values that are not lists or objects, a_restore_checks_its_members_in_the_services_order fails. With earlier ignored in validate_name_member_after, the new core test fails.
  • On 75d06b0b5, a control restored the kinds check of the previous revision. Then the 8 new rows of the engine table and the 8 new rows of the gate table failed, and no other row failed.
  • On 75d06b0b5, the 425 requests went twice to a SQLite server built from that commit. Each request got the same answer both times.

Line counts at 9a7483aa04, against #1327's head e3672395cb: production +217 -86, tests +319 -27, docs +2 -1. The test files, the parity corpus and the lines after #[cfg(test)] and mod tests count as tests, and .md files as docs.

git merge-tree shows no conflict with main at c8e66fb568. 106 open PRs change the files of this PR and of the PRs above it. Three of them get a new conflict from this PR:

#1110, #1114 and #1126 merge with this head without a conflict.

Not in this PR:

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

RestoreTableFromBackup answers some requests with another exception or text than before, as What and the table in Why give. An override member of another JSON type, at any depth, gets SerializationException before every other check. The restore refuses a ProvisionedThroughputOverride list of two numbers, which it read as a throughput before. A ProvisionedThroughputOverride member below 1 gets the clause of the model at provisionedThroughputOverride.writeCapacityUnits or provisionedThroughputOverride.readCapacityUnits, where it got the text of CreateTable. The restore answers a request with more than one fault in the order that What lists. A client that matches on the old answers sees the new ones. A restore with valid overrides 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.

RestoreTableFromBackup checked BillingModeOverride against its enum and
each ProvisionedThroughputOverride member against 1 before it checked
the BackupArn and the TargetTableName. A throughput member below 1 got
the text of CreateTable. When the server refused the TargetTableName
before authorization, the answer named only the constraints of the
name. In that case only, the server answered an override member of
another JSON type first. With any other name, it answered a BackupArn
of another account first, with AccessDeniedException. The server
answered a member of another JSON type inside an override only after
the pattern of the name and the cross-account refusal. It checked the
members of SSESpecificationOverride only after it read the backup. It
read a ProvisionedThroughputOverride list of two numbers as a
throughput, and it refused every VectorIndexOverride with a
ValidationException of its own.

DynamoDB answers an override member of another JSON type first, at any
depth of the override, for every BackupArn and every TargetTableName.
A list in place of a structure is of another type. An object as
VectorIndexOverride is of another type too, because the model has a
list there. A missing member and a number with a fraction are not of
another type. Then DynamoDB answers a BackupArn of another account,
then an absent or malformed BackupArn, then an absent TargetTableName,
then the length of the name. Then it lists the constraints of the model
in one message. The message names each throughput member below 1, then
the BillingModeOverride enum, then the pattern of the name. The id and
the region of the BackupArn come after that message. Measured in
us-east-1 on 21 Nov 2026.

The server now refuses an override member of another JSON type at any
depth in every restore, before the cross-account refusal. The engine
checks these kinds first, against the members that the model gives
each override. It checks the name and the override values after the
account and the shape of the BackupArn, and it lists their constraints
in one message. The throughput clause is the text of the model, with
writeCapacityUnits first. The parse of the overrides and the
PROVISIONED rule now come after the id and the region of the
BackupArn.

Fixes #1271.
Fixes #1278.
The new head of fix/1272-invalid-backup-arn holds main. On main, #1009
moved ListBackups and the point-in-time recovery requests from
backup.rs to backup_requests.rs, and backup/pitr.rs to
backup_requests/pitr.rs.

Conflicts:

- backup.rs: the use list of extenddb_core::types. This branch removed
  CreateTableInput, and main removed BackupSummary. The merge removes
  both.
- backup.rs: the body of check_restore_override_kinds.
  fix/1245-restore-name-after-account copies only the override members
  of another kind into a new map. This branch compares each member with
  RESTORE_OVERRIDE_KINDS at any depth. The merge keeps that comparison
  and copies only the members that it refuses.
- backup.rs: the doc of the restore steps, which
  fix/1136-restore-override-index-name rewrapped. The merge keeps the
  words of this branch with new line breaks.
- backup.rs: the pub use pitr lines at the end of the file, which main
  removed. The merge removes them.
- lib.rs: the pub use backup::{...} list. The merge keeps main's list
  and adds check_restore_name_and_overrides to it.
- backup_requests/pitr.rs: the doc of check_restore_table_name.
  fix/1224-restore-target-name added an Errors section, and this branch
  added the earlier clauses. The merge keeps both.
- table_name_gate.rs: the doc of the restore target test, where
  fix/1245-restore-name-after-account added 25 Nov to the dates. The
  merge keeps the words of this branch with the three dates.

This branch removed the export of check_restore_table_name, because the
server gate no longer calls it. The merge removes it from the
pub use backup_requests line of lib.rs and from backup_requests.rs too.
The doc of validate_override_shape and the comment of step 3 of the
restore named #1097 after DynamoDB's order of the PROVISIONED rule. An
issue number in a code comment goes out of date when the issue closes.
Both sentences state the order without it.
The README lists the checks that the server makes and the WebAssembly
build does not. It said that the server checks the JSON kind of each
override member of a restore only for a TargetTableName that it
refuses. That check came after the kind of the BackupArn. The server
now makes it for every restore, at any depth of the override, before
the kind of the BackupArn. The member types row now lists it with its
two texts. The TargetTableName row lists the clauses of the throughput
members below 1 and of the BillingModeOverride enum. They come before
the clauses of the name, in one message.

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

This branch is not on the current head of #1327. It sits on 8da64f4, and #1327 is now 2fda6a9, which moved backup/pitr.rs to backup_requests/pitr.rs. A merge of the two conflicts in crates/engine/src/backup.rs, crates/engine/src/backup_requests/pitr.rs, crates/engine/src/lib.rs and crates/server/src/table_name_gate.rs, and a merge with main conflicts in backup.rs and lib.rs. So the description's "git merge-tree shows no conflict with main" no longer holds, and the conflict lists for #1096, #1273, #1110, #1114 and #1126 are out of date. I resolved the conflicts by hand in a scratch tree to check the code. It builds, clippy with warnings as errors is clean, the core, engine, server and storage lib tests pass, and a 3189 request run against a SQLite server answers the same as this head. Could you rebase onto #1327 at 2fda6a9?

CI ran on 21 Nov on the old stack, before main added the wasm job and other checks. I think it needs a run on the rebased branch.

Two tests do not pin what the description says. If a list or an object of the wrong shape inside an override member is no longer compared (for example a KeySchema object or a Projection list in a GSI override), every engine and server unit test still passes. This head refuses both with SerializationException, so the code is right, but nothing fails if it changes. The same holds for validate_name_member_after ignoring earlier: all 226 core tests pass, only an engine test fails. A row for each would pin them. There is also no wire test for the new order, so no CI job runs it through the server. Could you add rows to tests/test_backup_restore_fidelity.py?

One question on numbers. A ReadCapacityUnits of 1.0, 0.0 or 1e0 with a valid target name gets "Start of structure or map found where not expected: invalid type: floating point 1.0, expected i64", and with the name a b it gets the name clause. The below one clause reads the raw number with as_i64(), so 0.0 gets no clause. The parse behaves the same on 8da64f4. Has DynamoDB been sent a whole number written with a fraction?

I will approve once the branch is rebased onto #1327 and CI is green on it, and the two unit pins and a wire row are added.

The new head of fix/1272-invalid-backup-arn holds main of 2 Dec. On
main, #1521 moved the WebAssembly section of README.md to
docs/webassembly.md.

Conflict:

- README.md: the WebAssembly section. This branch changed two rows of
  its table of the checks that the server makes and this build does
  not. The merge takes the README of fix/1272-invalid-backup-arn. It
  makes the same two changes in docs/webassembly.md: the new member
  types row for the restore overrides, and the clauses of the
  TargetTableName row.
Three checks of the restore had no test that fails when they change.

The engine table of the restore's order gets two rows: a KeySchema
object and a Projection list inside a GSI override entry. Each one gets
a SerializationException before a BackupArn of x or a TargetTableName of
"a b".

A core test of validate_name_member_after sends a BillingModeOverride
clause as earlier. The clause comes before the clause of the name, and
alone when the name passes.

The wire table of test_backup_and_table_names_are_validated gets seven
restore rows for the order. They send the two nested kinds and the shape
of the BackupArn. They send the one message of the values and the name,
and the two capacity clauses with WriteCapacityUnits first. The last two
send the backup id before the PROVISIONED rule.

DynamoDB gave these answers on 3 Dec 2026, each request sent twice.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol

  1. The branch takes fix(engine): answer a missing or malformed BackupArn as DynamoDB does #1327's new head with a merge. 31e3bd6edb merged fix(engine): answer a missing or malformed BackupArn as DynamoDB does #1327 at 2fda6a911, and 38d1f47f2d merges its pushed head e3672395cb. The only conflict was the WebAssembly section of README.md, which docs(readme): lead with a first request, move WebAssembly to its own page #1521 moved to docs/webassembly.md on main. The merge makes this PR's two row changes in docs/webassembly.md. git merge-tree of the new head 9a7483aa04 with main at c8e66fb568 shows no conflict.
  2. CI runs on this tree when the branch is pushed. Before the push, the wasm adapter tests with the parity corpus and the WebAssembly clippy step passed at 9a7483aa04, beside the lib tests, clippy and fmt. The description lists the runs.
  3. The description now gives the conflicts of 9a7483aa04 with main and with the open PRs. fix(engine): refuse ProjectionType and StreamViewType outside their sets #1110, fix(engine): refuse the TableClass and SSESpecification DynamoDB refuses #1114 and fix(engine): read SSESpecification in UpdateTable #1126 merge with it without a conflict, and each merge keeps one enum_constraint.
  4. 9a7483aa04 pins both. The engine table of the restore order gets a KeySchema object and a Projection list inside a GSI override entry. Each gets SerializationException before a BackupArn of x or a TargetTableName of a b, as DynamoDB answered on 3 Dec 2026. With the kind check limited to values that are not lists or objects, the engine test fails. A new core test, the_clauses_of_earlier_members_come_before_the_names, sends a BillingModeOverride clause as earlier. With earlier ignored, it fails.
  5. 9a7483aa04 adds seven restore rows to test_backup_and_table_names_are_validated in tests/test_backup_restore_fidelity.py. They send the two nested kinds and the shape of the BackupArn. They also send the one message of the values and the name, the two capacity clauses (writeCapacityUnits first), and the backup id before the PROVISIONED rule. DynamoDB gave each answer on 3 Dec 2026, each request sent twice.
  6. Yes, on 3 Dec 2026, each request twice, with a valid target and a backup that does not exist. 1.0 and 1e0 get BackupNotFoundException, so the service reads them as 1. 0.0 gets 1 validation error detected: Value '0' at 'provisionedThroughputOverride.readCapacityUnits' failed to satisfy constraint: Member must have value greater than or equal to 1. This PR does not change the parse, which refuses all three with SerializationException, as on 8da64f4 and on main. fix(core): truncate and clamp a capacity figure, then bound it #1167 reads a capacity figure with a fraction by truncating it, so 1.0 and 1e0 get the service's answer there. The below-1 clause of this PR reads the figure with as_i64(), which gives no value for 0.0, so 0.0 still gets no clause when both PRs are merged.

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