Skip to content

fix(authz): check a point-in-time restore's target before its source - #827

Merged
LeeroyHannigan merged 4 commits into
mainfrom
fix/446-pitr-authz-order
Nov 9, 2026
Merged

LeeroyHannigan merged 4 commits into
mainfrom
fix/446-pitr-authz-order

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

What

RestoreTableToPointInTime now authorizes the item actions on the target table before dynamodb:RestoreTableToPointInTime on the source table. For a caller with no policy, the denial now names dynamodb:Scan on the target table, as on Amazon DynamoDB. On main, it names the restore action on the source table.

authz_targets in crates/server/src/authz_resource.rs returns the target's item actions first and the source's restore action last. authorize_request checks the pairs in that order, and the first denied pair is the one the denial names. The set of required actions and resources does not change, so a request that a policy allows on main is still allowed.

The admin guide's resource table and its restore note, and the v0.1.15 upgrade note, describe the new order.

This pull request does not implement point-in-time restore, which stays unsupported as on main since #335. An authorized restore still answers PointInTimeRecoveryUnavailableException, and an index SourceTableArn still answers ValidationException: Invalid Request: Table ARN is invalid. A new test pins that second answer.

Why

#446 measured both answers on the service on 22 October, for a caller with no policy and for an admin, with an index SourceTableArn. The denial on main named a different action and resource. A policy written against the service's denial therefore sees a different action and resource on ExtendDB.

Part of #446

Testing done

  • restore_order_tests.rs in crates/server/src/authz_resource/ checks the order of the authorization targets and the denial for a caller with no policy. other_arn_fields_keep_the_supplied_spelling now reads the source from the last target. With main's order, all three tests fail.
  • Two tests in tests/test_authz_resource_arn.py send a RestoreTableToPointInTime request with an index SourceTableArn. The first expects the denial for a caller with no policy to name dynamodb:Scan on the target. The second expects Invalid Request: Table ARN is invalid. for a caller allowed dynamodb:*. I ran the four restore tests of the file against a SQLite server built from this branch: 4 passed. With main's order restored in authz_targets, the dynamodb:Scan test fails and the other three pass. The Table ARN is invalid answer is already on main, so that test passes there too.
  • cargo +1.97.0 fmt --all -- --check: clean.
  • cargo +1.97.0 clippy --locked -p extenddb-server --all-targets -- -D warnings: clean.
  • cargo +1.88.0 test --locked -p extenddb-server: 295 passed.

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


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.

…446)

RestoreTableToPointInTime now authorizes the item actions on the target
table before dynamodb:RestoreTableToPointInTime on the source table. The
service checks them in that order: a caller with no policy is denied on
dynamodb:Scan on the target table (measured 2026-10-22 with an index
SourceTableArn). ExtendDB denied the same caller on the restore action on
the source table.

The set of required actions and resources is unchanged; only the order,
and so the action and resource a denial names, changes.
The admin guide's resource table and restore compatibility note, and the
v0.1.15 point-in-time recovery upgrade note, state that the target's item
actions are checked before the restore action, so a caller with no policy
is denied naming dynamodb:Scan on the target table.
…e answer (#446)

A caller with no policy and an index SourceTableArn is denied naming
dynamodb:Scan on the target table, and a caller allowed dynamodb:* gets
ValidationException "Invalid Request: Table ARN is invalid." for the same
request. Both answers are the service's, measured on 2026-10-22.

@eliseong eliseong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

RestoreTableToPointInTime now authorizes the target table's item actions before the restore action on the source. I measured the live service and ran a local instance from this branch.

  • On the live service, a restore request denies on an item action on the target table, not on the restore action on the source. The denial names the target table as the resource.
  • On an instance built from this branch: a caller with no policy is denied on dynamodb:Scan on the target; a caller allowed dynamodb:* with an index SourceTableArn gets Invalid Request: Table ARN is invalid.; and a well-formed authorized restore answers PointInTimeRecoveryUnavailableException, since the feature stays unimplemented.
  • A caller allowed only the restore action, and not the item actions, is now denied on the target. A caller allowed the item actions but not the restore action is denied on the restore action on the source. Item-action grants scoped to a different table name do not satisfy the check.
  • A target ARN that names another account or region, or that carries an index suffix, resolves to the caller's own account and region on the base table, so it does not change which resource is checked.
  • Restoring the source-first order fails the two order tests.

This is a partial fix for its issue, which stays open for the restore implementation.

@eliseong
eliseong added this pull request to the merge queue Nov 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 9, 2026
@eliseong
eliseong added this pull request to the merge queue Nov 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 9, 2026
@LeeroyHannigan
LeeroyHannigan added this pull request to the merge queue Nov 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 9, 2026
@eliseong
eliseong added this pull request to the merge queue Nov 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 9, 2026
@LeeroyHannigan
LeeroyHannigan added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit e24ff1a Nov 9, 2026
39 checks passed
@LeeroyHannigan
LeeroyHannigan deleted the fix/446-pitr-authz-order branch November 9, 2026 20:29
hitesh96db pushed a commit that referenced this pull request Nov 11, 2026
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.
parsnips pushed a commit to parsnips/extenddb that referenced this pull request Nov 13, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants