Repository navigation
Closed
Labels
priority: mediumMedium prioritytype: featureNew feature or requestworkload: daysLikely takes days to resolve
Milestone
Description
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 /medon'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.mdand an entry indocs/migration-0.18.md - Rule-based ownership unchanged
Metadata
Metadata
Assignees
Labels
priority: mediumMedium prioritytype: featureNew feature or requestworkload: daysLikely takes days to resolve
Activity
fix(access-control): reject _id, NUL owner fields