Repository navigation
feat: support several token issuers - #264
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Validation details come from FOCA (exceptions.validation_details), and problem() builds on FOCA's problem_response(), adding only the codes of conflicts. Tests use locked_enforcer() instead of the removed get_enforcer(). Refs #226 Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA checks the group settings, requires admins (security.access_control.require_admin, moved from custom.access_control.require_admin), warns of placeholders in the service info and refuses service clients (require_no_service_clients()); the app's own copies are removed. The chart reads require_admin from its new place and rejects the old key. Refs #226 Co-Authored-By: Claude Opus 5.5 <[email protected]>
server.public_url replaces custom.endpoints.service; the app refuses to start without it, and FOCA's get_public_url() builds the Location header. The chart sets it from hostName or the new value publicUrl and rejects the old key. FOCA's get_custom_config() replaces the app's. Refs #226 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The image loads foca.gunicorn_config (same settings); cloud_registry.gunicorn_config is removed. Tests keep the checks of the image command and its health check port. Refs #226 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #226 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Chart docs name the required image version, tests render publicUrl, docstrings and the dev overlay are clearer. Refs #226 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #226 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #226 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # cloud_registry/app.py
# Conflicts: # cloud_registry/app.py
Admins act as admins only in requests that ask for the role in the header X-Request-Roles (FOCA opt-in roles, opt_in_roles: [admin] in the base config). GET /me reports whether the user may switch to admin mode (admin_available). The duplicate check passes the header on to the read check, so admins in admin mode learn the registered service. Document the header for clients and scripts, and the upgrade (stored rules granting admin). Closes #240 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pin FOCA and its development image to 6214325, which allows opt-in roles that no group is mapped to (elixir-cloud-aai/foca#530), so that configs without an admin mapping still load with admin mode. Co-Authored-By: Claude Opus 5.5 <[email protected]>
GET /me reports admin_available whenever admin is true, e.g., without the opt-in. Test each admin operation with and without admin mode, the permissions API, Vary and the opt-out; clarify the upgrade notes (GET /me, configured admin rules), the config comment and the docs on making users admins. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Docker Compose config turns admin mode off, as it maps no admin group. Describe when admin is true without the header, and when configured rules count as admins; tidy a docstring and test constants. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Trust several token issuers: FOCA namespaces the subjects of users by issuer, so user identifiers may contain slashes. The permissions API accepts them (format: path), still routing group paths to the group routes, and the owners policy covers nested paths. Add python -m cloud_registry.namespace_subjects, which namespaces the stored subjects of an issuer (rules, service types, user names), for deployments that add an issuer without keeping its subjects bare. Refs #257 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Accept issuer maps (FOCA IssuerConfig), count their group claims for group mappings, and require a global audience only unless each issuer has one. Refs #257 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #257 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refuse to namespace bare subjects while an issuer keeps its subjects bare (they are that issuer's), and empty namespaces with a clear message; reload the rules also after partial runs; print errors to stderr. Treat backslashes as slashes after groups in user ids. Mirror FOCA's per-issuer group claims in the chart. Add tests and docs. Refs #257 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # Dockerfile # cloud_registry/config.yaml # cloud_registry/ga4gh/registry/permissions.py # config.dev.yaml # deployment/README.md # docs/upgrading.md # pyproject.toml # tests/test_image_command.py
In the chart, a null claim_groups of an issuer means the global claim, as in FOCA. Pin more test expectations and clarify the migration docs. Refs #257 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #240 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis PR adds end-to-end support for multiple token issuers by adopting FOCA's issuer-namespaced user identities, updating permission routing and Helm validation, migrating pre-existing bare subjects safely, and documenting deployment and upgrade procedures. Sequence diagram for namespaced user permissionssequenceDiagram
actor User
participant Issuer as TokenIssuer
participant Registry as CloudRegistry
participant Policy as PermissionStore
User->>Issuer: Obtain token
User->>Registry: GET /me
Registry-->>User: user_id = namespace|sub
User->>Registry: PUT /services/{id}/permissions/{userId}
Registry->>Policy: Store role for namespaced user_id
Policy-->>Registry: Role stored
Flow diagram for subject migrationflowchart TD
Start([Run namespace_subjects]) --> Validate[check_namespace]
Validate -->|valid trusted namespace| Rules[_namespace_rules]
Rules --> Types[_namespace_service_types]
Types --> Names[_namespace_user_names]
Names --> Reload[mark_changed]
Reload --> Done([Stored bare subjects namespaced])
Validate -->|invalid or bare issuer remains| Error([Fail without migration])
Start -->|--dry-run| Count[Count bare subjects only]
Count --> DoneDry([Report counts])
File-Level Changes
Assessment against 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 #264 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 19 20 +1
Lines 1866 1976 +110
==========================================
+ Hits 1866 1976 +110 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
# Conflicts: # tests/conftest.py
There was a problem hiding this comment.
Hey - I've found 6 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cloud_registry/namespace_subjects.py" line_range="151" />
<code_context>
+ and value.startswith(prefix)
+ and _is_bare(value[len(prefix) :])
+ }
+ collection.update_one({"_id": rule["_id"]}, {"$set": changed})
+ return rewritten, configured
+
</code_context>
<issue_to_address>
**Revoked roles reappear after migration**
When an owner revokes a namespaced user's role on a service while the migration has not yet rewritten that user's bare rule, `_delete_roles()` finds no role for the namespaced user and returns `404`; the migration then rewrites the still-stored bare rule to that user, leaving the role granted after the caller's revocation attempt.
Serialize migration rule rewrites with permission changes, or prevent permission mutations until the migration has completed.
</issue_to_address>
### Comment 2
<location path="cloud_registry/config.yaml" line_range="128" />
<code_context>
+ # users (namespaced by issuer, with several issuers) and groups
+ # may contain slashes; the first rule also covers the roles of
+ # groups, the second one is kept for overrides of either
+ owners-change-permissions: [p, owner, "/ga4gh/registry/v1/services/:id/permissions/*", "(PUT)|(DELETE)"]
owners-change-group-permissions: [p, owner, "/ga4gh/registry/v1/services/:id/permissions/groups/*", "(PUT)|(DELETE)"]
maintainers-update-services: [p, maintainer, "/ga4gh/registry/v1/services/:id", PUT]
</code_context>
<issue_to_address>
**Group policy overrides stop working**
When a deployment removes or narrows `owners-change-group-permissions` to restrict owner access to group permissions, the broad `owners-change-permissions` rule matches group-permission paths as well as user paths, and the model combines matching allow rules with an `some(where allow)` effect. Removing or narrowing `owners-change-group-permissions` therefore no longer prevents owners from changing group permissions, so deployments cannot use that named rule to disable or restrict group grants while retaining user grants.
Keep the user-permission rule from matching the reserved `permissions/groups/` subtree, or provide an explicit deny/override mechanism for the group-permission policy.
</issue_to_address>
### Comment 3
<location path="cloud_registry/ga4gh/registry/permissions.py" line_range="605" />
<code_context>
+ or starts with `groups/`.
"""
- if userId == "groups":
+ if userId.replace("\\", "/").split("/", 1)[0] == "groups":
raise NotFound
</code_context>
<issue_to_address>
**Namespaced users cannot change roles**
When a trusted issuer uses a valid namespace beginning with `groups/`, `_check_user_id()` rejects the resulting user IDs because their first path segment is `groups`, so the permissions API returns 404 instead of letting callers grant or revoke those users’ roles.
Distinguish group IDs from valid issuer-namespaced user IDs when checking the reserved `groups/` path.
Also at `cloud_registry/ga4gh/registry/permissions.py:606`, `cloud_registry/namespace_subjects.py:92`.
</issue_to_address>
### Comment 4
<location path="cloud_registry/namespace_subjects.py" line_range="151" />
<code_context>
+ and value.startswith(prefix)
+ and _is_bare(value[len(prefix) :])
+ }
+ collection.update_one({"_id": rule["_id"]}, {"$set": changed})
+ return rewritten, configured
+
</code_context>
<issue_to_address>
**Migration stops on duplicate rules**
When a namespaced user already has the same policy rule as the bare user being migrated, `_namespace_rules()` updates the bare rule to the namespaced subject, and MongoDB raises `DuplicateKeyError`; the migration stops with some roles still stored under the bare ID.
Handle an existing identical namespaced rule as a migration duplicate instead of allowing the update to abort.
</issue_to_address>
### Comment 5
<location path="cloud_registry/namespace_subjects.py" line_range="67" />
<code_context>
+ Returns:
+ Whether the subject is a string without the separator of namespaces.
+ """
+ return isinstance(subject, str) and NAMESPACE_SEPARATOR not in subject
+
+
</code_context>
<issue_to_address>
**Legacy subjects lose associated data**
When a legacy subject contains the namespace separator `|`, `_is_bare()` treats the subject as already namespaced, so the migration skips its policy rules, service-type ownership, and display names; the new namespaced identity no longer matches those records.
Determine whether a subject is already namespaced without treating every occurrence of `|` as proof that it is.
Also at `cloud_registry/namespace_subjects.py:135`.
</issue_to_address>
### Comment 6
<location path="cloud_registry/namespace_subjects.py" line_range="204" />
<code_context>
+ continue
+ user_id = f"{namespace}{NAMESPACE_SEPARATOR}{name['user_id']}"
+ try:
+ collection.update_one({"_id": name["_id"]}, {"$set": {"user_id": user_id}})
+ except DuplicateKeyError:
+ collection.delete_one({"_id": name["_id"]})
</code_context>
<issue_to_address>
**Display-name requests fail during migration**
When a namespaced user calls `GET /me` for a service while the migration rewrites that user's existing bare display-name row, the migration changes a bare row to the namespaced unique key while `remember_current_user()` upserts that same key; if the upsert's lookup precedes the migration update but its insert follows it, MongoDB raises `DuplicateKeyError` and the request fails.
Coordinate display-name writes with the migration or retry the upsert after a duplicate-key error.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 6 findings to address first, and issuer namespacing changes which identity matches stored owner and maintainer rules, and the migration rewrites those policy subjects and may delete duplicate display-name records. Reverting the code does not automatically restore those stored values, so a mistaken namespace or migration needs deliberate repair.
Blocking findings: cloud_registry/namespace_subjects.py:151, cloud_registry/config.yaml:128, cloud_registry/ga4gh/registry/permissions.py:605, cloud_registry/namespace_subjects.py:151, cloud_registry/namespace_subjects.py:67, and 1 more
Refuse to start if the namespace of a trusted issuer starts with groups/, as its users could not be managed via the permissions API. The migration takes only subjects that start with a configured namespace as namespaced, as subjects may contain the separator (e.g., auth0|123). Document how to run the migration and the policy rules for the roles of groups. Refs #257 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Deployments can trust several token issuers. With several, FOCA namespaces the subjects of users by issuer (
<namespace>|<sub>; by default, the namespace is the issuer), so equal subjects of different issuers are different users, also as owners and maintainers of services and as the users who added service types.Builds on #263 (#240, admin mode) and #261 (#226, FOCA 0.18), both merged; dev is merged in, so the diff shows only this PR. FOCA is pinned to the release 0.18.0 (from dev); v0.5.0 is tagged.
Closes #257
What changes
userIdhasformat: path), encoded or not. Paths of the roles of groups (.../permissions/groups/<group>) stay routed to the group routes;groups,groups/andgroups\xas user identifiers are not found (404). Dot segments are still rejected (400). The policyowners-change-permissionscovers nested paths (/permissions/*).python -m cloud_registry.namespace_subjects <namespace> [--dry-run]namespaces the stored subjects of the issuer trusted so far (rules, service types, display names), for deployments that add an issuer without keeping that issuer's subjects bare. It refuses empty or unknown namespaces, and refuses to run while a trusted issuer keeps its subjects bare (namespace: ""), as the bare subjects are then that issuer's. It reloads the rules on running instances, also after partial runs. Configured rules with bare users are counted, not changed (a warning says to namespace them in the config). It can be run again.IssuerConfig:issuer,namespace,audience,claim_groups,userinfo_claims). A global audience is required only unless each issuer has an audience of its own (requireAudience, computed). Group mappings need a group claim of at least one issuer, as in FOCA: an issuer'sclaim_groupsreplaces the global one, unless unset or null.claim_groups: ""for the others). upgrading.md "Several token issuers": recommendednamespace: ""for the issuer trusted so far, or the migration. access-control.md, the chart README and values.yaml point to it; the API reference lists the migration module.Verification
ruff check,ruff format --check,mypy cloud_registry tests scripts: clean.mkdocs build --strict: clean.pre-commit run --all-files: passed.groupsin user identifiers; the chart's per-issuer group claims (now as in FOCA); clearer errors for empty namespaces; rules reloaded after partial runs; CLI errors on stderr; tests forgroupspaths and dot segments in namespaced identifiers; docs on the migration's prerequisites.claim_groupsof an issuer means the global claim (as in FOCA); more precise test expectations; docs wording.Declined review findings
/are merged by Werkzeug's path converter and redirected (308). Namespaced identifiers start with an issuer URL or a validated namespace, and bare subjects come from identity providers, so this isn't fixed: turning offmerge_slasheswould change the routing of all paths.Notes
checkAudiencerequires a global audience. This chart works around that by computingrequireAudience(false if each issuer is a map with its own audience). A fix in foca-common may be wanted.🤖 Generated with Claude Code