Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support advanced permission checks #1315

Open
TheSlimvReal opened this issue Jun 21, 2022 · 2 comments
Open

Support advanced permission checks #1315

TheSlimvReal opened this issue Jun 21, 2022 · 2 comments
Labels
Status: Complex Issue advanced, particularly challenging topic that requires extensive knowledge of the code base Type: Refactoring / Technical Enh. Technical Enhancement without changes for the user

Comments

@TheSlimvReal
Copy link
Collaborator

Currently, the permission definitions in CASL only allow to restrict access based on the active user, the requested entity and the properties of the requested entity.
This allows permissions like user X can only read female children.

A more advanced but still common use case would involve a relationship check.
E.g. user Y can only read children which currently attend school Z
This is currently not possible, because it would require for each child that it requested, to load the child school relations and than check which school the child currently attends. This mechanism is not supported by the CASL library (only works synchronous).

I currently see the following options to support the described scenario

  1. Implement Make ChildSchoolRelation part of Child entity #693 to have more information in the child object and somehow store in the org.couchdb.user object or as a database role for which schoolID's a user has access.
  2. Make rules that automatically update the permission object whenever a write on a relevant object happens. E.g. add a child to the list of children for which a user has access, once a relation with a given school has been saved
  3. Keep an in-memory storage with synchronous access of important entities in the backend and extend CASL so checks across entities synchronously
@TheSlimvReal TheSlimvReal added Type: Refactoring / Technical Enh. Technical Enhancement without changes for the user discuss labels Jun 21, 2022
@TheSlimvReal
Copy link
Collaborator Author

Point 3 would probably be the solution which would give us the most freedom how complex rule can get but I am not sure how well it scales and also the rule definitions can get increasingly complex (see the query syntax).

Point 2 has the danger that the permissions and the data might get out of sync when there are some errors which is difficult to recover from. Also the implementation effort is very high as this a completely new concept.

Point 1 is my preferred option as the restructuring comes with some other nice benefits (less indices, easy permissions on related data) but it still has limitations e.g. user X can only read notes where a child is linked for which user X has access. I am not sure though if we should support something like this. The other point is that for the above use case we would also need to update the org.couchdb.user object or the permission rule based on which schools a user is allowed to have access to. This needs to be incorporated into the UI (e.g. the school can be assigned to the user which triggers the user or the permission object to be updated - not supported yet).

@sleidig
Copy link
Member

sleidig commented Jun 23, 2022

I'll try to list out essential user stories here:

Rule to give user access to ...

  1. (1) any Note assigned to own User
  2. (2) any Child with status/location/... "A" (i.e. value of a dropdown field of Child)
  3. (3) any Child of School "A" (i.e. child-school relationship entry)
  4. (4) any Note of any accessible Child (i.e. for children accessible through any other above rule; also Observation, ASER, ...)

Looking at our abstract entity property models we roughly had

  • "standard" data properties
  • entity references
  • two-step references (e.g. child <-> school via ChildSchoolRelation)

We can maybe completely do away with the two-step refs by always embedding these (not sure, haven't carefully thought this through).
But I think we do need a way to handle permissions for direct entity refs, where the rule is not only specifying individual IDs of the related entity but instead a rule based on rules.

@sleidig sleidig moved this from Triage to Postponed / On Hold in All Tasks & Issues Sep 18, 2023
@sleidig sleidig added Status: Needs Details/Concept Status: Complex Issue advanced, particularly challenging topic that requires extensive knowledge of the code base and removed Status: High Priority labels Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Complex Issue advanced, particularly challenging topic that requires extensive knowledge of the code base Type: Refactoring / Technical Enh. Technical Enhancement without changes for the user
Projects
Status: Postponed / On Hold
Development

No branches or pull requests

2 participants