Skip to content

feat!: add owner-based access control - #66

Closed
uniqueg wants to merge 5 commits into
feat/foca-0.14from
feat/access-control
Closed

uniqueg wants to merge 5 commits into
feat/foca-0.14from
feat/access-control

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements the permission model of #62 with FOCA's access control (Casbin). It is stacked on #65 (FOCA 0.14.0 upgrade) and needs these FOCA PRs, planned for FOCA 0.14.0: elixir-cloud-aai/foca#308 (security.auth.userinfo_claims), elixir-cloud-aai/foca#310 (operations keep their own x-openapi-router-controller) and elixir-cloud-aai/foca#311 (security.access_control.policies).

Mostly configuration, plus minimal code for what is app-specific (who owns which service):

  • Public reads: GET on services, a service, service types and service info need no token. The security: [] overrides are in additions.openapi.yaml and merged into the GA4GH operations, so the vendored specifications are unchanged.
  • Owners: any LS Login user can register a service (POST /services) and becomes its owner (add_owner() after registration). Owners can update and delete their services.
  • Managing permissions: new endpoints GET /services/{serviceId}/permissions, PUT and DELETE /services/{serviceId}/permissions/{userId} (body {"role": "owner" | "maintainer"}) let owners grant and revoke roles by user ID (sub). Granting a role replaces the user's other role on the service.
  • Maintainers can update (PUT), but not delete a service or manage its permissions.
  • Admins: members of ECP_CLN:ADMIN (entitlement urn:geant:lifescience-ri.eu:group:elixir:ECP_CLN:ADMIN#aai.lifescience-ri.eu, mapped to role admin) can do everything, including POST /service-info (admin only) and registering services with chosen IDs (PUT of a new service). LS Login access tokens do not contain eduperson_entitlement, so it is taken from user info via userinfo_claims (cached per token for 5 minutes).
  • Policies: FOCA's reference model for resource-scoped roles (cloud_registry/access_control/model.conf); the five policy rules are set in config.yaml (security.access_control.policies) and added on startup unless stored already. The permission endpoints are routed to ga4gh.registry.permissions. Rules are stored in collection policy_rules of database serviceStore. Roles on a service are revoked when it is deleted.
  • Fixed along the way: RegisterService now distinguishes newly created services (upserted_id) from replaced ones; modified_count alone would have made a maintainer replacing a service with identical content its owner.

Verification

  • pytest: 40 passed (Python 3.12, FOCA dev with foca#308, docs: stop overriding the org contributing guide #309, feat(chart): set the number of app replicas #310 and Reject extra fields in service organizations #311 merged locally; also with the pinned mongomock==4.0.0). New tests/test_access_control.py creates the app from the real config.yaml (in-memory MongoDB, mock LS Login with RS256-signed at+jwt tokens and entitlements via user info only) and covers every permission path: public reads, 401 without token, creator becomes owner, 403 for others on PUT/DELETE/permissions, admin can do everything, service info admin only, maintainer PUT but not DELETE, granting/replacing/revoking roles, invalid role/user ID (400), unknown service (404), PUT-create admin only, roles removed with the service. Without userinfo_claims, 7 of these 11 tests fail; without the configured maintainer rule, the maintainer test fails.
  • flake8, black --check: pass. mypy cloud_registry (mypy 2.4): pass.

Not verified: a deployment (Docker/compose, Helm) and real LS Login tokens against a running instance; #62 asks for a test deployment. CI does not run yet: the workflow only runs for PRs to dev, and foca>=0.14.0 is not on PyPI yet. Retarget this PR to dev after #65 is merged.

Open questions

  1. Admin entitlement: only the LS Login form of ECP_CLN:ADMIN is mapped. Admins' user info also lists urn:geant:elixir-europe.org:group:elixir:ECP_CLN:ADMIN#perun.elixir-czech.cz; add it to group_mapping if needed.
  2. Existing services have no owner, so only admins can modify them (cleanup in Populate the Cloud Registry: owners register their own deployments, admins remove placeholder entries generic-issues#29). Admins can assign owners via the new permissions endpoints.
  3. Not done, deliberately: exposing owners in GET responses (would publish user IDs; owners and admins can list them via /permissions), and preventing owners from removing the last owner (admins can still fix that).

🤖 Generated with Claude Code

Summary by Sourcery

Implement owner-based access control for registry services with administrator support and permission-management APIs.

New Features:

  • Add owner-based access control for services, including owner and maintainer roles, administrator privileges, and public read access.
  • Add endpoints for owners and administrators to list, grant, replace, and revoke service permissions.
  • Use LS Login entitlement claims to identify administrators and allow administrators to manage service metadata and create services with chosen identifiers.

Bug Fixes:

  • Ensure ownership is assigned only when a service is newly created, not when an existing service is replaced.
  • Remove all service permissions when the associated service is deleted.

Enhancements:

  • Configure Casbin-based, resource-scoped authorization policies and persist service roles in the registry database.

Documentation:

  • Document the access-control model, roles, and permission-management API in the README.

Tests:

  • Add comprehensive access-control coverage for authentication, public reads, ownership, role management, administrator privileges, validation, and permission cleanup.

Alex Kanitz and others added 2 commits October 19, 2026 22:02
Use FOCA's access control (Casbin) to implement the agreed permission
model:

- Anyone can read services, service types and service info: the read
  operations of the GA4GH specifications are made public via additions
  merged into them, so the vendored specifications stay unchanged.
- Any LS Login user can register a service (POST) and becomes its
  owner. Owners can update and delete their services and grant other
  users the roles owner or maintainer (update only) via new endpoints
  /services/{serviceId}/permissions[/{userId}].
- Members of ECP_CLN:ADMIN are admins and can do everything, including
  setting the service info and registering services with chosen
  identifiers (PUT of a new service). LS Login provides entitlements
  via user info only, so they are added to the token claims via FOCA's
  security.auth.userinfo_claims.

Policies use FOCA's reference model for resource-scoped roles and are
added on startup; roles on services are revoked when they are deleted.

BREAKING CHANGE: non-admins can no longer modify or delete services
they do not own or maintain, set the service info, or register
services via PUT. Existing services have no owner (see #63).

Closes #62

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 19, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces FOCA/Casbin-backed owner-based access control for registry services, with public reads, authenticated ownership and maintenance workflows, admin entitlement support, permission-management endpoints, lifecycle cleanup, OpenAPI/README documentation, and end-to-end mocked identity tests.

Sequence diagram for service registration and ownership assignment

sequenceDiagram
    actor User
    participant API as Registry API
    participant RegisterService
    participant Policy as FOCA/Casbin
    participant Rules as policy_rules

    User->>API: POST /services
    API->>Policy: Enforce POST /services
    Policy->>Rules: Evaluate authenticated user policy
    Rules-->>Policy: Allow
    API->>RegisterService: register_metadata()
    RegisterService-->>API: service id
    API->>Policy: add_owner(serviceId)
    Policy->>Rules: Store owner role for service resource
    Rules-->>Policy: Owner stored
    API-->>User: Service id
Loading

Sequence diagram for role management on a service

sequenceDiagram
    actor Owner
    participant API as Registry API
    participant Policy as FOCA/Casbin
    participant Rules as policy_rules

    Owner->>API: PUT /services/{serviceId}/permissions/{userId}
    API->>Policy: Enforce permission-management policy
    Policy->>Rules: Check owner role or admin role
    Rules-->>Policy: Allow
    API->>Policy: add_resource_role(userId, role, service)
    Policy->>Rules: Replace other service role
    Rules-->>Policy: Role stored
    API-->>Owner: Permission
Loading

Flow diagram for service access-control roles

flowchart LR
    User[Authenticated user] -->|POST /services| Owner[Owner]
    Owner -->|PUT| Service[Service]
    Owner -->|DELETE| Service
    Owner -->|GET PUT DELETE| Permissions[Service permissions]
    Maintainer[Maintainer] -->|PUT| Service
    Admin[Admin entitlement] -->|All operations| Service
    Admin -->|POST /service-info| ServiceInfo[Service info]
    Public[Anyone] -->|GET| Service
    Public -->|GET| ServiceInfo
Loading

File-Level Changes

Change Details Files
Configures FOCA/Casbin access control with resource-scoped owner and maintainer roles plus global admin access.
  • Adds the resource-role model and startup policy registration.
  • Loads entitlement claims from LS Login user info and maps the configured admin group.
  • Defines public read access and authenticated write policies, including admin-only service-info updates and ID-selected service creation.
cloud_registry/access_control/model.conf
cloud_registry/config.yaml
cloud_registry/app.py
Adds service permission management and ownership lifecycle handling.
  • Adds permission list, grant/replace, and revoke controllers with validation and service existence checks.
  • Assigns the registering user as owner and removes all roles when a service is deleted.
  • Ensures only newly created PUT services receive ownership, avoiding ownership changes on replacements.
cloud_registry/ga4gh/registry/permissions.py
cloud_registry/ga4gh/registry/server.py
cloud_registry/ga4gh/registry/service.py
Documents and exposes the access-control API contract.
  • Marks read operations as unauthenticated in the OpenAPI additions.
  • Documents permission endpoints, role schemas, parameters, and response/error behavior.
  • Adds README guidance for owner, maintainer, and admin capabilities.
cloud_registry/api/additions.openapi.yaml
README.md
Adds comprehensive access-control verification and updates existing service-handler tests.
  • Covers public reads, authentication failures, ownership, role replacement/revocation, maintainer restrictions, admin privileges, invalid inputs, service recreation, and entitlement lookup via mocked LS Login.
  • Updates unit tests to verify ownership assignment and cleanup hooks.
tests/test_access_control.py
tests/ga4gh/registry/test_server.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Use FOCA options proposed for 0.14.0: policy rules are set via
security.access_control.policies instead of being added in code on
startup (elixir-cloud-aai/foca#311), and the permission endpoints are
routed to their own controller module via x-openapi-router-controller
instead of being re-exported from the server module
(elixir-cloud-aai/foca#310).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
uniqueg and others added 2 commits October 20, 2026 00:18
Connexion logs the status code with %d, which fails for the string
"201" and makes the access control test fail under pytest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With FOCA 0.14, configured policies are managed on startup and cannot
be changed via the permissions API.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
uniqueg added a commit that referenced this pull request Oct 20, 2026
- Public reads; writes need roles on a service (owner, maintainer) or
  the admin role, via FOCA's access control (Casbin)
- Owners manage roles: GET/PUT/DELETE /services/{id}/permissions
- GET /me: the current user's ID, admin flag and roles
- Display names from LS Login user info, scoped per service
- Removing or demoting the last owner returns 409
- Startup fails without an admin group mapping, unless
  custom.access_control.require_admin is false; Helm render fails too
- Audience verification on by default; Docker Compose uses a
  development overlay (config.dev.yaml)
- Registration and role changes roll back on failures

Replaces #66 (commits re-applied, author preserved, signed).

Closes #62

BREAKING CHANGE: writes need roles. Only owners (and maintainers, for
updates) can change a service; only admins can set the service info
or create services with chosen IDs. Existing services have no owner,
so only admins can change them.

BREAKING CHANGE: deployments must set security.auth.audience and map
an admin group to admin in security.access_control.group_mapping, or
set custom.access_control.require_admin: false. Otherwise the app
refuses to start, and the Helm chart fails to render without the
mapping.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg

uniqueg commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Superseded by #106, which re-applies these commits on top of dev (author preserved, signed commits, as required by the branch rules) and adds the follow-up work decided on 2026-10-20. Thanks!

@uniqueg uniqueg closed this Oct 20, 2026
@uniqueg
uniqueg deleted the feat/access-control branch November 9, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant