Repository navigation
feat(access-control): add GET /me with app hook - #687
Conversation
Clients need to know who the caller is and what they may do. With me_enabled, FOCA serves the subject, client, groups and admin status of callers with a valid token, plus fields from an app's function (me_hook). Off by default, so apps with their own endpoint are unaffected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
From review: helpers for paths in hooks stay with the app's APIs, rules of the app aren't checked against the endpoint, hooks are checked also without the endpoint, routes it shadows are logged, and callers without an identity aren't told that being an admin is available. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Without access control, me_hook and me_path have no effect, so they are refused like me_enabled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis PR adds an opt-in, authenticated Sequence diagram for the authenticated GET /me requestsequenceDiagram
actor Caller
participant FOCA as FOCA /me endpoint
participant Hook as Application me_hook
participant Access as Access-control helpers
Caller->>FOCA: GET me_path with token
FOCA->>Access: get_current_subject()
FOCA->>Access: get_current_client()
FOCA->>Access: get_current_groups()
FOCA->>Access: is_admin()
FOCA->>Access: get_available_opt_in_roles()
opt me_hook configured
FOCA->>Hook: me_hook()
Hook-->>FOCA: Application fields
end
FOCA-->>Caller: subject, client, groups, admin, admin_available, hook fields
Flow diagram for optional GET /me registrationflowchart TD
Config["me_enabled configured"] --> Enabled{me_enabled?}
Enabled -- No --> Skip["Do not register endpoint"]
Enabled -- Yes --> Base{"API has base path /?"}
Base -- Yes --> Error["Raise configuration error"]
Base -- No --> Conflict{"me_path conflicts with route?"}
Conflict -- Yes --> Error2["Raise route conflict error"]
Conflict -- No --> Hook{"me_hook configured?"}
Hook -- Yes --> Import["import_me_hook()"]
Hook -- No --> Register["Register GET me_path with OpenAPI spec"]
Import --> Register
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 #687 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 61 62 +1
Lines 8071 8130 +59
=========================================
+ Hits 8071 8130 +59
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ 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="foca/security/access_control/register_access_control.py" line_range="193" />
<code_context>
app=cnx_app, access_control_config=access_control_config
)
_check_routes_enforced(cnx_app.app)
+ cnx_app = register_me_endpoint(
+ app=cnx_app, access_control_config=access_control_config
+ )
</code_context>
<issue_to_address>
**Failed startup leaves partial registration**
When `me_enabled` is set and the configured path conflicts with a route, or an API has the root base path, and the caller retries using the same Connexion app after the registration error, a route conflict or root-base-path check in `register_me_endpoint()` raises only after `register_access_control()` has registered the Mongo collection and permission API; retrying registration on the same Connexion app encounters leftover routes and configuration instead of starting cleanly.
Validate the `/me` configuration and route constraints before registering the permission API or mutating database configuration, or roll back those registrations if `/me` registration fails.
</issue_to_address>
### Comment 2
<location path="foca/security/access_control/register_access_control.py" line_range="705" />
<code_context>
+ Raises:
+ ValueError: It is the path of a route of the app.
+ """
+ if any(rule.rule == path for rule in app.url_map.iter_rules()):
+ raise ValueError(
+ f"'security.access_control.me_path' is taken by another route: '{path}'"
</code_context>
<issue_to_address>
**POST routes block caller endpoint**
When an application already has a POST-only route at the configured `me_path`, the method-blind path check raises `ValueError` before checking whether the existing route handles `GET`, so a valid `GET /me` cannot coexist with an unrelated `POST` route at the configured path.
Reject exact-path routes only when their methods conflict with GET (including Flask's automatic HEAD/OPTIONS behavior).
</issue_to_address>Linked issues
#610 feat(access-control): add GET /me with app hook · 3 of 4 met · 1 to check by hand
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Provide an optional GET /me returning caller information and app hook fields. | ✅ Met | The endpoint is opt-in and returns subject, groups, admin status, and hook fields; it also reports client and admin_available. |
| 2 | Test anonymous, user, admin, service client, and hook-fields cases. | ✅ Met | The added tests cover each listed case. |
| 3 | Achieve 100% coverage. | 👀 Check by hand (runtime) | Confirm that the reported test run reaches 100% coverage; the diff alone does not establish executed coverage. |
| 4 | Document the endpoint on the access-control page, including how cloud-registry's response maps to it. | ✅ Met | The access-control documentation describes the endpoint and includes the cloud-registry-to-FOCA field mapping. |
Sourcery assessment
Needs a human reviewer. 2 findings to address first, and any caller with a valid token can reach this endpoint without access-control policies, and its response reveals caller identity, group claims, and admin status derived by FOCA. Reverting stops future responses, but information already disclosed cannot be taken back.
Blocking findings: foca/security/access_control/register_access_control.py:193, foca/security/access_control/register_access_control.py:705
Summary
Closes #610.
With
security.access_control.me_enabled, FOCA servesGET /me(path:me_path) for any caller with a valid token. It returnssubject,client,groups,adminandadmin_available, in the snake_case of the permissions API.me_hooknames a function adding fields of the app, which can't replace these. Off by default, so apps with their own endpoint aren't affected.Decisions, as the issue leaves them open:
401, as in cloud-registry._register_api): the helpers for paths stay with the app's API in hooks, and the app's rules aren't checked against it, as policies aren't enforced on it./, as Connexion names blueprints after base paths: apps with an API at/get a clear error, and declare the endpoint in that API instead.Docs:
docs/access-control.md(The current caller, with how cloud-registry's response maps to it),docs/configuration/access-control.md,docs/reference.md.How it was verified
{base_path}/*.Declined review findings
admin_availablecounts only the opt-in roleadmin, not opt-in roles that rules link to it: same as cloud-registry; documented.me_pathtakes over the redirect of a route with a trailing slash (/api/{id}/): that route still works at its own path.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Provide an opt-in current-caller endpoint that gives clients consistent identity and access-control information while supporting application-specific fields.
New Features:
GET /meendpoint reporting the caller’s identity, groups, client, and admin status.Enhancements:
Documentation:
Tests: