Repository navigation
Description
Why?
Resource-scoped roles (introduced in #259 for #258) only cover the exact path they were granted on. The reference model (resource_role_model.conf) checks g2(r.sub, p.sub, r.obj), and Casbin compares the stored resource path with the request path for equality. So owning /services/ABC does not give access to /services/ABC/permissions.
The owner-managed access endpoint from the use case in #258 (elixir-cloud-aai/cloud-registry#62) is exactly such a sub-path. The current workaround is to opt that endpoint out of enforcement (x-foca-access-control: false) and check ownership in app code via list_resource_roles(). That works, but moves authorization back into app code, which #258 set out to avoid.
How? (suggestion)
- Register a Casbin domain matching function for resource-scoped role definitions (role definitions with three fields, e.g.
g2 = _, _, _), so that a role granted on a resource path also applies to its sub-paths: the request path equals the stored path, or starts with the stored path followed by/. Matching is on path segment boundaries, so/services/ABCdoes not cover/services/ABCD. Trailing slashes in stored paths are ignored. - Sub-path matching only makes a role apply below the resource. What a role may do there is still decided by
prules (e.g.p, owner, /services/:id/permissions, (GET)|(PUT)), so maintainers etc. get no extra access unless rules say so. - Config option to opt out, e.g.
access_control.resource_roles_cover_subpaths(defaulttrue). Resource-scoped roles have not been released yet (merged after v0.13.0), so the default does not change behaviour for released versions. - Update the reference model comments and docs with a sub-path example.
Acceptance criteria
- An owner of
/services/ABCcan access/services/ABC/permissionsif aprule allowsownerthere, without opting the endpoint out of enforcement. - No access to sibling resources sharing a prefix (
/services/ABCD), to other resources' sub-paths, or to sub-paths without a matchingprule. - Sub-path matching can be disabled by config, restoring exact matching.
- Docs and tests updated.
Out of scope
- Wildcards or patterns in stored resource paths.
Drafted with AI assistance (Claude Code).
Activity