Skip to content

feat(access-control): add resource ownership helpers #354

Closed

Description

@uniqueg

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 role admin (via g rules or group_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 option security.access_control.resource_roles (default [owner, maintainer], must contain owner). Downgrading the last owner (user or group) raises LastOwner (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.

Activity

  1. added
    priority: medium
    status: blocked
    type: auth
    type: feature
    workload: hours
    on Oct 21, 2026
  2. added
    status: in progress
    and removed
    status: blocked
    on Oct 22, 2026
  3. uniqueg commented on Oct 22, 2026

    @uniqueg
    MemberAuthor

    Done in #378.

  4. removed
    status: in progress
    on Oct 22, 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

    priority: mediumtype: authtype: featureworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions