Skip to content

Resource roles should cover sub-paths #260

Closed

Description

@uniqueg

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/ABC does 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 p rules (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 (default true). 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/ABC can access /services/ABC/permissions if a p rule allows owner there, 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 matching p rule.
  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions