Repository navigation
Closed
Labels
priority: mediumMedium prioritytype: authRelated to authorization or authenticationtype: featureNew feature or requestworkload: hoursLikely takes hours to resolve
Description
Why?
Part 1 of #341 (refs #341; a follow-up adds the controllers and closes it): the Python helpers that give FOCA apps resource ownership, extracted from cloud-registry's cloud_registry/ga4gh/registry/permissions.py. Depends on #340 for attributing resources that service clients create on a user's behalf to that user.
How?
New module foca.security.access_control.ownership, exported from foca.security.access_control, on top of the resource role helpers (add_resource_role() and friends):
is_admin(): whether the current subject has the roleadmin(viagrules orgroup_mapping), i.e., may see and do everything.add_owner(resource, subject=None, subject_type="user"): the creating user becomes owner. By default, the user the request is attributed to: the user an allow-listed service client acts for (feat(auth): support service tokens and roles #340), otherwise the token subject.list_roles(resource, role=None): roles granted on a resource, users first, then groups.grant_role(resource, subject, role, subject_type="user"): grants a role, replacing the subject's other roles on the resource. Roles must be in the new optionsecurity.access_control.resource_roles(default[owner, maintainer], must containowner). Downgrading the last owner (user or group) raisesLastOwner(409); if concurrent requests removed the other owners meanwhile, the owner is restored.revoke_roles(resource, subject, subject_type="user"): revokes all roles of a subject, with the same last-owner rule.list_subject_roles(prefix): roles of the current subject, directly and via groups, on the resources under a path prefix (e.g., for a "me" endpoint).resource_filter(prefix, field="id"): MongoDB filter for the resources under a prefix that the current subject may see:{}for admins, the identifiers of the resources they have a role on otherwise.
Role changes are logged for auditing (who changed which role of whom on which resource). Documented in a "Resource ownership" section of the access control guide, the API reference and a migration guide for 0.16.
Acceptance criteria
- Tests cover ownership on create (also on behalf of a user), role management, the last-owner rule (also with groups and concurrent changes), owner-filtered listings and the admin override.
- Documented, with cloud-registry's behaviour as the reference.
Metadata
Metadata
Assignees
Labels
priority: mediumMedium prioritytype: authRelated to authorization or authenticationtype: featureNew feature or requestworkload: hoursLikely takes hours to resolve
Activity
test(access-control): add issuers to owner claims
fix(access-control): keep owners on failed checks
uniqueg commentedon Oct 22, 2026
Done in #378.