Skip to content

fix(access-control): replace roles atomically #398

Closed

Description

@uniqueg

Problem

grant_role() (foca/security/access_control/ownership.py) replaces a subject's resource roles in two steps: it revokes the subject's other roles of access_control.resource_roles on the resource, then adds the new role. Revoking first is deliberate (a failure leaves fewer rights, not more), but it isn't atomic:

  • Between the two steps, the subject has no role on the resource, so its concurrent requests can get 403 (e.g., a maintainer promoted to owner).
  • Two concurrent grants for the same subject and resource (e.g., owner and maintainer) can both revoke and then both add, leaving the subject with two roles, which grant_role() is meant to prevent.

Found in the FOCA 0.16.0 pre-release review (low).

Expected

  • Replacing a role is effectively atomic for the affected subject and resource: no window without a role in the normal path, and at most one role of resource_roles afterwards, also under concurrent grants (e.g., add the new rule first and remove the others with one filtered delete, or a single document update / transaction-free compare-and-set on the policy collection, then reload; keep "fail with fewer rights" for errors).
  • Concurrency tests (as for the last-owner checks) for promote/demote and for two concurrent grants.
  • Docs of grant_role() updated; release notes entry.

For FOCA 0.17.0.

Activity

  1. added
    priority: medium
    status: triage
    type: bug
    workload: hours
    on Oct 22, 2026
  2. added a commit that references this issue on Oct 22, 2026
  3. uniqueg commented on Oct 22, 2026

    @uniqueg
    MemberAuthor

    Done in #413.

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

    priority: mediumstatus: triagetype: bugworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions