Repository navigation
Description
Why?
FOCA's Casbin-based access control (security.access_control) cannot currently be
used without writing glue code, and enabling it as-is opens a privilege escalation
hole. Concrete use case: elixir-cloud-aai/cloud-registry#62 (anyone can read; any
logged-in user can register a service and becomes its owner; owners can grant other
users "owner" or "maintainer" (PUT but not DELETE) on their resource; an admin group
from an OIDC entitlement claim can do everything).
Enforcement, identity and the permissions API should work through config alone.
Resource ownership (who becomes owner of what, and when) depends on each app's
domain and stays app code, but FOCA should provide small helpers so that this code
stays short and consistent across apps.
Findings (checked against 0.12.1, 0.13.0 and dev):
- Enforcement is opt-in per controller. Policies are only enforced on functions
decorated with@check_permissions; there is no config option to enforce them on an
app's API operations. - The user ID can't be taken from OIDC tokens. flask-authz's
authorization_decoder
decodes Bearer tokens withJWT_SECRET_KEY/JWT_HASH(HS-style) and reads the
identityclaim. With RS256 tokens from an OIDC provider (claimsub) this always
fails, so the only option left is headers (X-User), which clients can spoof
unless a trusted proxy sets them. - The permissions API is unprotected.
access-control-specs.yamldeclares no
securityand the controllers do no authorization checks: when access control is
enabled, anyone, even without logging in, canPOST /permissionsand grant
themselves admin. - No group/role mapping from claims. Group or entitlement claims (e.g.
eduperson_entitlement) can't be mapped to Casbin roles by config. - No helpers for resource-level rules. Apps implementing ownership must work
with the Casbin adapter and rule format directly.
How? (suggestions, open to discussion)
access_control.enforce: true(defaultfalsefor backwards compatibility): wrap
every operation of the app's specs with the enforcer, with a per-operation opt-out
(e.g.x-foca-access-control: false) or automatic skip for operations with
security: [].- Take the subject from the already validated token claims (connexion
token_info/ FOCA'svalidate_tokenresult) instead of re-decoding the token:
access_control.claim_identity(defaultsub). E.g., use flask-authz's
owner_loaderhook rather than its built-in Bearer decoder. access_control.claim_groups(e.g.eduperson_entitlement) plus optional
group_mapping(claim value -> Casbin role, e.g."<entitlement>": admin); add
these as implicit subjects during enforcement, so no rules are needed per user.- Secure the permissions API: require
bearerAuth, and enforce it through Casbin
itself (e.g. only theadminrole may manage rules). - Small public helpers for app code, e.g. in
foca.security.access_control:get_current_subject()/get_current_groups()(from the validated claims);add_resource_role(subject, role, resource),
remove_resource_role(subject, role, resource),
list_resource_roles(resource),remove_resource(resource);- roughly what an app needs to grant ownership on create, offer owner-managed
access through its own endpoints, and clean up on delete. Ownership logic itself
stays in the app.
- A reference model (e.g.
resource_role_model.conf) supporting resource-scoped
roles: public reads, any authenticated user may create,owner= full access,
maintainer= read + update,adminrole = everything; and a short docs example
of the app code that grants ownership on create using the helpers. - Docs and tests for all of the above, including a regression test that an
unauthenticated or non-admin user can't modify permissions.
Acceptance criteria
- With only a model file and config, an app enforces policies on its operations
using OIDC (RS256) token claims for identity and group-to-role mapping. - The permissions API rejects unauthenticated and unauthorized requests.
- Resource-scoped role rules can be managed through documented public helpers.
- Defaults don't change behaviour for existing apps (apart from securing the
permissions API, which is a fix).
Out of scope
- Generic resource-ownership logic (deciding owners on create, owner-managed access
endpoints, cleanup on delete): app-specific, done in each app with the helpers above.
Part of the ELIXIR Compute Platform WP4 sprint (M4.1).
Drafted with AI assistance (Claude Code).
Activity
feat: namespace access control subjects and check helper models
docs: document subject namespaces, identity claim and helper ptype
fix: silence mypy error on PyJWT decode options
test: replace pkg_resources with importlib.resources
test: cover remaining access control branches