Covey
11/11/2024, 11:17 AMdefinition page_user_management {
relation organization: organization:*
permission can_view = organization->is_admin
}
definition organization {
relation admin: user
relation supplier: user
relation buyer: user
relation teacher: user
relation student: user
relation parent_organization: organization
permission is_admin = admin + parent_organization->is_admin
permission is_supplier = supplier + parent_organization->is_supplier
permission is_buyer = buyer + parent_organization->is_buyer
permission is_teacher = teacher + parent_organization->is_teacher
permission is_student = student + parent_organization->is_student
}
What is the convention for "making page_user_management
public? I guess I would need to create a relation like this:
page_user_management:[some-id] organization organization:*
But what should [some-id]
be?vroldanbet
11/11/2024, 11:45 AMrelation organization: organization:*
Assuming page_user_management
was a resource you'd do something like
definition page_user_management {
relation organization: organization
relation public: user
permission can_view = organization->is_admin + public
}
but the fact you ask about what the ID of page_user_management
would be makes me think it's not defined in your app as a resourcevroldanbet
11/11/2024, 11:46 AMvroldanbet
11/11/2024, 11:47 AMCovey
11/11/2024, 12:22 PMRole
. For example: organization:my-org admin user:user-1
We also want to model "page permissions" using SpiceDB. The example in my previous message is for a User Management page. For testing purposes, I want all users who have the admin
role in any organization to have the can_view
permission on the UserManagement page.
Previously, I made a POC where I modeled pages like this:
definition page {
relation viewer: role
relation excluded_viewer: user
permission can_view = viewer->member - excluded_viewer
}
However, from my conversations with members of the authzed team, I understood (perhaps incorrectly) that this approach is recommended only for "dynamic pages" or when users can create/delete pages themselves. We have a static set of pages, each with its own set of permissions.
Did this make things clearer? Please let me know if you want me to elaborate further - I'd be happy to!
Thanks for helping out! I'm really enjoying the learning experience here - it's just a little bit difficult to figure out "the right way" to do things sometimes. 😊vroldanbet
11/11/2024, 3:24 PMcheck organization:my-org manages_roles user:the_acting_user
when the user management page controller is invoked.vroldanbet
11/11/2024, 3:25 PMdefinition organization {
relation admin: user
relation supplier: user
relation buyer: user
relation teacher: user
relation student: user
relation parent_organization: organization
permission is_admin = admin + parent_organization->is_admin
permission is_supplier = supplier + parent_organization->is_supplier
permission is_buyer = buyer + parent_organization->is_buyer
permission is_teacher = teacher + parent_organization->is_teacher
permission is_student = student + parent_organization->is_student
permission manages_roles = is_admin
}
vroldanbet
11/11/2024, 3:27 PMCovey
11/11/2024, 8:43 PMzed permission lookup-resources page can_view user:user-1
(This is the query from the old POC). This returns a list of all pages the users are allowed to access and is used to populate the menu on the frontend.
2. Whenever a user tries to access a given page using the URL, we check permissions for that page explicitly.
In the future, we will add more permissions to each page, and these permissions will differ from each other, hence the schema rewrite now.Covey
11/12/2024, 7:46 AMvroldanbet
11/12/2024, 10:12 AMlookup-resources
to return the tabs to present as allowed to the user, though, but I suspect such a model can have challenges to evolve down the line. It's also not the same as you presented earlier, where the page_user_management
was modeled in the schema: having a page
is indeed "dynamic pages" as pointed by fellow Authzedders, since now the page becomes a resource on its own with its own id.
The mental model we tend to use when doing SpiceDB schemas is to capture your business logic, defining the main concepts in it, and how they relate to each other (e.g. the GitHub model - organizations have repositories, repositories have issues, users are members of organizations, teams belong to organizations...). The presentation of it (the pages) is a different projection. It's similar to object orientation patterns in away.
At the end of the day, whatever works for you is fine. I'm not sure there is anything specific about your application that would benefit from this design, as far as I can tell
If I were to design your schema, I'd do a few things:
- move away from permissions as roles. describe permissions in terms of the action performed in the application, not on the role the user has. That decouples the privilege grant, from the actual permission the user has.
- definitions in your schema are resources of your application. The permissions are "verbs", or actions a subject can perform over a resource
- having permission to see a page of an organization should be a permission in the organization if only 1 such page exists (role admin page).
- if there are nested resources to the organization (e.g. /org/<org_id>/nested_resource/<resource_id>
)) then that becomes a definition on its ownvroldanbet
11/12/2024, 10:13 AMlookup-resources
on page load to determine "which tabs to render as enabled / not-greyed out", you can use BulkCheck
API to check all the permissions you want to render in the UI. (i.e. check user:covey manage_roles, purchase, supply, teach organization:my-org
)Covey
11/12/2024, 1:03 PMvroldanbet
11/12/2024, 1:22 PM