Skip to content

feat!: move role endpoints under users - #337

Merged
uniqueg merged 6 commits into
devfrom
feat/336-role-endpoints-under-users
Nov 3, 2026
Merged

uniqueg merged 6 commits into
devfrom
feat/336-role-endpoints-under-users

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Closes #336

Summary

User roles move to FOCA's layout (as in trs-filer), without an alias:

Operation Path
Roles of users (PUT, DELETE) /services/{serviceId}/permissions/users/{userId} (before: /services/{serviceId}/permissions/{userId})
Roles of groups (PUT, DELETE) /services/{serviceId}/permissions/groups/{group} (unchanged)
List (GET) /services/{serviceId}/permissions (unchanged)
  • The old paths return 404. A user called groups, or whose identifier starts with groups/, now works like any other, and can accept invitations. Identifiers with slashes work as before.
  • The groups collision goes: _first_segment(), _check_user_id(), check_namespaces() and the startup refusal of issuer namespaces starting with groups/.
  • owners-change-permissions moves to .../permissions/users/* and no longer covers groups. owners-change-group-permissions keeps its path and is the only rule for groups.
  • warn_owner_rules() warns of rules that cover both (e.g., the rule of 1.0.0rc1 kept in an overlay). The invitation warning checks the new paths, so it also fires for overlays still on .../permissions/:user.
  • EXAMPLE_USERS stays: the invitation warning needs identifiers with slashes, e.g., for a rule covering users of one issuer only. It wasn't there only for the collision.
  • Docs: access-control.md, api.md, configuration.md, upgrading.md, the chart's upgrade notes. reference.md is generated from the docstrings. Chart values and templates don't contain these paths.

The matching client change is cloud-registry-ui#190, which ships with this.

Upgrade from stored data

tests/test_upgrade_rc1.py starts this version on tests/data/store_1.0.0rc1.json, which is what the tag v1.0.0rc1 wrote to a MongoDB 7.0 (only the hash of the invitation token is replaced). It runs on mongomock and on MongoDB 7.0 in CI, and shows:

  • FOCA's generations replace the stored configured rule .../permissions/* on startup. It doesn't linger: with owners-change-group-permissions: null, owners get 403 on the roles of groups.
  • Stored roles are unchanged, document by document, and keep working for users and groups, including a group as only owner and a user with slashes.
  • An open invitation stored by 1.0.0rc1 can be accepted, and its role managed on the new path.
  • Rules stored via FOCA's permissions API do stay. The upgrade guide tells admins to remove those on former paths.

By hand, once: the app of v1.0.0rc1 wrote to a real MongoDB 7.0, mongodump kept its data and indexes, and the same tests ran on a mongorestore of it: 9 passed. Scripts: cr-336-upgrade/ in the project's work folder (test_capture_336.py, test_zz_e2e_336.py).

Verification

Local, on the code at 5e2e467, before review fixes that only touched docs, test tidying and one docstring:

  • pre-commit run --all-files: all hooks passed, also on the final code. So did the gitleaks-all manual hook, before the last docs-only commit.
  • mkdocs build --strict: passed, also on the final docs.
  • Unit tests with coverage (mongomock, Helm available): 1951 passed, 11 skipped, 1 failed, 100% coverage. The failure, test_release_after_expiry, isn't related: it got a 401 under heavy local load while two full runs were going, as its monkeypatch.undo() also removes the mocked identity provider. It passed 3 of 3 runs alone, and passed in the MongoDB run.
  • Full suite on MongoDB 7.0: 1963 passed.
  • After the review fixes: tests/test_upgrade_rc1.py, tests/test_issuers.py, and the docs and chart README tests passed locally. The full suite is left to CI below.

TDD: the tests moved first and failed (62 failed in the three main test files), then the code followed.

CI on 43be7b7: all checks passed (CI passed, Test on mongomock and MongoDB 7.0, Lint, Docs, Chart, Smoke test, Scan image, CodeQL, codecov patch and project).

Release notes (for "Breaking changes")

  • API: the roles of users move from /services/{serviceId}/permissions/{userId} to /services/{serviceId}/permissions/users/{userId}, without an alias, so clients must move. The policy rule owners-change-permissions moves to .../permissions/users/* and no longer covers the roles of groups: overlays that redefine it or give policies as a list must update it. Upgrade with the app scaled to 0 replicas, as pods of 1.0.0rc1 would grant roles to a user users/<id> on the new paths. Stored roles need no migration (feat!: move role endpoints under users #336, feat!: move role endpoints under users #337)

Declined review findings

  • Tests of mixed-version pods and of going back (adversarial, low): they would need the code of 1.0.0rc1 in the test suite. A reviewer checked these claims against an extract of the tag instead.
  • A test that a second start replaces rules seen by a running app (adversarial, low): that's FOCA's behaviour, not this app's.
  • Renaming test_rule_stored_via_permissions_api_stays, which inserts the rule directly (adversarial, low): the stored shape is the API's, and the docstring now says so.
  • Importing the private _create_app from tests.test_access_control (quality, low): the tests' existing convention.
  • Documenting groups/... as an exception to the 404 of former paths (Sourcery, medium): these were group paths in 1.0.0rc1 too, as it refused such user identifiers, so they aren't former paths of users.

The second adversarial round found three docs problems, all fixed in the last commit. That commit had no third round, as reviews stop at two.

Open questions

None.

🤖 Generated with Claude Code

https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG

uniqueg and others added 5 commits November 3, 2026 07:17
User roles move from /services/{serviceId}/permissions/{userId} to
/services/{serviceId}/permissions/users/{userId}, as in FOCA and
trs-filer; groups stay at /permissions/groups/{group}. The old paths are
not found, without an alias. User identifiers may contain slashes, so
the two layouts collided, and the app had to refuse users and issuer
namespaces called `groups`; these checks go.

The rule owners-change-permissions moves to .../permissions/users/* and
no longer covers groups, so owners-change-group-permissions is the only
rule for them. warn_owner_rules() now warns of rules that cover both,
such as the rule of 1.0.0rc1 kept in an overlay, and checks the new
paths for its invitation warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Start the app on what 1.0.0rc1 stored in MongoDB 7.0, captured from that
tag: stored roles of users and groups keep working on the new paths, the
stored rule of .../permissions/* is replaced on startup and grants
nothing, an open invitation can be accepted, and rules stored via FOCA's
permissions API stay, as the upgrade guide says.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Update the access control, API and configuration docs, and add what
deployers and API clients must change to the upgrade guide and to the
upgrade notes of the chart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Pods of 1.0.0rc1 take the new paths for the old ones, and grant roles to
a user `users/<id>` instead of `<id>`, so upgrades should scale the app
to 0 replicas; the upgrade guide now says so, and how to find such
roles. Also remove the claim that users called `groups` can't accept
invitations, and tidy the upgrade tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
1.0.0rc1 can't start until the index of expired invitations is dropped,
so going back needs that first. Check the owners before revoking stray
roles, as the last owner can't be revoked, and name the path on each
version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
@uniqueg uniqueg added this to the v1.0.0-rc2 milestone Nov 3, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This breaking change separates user-role mutations from group-role mutations by moving them to /permissions/users/{userId} without an alias, removes the former groups path collision constraints, updates policy matching and migration guidance, and verifies compatibility with RC1-stored roles and invitations.

Sequence diagram for moving a user role mutation

sequenceDiagram
    actor Client
    participant API
    participant Permissions
    participant Store
    Client->>API: PUT /services/{serviceId}/permissions/users/{userId}
    API->>Permissions: putServicePermission(serviceId, userId)
    Permissions->>Store: put_role(serviceId, userId, user, role)
    Store-->>Permissions: Role stored
    Permissions-->>Client: User identifier and role
Loading

Sequence diagram for RC1 upgrade rollout

sequenceDiagram
    actor Admin
    participant App as NewApp
    participant MongoDB
    participant Client
    Admin->>NewApp: Start with RC1 stored data
    NewApp->>MongoDB: Replace configured policy rules
    NewApp->>MongoDB: Read stored roles and invitations
    MongoDB-->>NewApp: Existing roles and open invitations
    Client->>NewApp: PUT /permissions/users/{userId}
    NewApp->>MongoDB: put_role(serviceId, userId, user, role)
    MongoDB-->>NewApp: Role stored unchanged
    NewApp-->>Client: Success
Loading

Flow diagram for permission policy separation

flowchart TD
    Request[Role mutation request]
    UserPath{Path uses /permissions/users/*?}
    GroupPath{Path uses /permissions/groups/*?}
    UserRule[owners-change-permissions]
    GroupRule[owners-change-group-permissions]
    Warning[warn_owner_rules warns about overlapping rules]
    Request --> UserPath
    UserPath -->|yes| UserRule
    UserPath -->|no| GroupPath
    GroupPath -->|yes| GroupRule
    GroupPath -->|no| Warning
Loading

File-Level Changes

Change Details Files
Move user-role mutation endpoints into an explicit users route and remove collision-specific identifier restrictions.
  • Update OpenAPI routes, handlers, docstrings, and client-facing references to /permissions/users/{userId}.
  • Remove _first_segment, namespace startup validation, and the special rejection of users named or prefixed groups.
  • Preserve group-role routing under /permissions/groups/{group} and allow slash-containing user identifiers under the new route.
cloud_registry/api/additions.openapi.yaml
cloud_registry/app.py
cloud_registry/ga4gh/registry/permissions.py
cloud_registry/ga4gh/registry/invitations.py
cloud_registry/config.yaml
Align authorization policy generation and startup warnings with the separated user and group endpoint layouts.
  • Change owners-change-permissions to cover only /permissions/users/*; retain the group rule as the sole group mutation rule.
  • Warn about legacy broad rules that still cover both user and group roles, and check invitation access against the new user paths.
  • Document required overlay and stored-policy updates for the breaking route and policy changes.
cloud_registry/config.yaml
cloud_registry/ga4gh/registry/permissions.py
docs/access-control.md
docs/configuration.md
docs/upgrading.md
deployment/README.md
Add comprehensive regression and upgrade coverage for endpoint routing, identifier handling, authorization, invitations, and persisted data.
  • Update existing endpoint and policy tests to use the new user route and validate old paths return 404.
  • Test users and issuer namespaces beginning with groups or users, including slash-containing identifiers and invitation acceptance.
  • Add an RC1 captured-store upgrade suite verifying configured-rule replacement, unchanged roles, invitation compatibility, policy API behavior, and mixed user/group authorization.
tests/data/store_1.0.0rc1.json
tests/test_access_control.py
tests/test_conflicts.py
tests/test_invitations.py
tests/test_issuers.py
tests/test_rename.py
tests/test_service_limits.py
tests/test_service_types.py
tests/test_upgrade_rc1.py
tests/test_verification.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

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (32dca62) to head (43be7b7).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #337   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         2418      2406   -12     
=========================================
- Hits          2418      2406   -12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 3, 2026 07:15

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="docs/upgrading.md" line_range="16-17" />
<code_context>
+
+- **API:** `PUT` and `DELETE /services/<id>/permissions/<user-id>` move to
+  `/services/<id>/permissions/users/<user-id>`. There is no alias: the former
+  paths are not found (`404 Not Found`), so move API clients in the same
+  upgrade, also [cloud-registry-ui](https://github.com/elixir-cloud-aai/cloud-registry-ui).
+  The only exception are identifiers that start with `users/` (e.g., of an
+  issuer with such a namespace): their former path is the new path of the user
</code_context>
<issue_to_address>
**Some former paths still reach groups**

When a request to a former user-role path has a user identifier starting with `groups/` and the caller is authorized to manage the matching group, a stale client using an identifier beginning with `groups/` reaches the existing group-permission route, not a missing route; an authorized request can therefore change that group’s role instead of returning `404`. Deployers may assume stale requests are harmlessly rejected.

Document that `groups/` paths are still routed to group permissions and can succeed for authorized callers, and call out this exception in the upgrade guidance.
</issue_to_address>

### Comment 2
<location path="tests/test_issuers.py" line_range="172" />
<code_context>
+    response = client.put(url, json={"role": "maintainer"}, headers=owner)
+    assert response.status_code == 200, response.get_json()
+    assert response.get_json() == {"user_id": user, "role": "maintainer"}
+    assert client.delete(url, headers=owner).status_code == 200


</code_context>
<issue_to_address>
**Namespaced role deletion can be a no-op**

When the issuer namespace is one of `groups`, `groups/a`, `groups\\a` or `users`, `test_namespaces_named_like_paths` only checks that DELETE returns 200 at line 172, so a handler that leaves the granted role in place passes. The test never checks the permissions after deletion.

After DELETE, assert that the namespaced user's role is absent from the service's permissions.
</issue_to_address>

Linked issues

#336 feat!: move role endpoints under users · 8 of 8 met

# Requirement Status Notes
1 Move user-role PUT and DELETE paths under /permissions/users/{userId}, keep group paths unchanged, and provide no alias for the old user paths. ✅ Met OpenAPI, controller comments, tests, and API docs use the new paths; tests check that old paths return 404.
2 Allow users called groups or starting with groups/, including users with slashes, and remove the collision and namespace-refusal checks. ✅ Met The collision checks and startup refusal are removed; tests cover these user identifiers, slash-containing identifiers, and issuer namespaces.
3 Move owners-change-permissions to .../permissions/users/*; leave owners-change-group-permissions as the rule for groups. ✅ Met The base config separates the paths, and tests cover the resulting access and warning behavior.
4 Update warn_owner_rules() and invitation-rule checks for the new paths, while retaining examples needed to detect rules covering namespaced users. ✅ Met The warning logic checks the new user paths and tests include broad, legacy, and issuer-specific rules.
5 Update invitation behavior and documentation for the new user-role paths. ✅ Met Invitation docstrings and policy checks use the new path; tests cover accepting invitations for users previously blocked by the collision.
6 Keep previously stored roles working without migration. ✅ Met Upgrade tests start on captured 1.0.0rc1 data and verify stored user and group roles remain listed and effective.
7 Update the OpenAPI descriptions and the access-control, API, and upgrade documentation, including breaking-change guidance for clients and deployers. ✅ Met The diff updates the OpenAPI descriptions and named docs; the PR description also includes release notes under “Breaking changes.”
8 Tests and strict documentation build pass. ✅ Met The PR reports passing tests and mkdocs build --strict; the remaining reported test failure was isolated and passed in the MongoDB run.

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and during a mixed-version rollout, an old pod can interpret the new /permissions/users/<id> path as a request to change the role of user users/<id>, leaving a persistent role grant to the wrong principal. Reverting the code does not undo such grants; they need to be audited and revoked.

Blocking findings: docs/upgrading.md:17, tests/test_issuers.py:172


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread docs/upgrading.md Resolved
Comment thread tests/test_issuers.py Resolved
@uniqueg
uniqueg merged commit 19a6c82 into dev Nov 3, 2026
44 checks passed
@uniqueg
uniqueg deleted the feat/336-role-endpoints-under-users branch November 3, 2026 07:51
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.

feat!: move role endpoints under users

1 participant