Repository navigation
feat!: move role endpoints under users - #337
Conversation
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
Reviewer's GuideThis breaking change separates user-role mutations from group-role mutations by moving them to Sequence diagram for moving a user role mutationsequenceDiagram
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
Sequence diagram for RC1 upgrade rolloutsequenceDiagram
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
Flow diagram for permission policy separationflowchart 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
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Closes #336
Summary
User roles move to FOCA's layout (as in trs-filer), without an alias:
PUT,DELETE)/services/{serviceId}/permissions/users/{userId}(before:/services/{serviceId}/permissions/{userId})PUT,DELETE)/services/{serviceId}/permissions/groups/{group}(unchanged)GET)/services/{serviceId}/permissions(unchanged)404. A user calledgroups, or whose identifier starts withgroups/, now works like any other, and can accept invitations. Identifiers with slashes work as before.groupscollision goes:_first_segment(),_check_user_id(),check_namespaces()and the startup refusal of issuer namespaces starting withgroups/.owners-change-permissionsmoves to.../permissions/users/*and no longer covers groups.owners-change-group-permissionskeeps 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_USERSstays: 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.access-control.md,api.md,configuration.md,upgrading.md, the chart's upgrade notes.reference.mdis 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.pystarts this version ontests/data/store_1.0.0rc1.json, which is what the tagv1.0.0rc1wrote 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:.../permissions/*on startup. It doesn't linger: withowners-change-group-permissions: null, owners get403on the roles of groups.By hand, once: the app of
v1.0.0rc1wrote to a real MongoDB 7.0,mongodumpkept its data and indexes, and the same tests ran on amongorestoreof 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 thegitleaks-allmanual hook, before the last docs-only commit.mkdocs build --strict: passed, also on the final docs.test_release_after_expiry, isn't related: it got a401under heavy local load while two full runs were going, as itsmonkeypatch.undo()also removes the mocked identity provider. It passed 3 of 3 runs alone, and passed in the MongoDB run.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")
/services/{serviceId}/permissions/{userId}to/services/{serviceId}/permissions/users/{userId}, without an alias, so clients must move. The policy ruleowners-change-permissionsmoves to.../permissions/users/*and no longer covers the roles of groups: overlays that redefine it or givepoliciesas a list must update it. Upgrade with the app scaled to 0 replicas, as pods of 1.0.0rc1 would grant roles to a userusers/<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
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._create_appfromtests.test_access_control(quality, low): the tests' existing convention.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