You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Activity
fix: address Sourcery review findings
uniqueg commentedon Oct 22, 2026
Done in #413.