Skip to content

Access control: config-driven enforcement with OIDC claims, secured permissions API #258

Closed

Description

@uniqueg

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):

  1. 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.
  2. The user ID can't be taken from OIDC tokens. flask-authz's authorization_decoder
    decodes Bearer tokens with JWT_SECRET_KEY/JWT_HASH (HS-style) and reads the
    identity claim. With RS256 tokens from an OIDC provider (claim sub) this always
    fails, so the only option left is headers (X-User), which clients can spoof
    unless a trusted proxy sets them.
  3. The permissions API is unprotected. access-control-specs.yaml declares no
    security and the controllers do no authorization checks: when access control is
    enabled, anyone, even without logging in, can POST /permissions and grant
    themselves admin.
  4. No group/role mapping from claims. Group or entitlement claims (e.g.
    eduperson_entitlement) can't be mapped to Casbin roles by config.
  5. No helpers for resource-level rules. Apps implementing ownership must work
    with the Casbin adapter and rule format directly.

How? (suggestions, open to discussion)

  1. access_control.enforce: true (default false for 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: [].
  2. Take the subject from the already validated token claims (connexion
    token_info / FOCA's validate_token result) instead of re-decoding the token:
    access_control.claim_identity (default sub). E.g., use flask-authz's
    owner_loader hook rather than its built-in Bearer decoder.
  3. 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.
  4. Secure the permissions API: require bearerAuth, and enforce it through Casbin
    itself (e.g. only the admin role may manage rules).
  5. 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.
  6. 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, admin role = everything; and a short docs example
    of the app code that grants ownership on create using the helpers.
  7. 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).

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