Skip to content

Cassandra and MongoDB: a create whose clear and undo both fail keeps a deleted principal's rows #962

Open

Description

@hitesh96db

Problem

On Cassandra and MongoDB, creating a user, group or role is two steps: insert the principal's row, then delete the rows that a delete by a release before #923 left under its name (clear_new_principal). The two steps are not atomic, and one path leaves the principal with the old rows and no way left to remove them.

clear_new_principal, at 4895dc8:

  • Cassandra: crates/storage-cassandra/src/management_store/dependents.rs:271
  • MongoDB: crates/storage-mongodb/src/management_store.rs:227

When the clear fails, it deletes the new principal row so that a retry of the create runs the clear again. When that delete also fails, the second error is only logged, and the create returns the first error. The principal row then stays with the old rows under it.

A retry of the create answers AlreadyExists (HTTP 409) before it reaches the clear, so the retry never removes the rows. Only a delete of that principal, or of its account, removes them (delete_principal_dependents and delete_account_iam); nothing else does.

A process that stops between the insert and the end of the clear leaves the same state, without either step failing.

The old rows are the deleted principal's inline policies, permissions boundary, access keys, group memberships, tags and failed logins (principal_dependents in the MongoDB store lists them). Left under the new principal, a policy or boundary grants it the old permissions, an old access key signs in as it, and a membership puts it in the old groups. This is the name-reuse inheritance #923 fixes.

The state needs rows that a release before #923 left behind, plus either a double failure or a stop at that point. SQLite and PostgreSQL insert the principal and delete the old rows in one transaction (delete_principal_attachments in each create_user), so they are not affected.

This comes from reading the code; the failure was not injected.

Expected

  • A create that returns an error leaves no principal row, or leaves one that the next create, delete or a background pass clears before the principal can sign in or be authorized.
  • A retry of the create after either failure removes the old rows.
  • Tests: on Cassandra and MongoDB, a create whose clear fails and whose undo fails, then a retry, leaves no old policy, key, membership, boundary or tag under the name. The same for a create stopped between the insert and the clear.

One way: mark the principal row as not yet cleared when it is inserted, and drop the mark only after the clear succeeds. A create that finds a marked row runs the clear again instead of answering 409, and authorization treats a marked principal as having no attachments.

Activity

  1. added
    bug
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions