Skip to content

feat(access-control): add field-based ownership #455

Closed

Description

@uniqueg

Problem

FOCA's resource ownership stores one g2 rule per owner per resource (e.g., g2, user:alice, owner, /tasks/1). That enables sharing (roles for users, groups and clients), FOCA's role endpoints and GET /me, but every rule takes memory in every app instance (about 55 MB per 100,000 rules, cf. #450), and listings filter by the identifiers of all resources of the caller.

Apps whose resources only ever belong to their creator (no sharing) don't need any of that: the owner can simply be stored in the resource document itself.

Proposal

An opt-in alternative, "ownership by document field", next to the existing rule-based ownership, which stays the default and unchanged:

  • The owner is stored in a field of the resource document (default owner) as {iss, sub}: the issuer and identity claim of the token of the creating request (or the user a service client is allowed to act for, cf. get_on_behalf_of_user()), written atomically with the document, as part of the same insert.
  • Helpers in foca.security.access_control.ownership:
    • one to set the owner field on a document to be created;
    • one to build a MongoDB filter for "owned by the caller", with the same admin bypass as is_admin() / resource_filter() (admins get an empty filter; for service clients acting for users, the client's own admin status applies).
  • Docs: when to choose field-based over rule-based ownership (no sharing, many resources per user, memory), how to enforce it (policies allow the operation, the controller filters by owner, e.g., 404 for others' resources), an index recommendation, and what is not covered (no sharing unless the app adds it; FOCA's role endpoints and GET /me don't cover such resources).

No app changes are planned (proTES keeps rule-based ownership).

Acceptance criteria

  • Helpers with tests (users, service clients, clients acting for users, admins, missing identity) at 100% coverage
  • Docs section in docs/access-control.md and an entry in docs/migration-0.18.md
  • Rule-based ownership unchanged

Activity

  1. added this to the v0.18.0 milestone on Oct 24, 2026
  2. added
    priority: medium
    status: in progress
    type: feature
    workload: days
    on Oct 24, 2026
  3. removed
    status: in progress
    on Oct 24, 2026
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

    priority: mediumtype: featureworkload: days

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions