Repository navigation
feat: add admin mode - #263
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]>
Reviewer's GuideAdds FOCA-backed, request-level admin mode: admins must opt in with Sequence diagram for request-level admin modesequenceDiagram
actor Admin
participant API
participant FOCA
Admin->>API: Request with Authorization
API->>FOCA: Evaluate request roles
alt X-Request-Roles: admin
FOCA-->>API: Admin permissions
API-->>Admin: Admin operation succeeds
else Header omitted
FOCA-->>API: Regular-user permissions
API-->>Admin: Admin operation denied or hidden
end
Sequence diagram for GET /me admin statussequenceDiagram
actor Client
participant API
participant FOCA
Client->>API: GET /me
API->>FOCA: is_admin()
API->>FOCA: get_available_opt_in_roles()
FOCA-->>API: Request admin status and availability
API-->>Client: admin and admin_available
Sequence diagram for duplicate service visibility in admin modesequenceDiagram
participant API
participant Permissions
participant FOCA
API->>Permissions: may_read_service(serviceId)
Permissions->>Permissions: Create synthetic GET request
Permissions->>FOCA: Evaluate with X-Request-Roles
alt Admin mode header present
FOCA-->>Permissions: Service is readable
Permissions-->>API: Registered duplicate visible
else Header omitted
FOCA-->>Permissions: Service is not readable
Permissions-->>API: Hidden duplicate conflict
end
File-Level Changes
Assessment against linked issues
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 #263 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 19 19
Lines 1862 1866 +4
=========================================
+ Hits 1862 1866 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
# 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
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cloud_registry/config.yaml" line_range="112-113" />
<code_context>
+ # groups can then be admins: configured rules granting `admin` are
+ # refused on startup. `[]` lets admins act as admins on every
+ # request; see "Admin mode" in `docs/access-control.md`
+ opt_in_roles:
+ - admin
# Managed on startup (removed rules are deleted); cannot be changed
# via the permissions API. Named, so that overlays can change, add or
</code_context>
<issue_to_address>
**Legacy grants bypass admin mode**
When old and new replicas overlap during a rolling upgrade and an administrator grants `admin` through the old permissions API, the old permissions API stores an `admin` grant while old and new replicas share the database; new replicas then load that rule, which still grants admin rights without the opt-in header, so the user retains ambient admin access after the rollout.
Drain old replicas before the final audit and revocation of stored admin grants, or otherwise prevent legacy replicas from writing admin grants during the upgrade.
</issue_to_address>
### Comment 2
<location path="cloud_registry/config.yaml" line_range="113" />
<code_context>
required:
- user_id
- admin
+ - admin_available
- may_add_service_types
</code_context>
<issue_to_address>
**Old replicas bypass admin mode**
When an upgrade rolls out new replicas while old replicas still serve requests, requests routed to old replicas are authorized under the previous always-admin behavior, while new replicas require the opt-in header. Admin operations without the header therefore succeed or fail depending on which replica handles them, so the new mode is not consistently enforced during a rolling upgrade.
Document or enforce a rollout that stops old replicas serving traffic before relying on admin mode being enforced.
</issue_to_address>
### Comment 3
<location path="cloud_registry/config.yaml" line_range="112-113" />
<code_context>
+ # groups can then be admins: configured rules granting `admin` are
+ # refused on startup. `[]` lets admins act as admins on every
+ # request; see "Admin mode" in `docs/access-control.md`
+ opt_in_roles:
+ - admin
# Managed on startup (removed rules are deleted); cannot be changed
# via the permissions API. Named, so that overlays can change, add or
</code_context>
<issue_to_address>
**Chart accepts rejected admin policies**
When a deployment sets `require_admin: false` and grants `admin` in `security.access_control.policies`, the Helm chart still documents that `require_admin: false` allows policies to grant `admin`, and its validation does not reject that configuration. FOCA now refuses configured policies granting `admin`, so deployments following the chart guidance render successfully but fail at app startup.
Update the chart documentation and validation so configurations with configured `admin` policies are rejected or replaced with group mappings before deployment.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 3 findings to address first, and the default now grants admin permissions only on requests carrying X-Request-Roles: admin, changing the authorization boundary for every deployment using the default config. If that policy is wrong, admin actions such as changing permissions or deleting services can still succeed when opted in, and those effects are not undone by reverting the change.
Blocking findings: cloud_registry/config.yaml:113, cloud_registry/config.yaml:113, cloud_registry/config.yaml:113
Refs #240 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Admin mode: admins act as admins only in requests that ask for it in the header
X-Request-Roles: admin(FOCA's opt-in roles, elixir-cloud-aai/foca#502). Without the header, admins have the permissions of other users.GET /metells clients whether the user may switch to admin mode (admin_available).Builds on #261 (#226, FOCA 0.18), now merged; dev is merged in, so the diff shows only this PR. The merge conditions hold:
scripts/check_release_pins.pypasses).Closes #240
What changes
security.access_control.opt_in_roles: [admin]in the base config.config.dev.yaml), which maps no admin group, setsopt_in_roles: [].opt_in_roles: [].GET /me:adminis true on requests in admin mode.admin_availableis true for members of admin groups, and wheneveradminis true (e.g., without the opt-in, or with stored admin rules).may_read_service()passes the opt-in header on to its synthetic request context. Admins in admin mode learn the registered service in a409; admins without the header get the hidden409, like other users.Vary, CORS), indocs/access-control.md#admin-mode.docs/operations.md: the permissions API refuses rules that grantadmin.docs/upgrading.md(From 0.5.0, item 4: the header, theGET /mesemantics, configured rules refused, stored rules still applying with a warning) and in the chart README.Verification
scripts/check_release_pins.pypasses.ruff,mypy,mkdocs build --strictandpre-commit run --all-filesare clean.test_admin_modecovers admin operations, parametrized: an admin without the header gets the same status as a user without roles; with the header, the request succeeds.test_admin_mode_vary,test_admin_mode_permissions_apiandtest_admin_mode_off(opt-out).test_mecoversadmin_available.test_admin_via_permissions_api: grantingadminvia the permissions API is refused.409for admins without the header./mecould reportadmin: truewithadmin_available: false(opt-out, stored rules). It is fixed.Declined review findings
rolesinmake_headers()stays admin mode: the test helpers ask for admin mode by default. Most existing tests are about admin rights as such, and the no-header paths have their own tests (see above). The default is documented in the helper's summary.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Introduce opt-in admin mode so administrators must explicitly request elevated permissions while preserving configurable support for always-active admin access.
New Features:
admin_availablethroughGET /meso clients can determine whether an administrator can switch to admin mode.Bug Fixes:
Enhancements:
adminrole while admin mode is enabled.Deployment:
Documentation:
Tests:
/mefields, opt-out behavior, permissions API restrictions, and duplicate conflict visibility.