You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/content/modeling/roles-and-permissions.mdx
+44-45
Original file line number
Diff line number
Diff line change
@@ -21,19 +21,19 @@ import {
21
21
22
22
<DocumentationNotice />
23
23
24
-
In this guide you will learn how to model roles and permissions model within <ProductNameformat={ProductNameFormat.ProductLink}/> using the _<ProductConceptsection="what-is-an-authorization-model"linkName="authorization model" />_ and _<ProductConceptsection="what-is-a-relationship-tuple"linkName="relationship tuple" />_.
24
+
To model roles and permissions in <ProductNameformat={ProductNameFormat.ProductLink}/> using <ProductConceptsection="what-is-an-authorization-model"linkName="authorization models" /> and <ProductConceptsection="what-is-a-relationship-tuple"linkName="relationship tuples" />. For the purpose of this guide:
25
25
26
-
-**Roles** are assigned to <ProductConceptsection="what-is-a-user"linkName="users" /> or a group of users, where any user can have more than one role (`editor`, `owner`, etc..).
27
-
-**Permissions**are what allows users to access certain <ProductConceptsection="what-is-an-object"linkName="objects" /> based on their specific roles (`device_renamer`, `channel_archiver`, etc..).
26
+
-**Roles** are assigned to <ProductConceptsection="what-is-a-user"linkName="users" /> or groups of users, where any user can have more than one role, like `editor` or `owner`.
27
+
-**Permissions**allow users to access certain <ProductConceptsection="what-is-an-object"linkName="objects" /> based on their specific roles, like `device_renamer` or `channel_archiver`.
28
28
29
-
For example, the role `viewer` of a `trip` can have **permissions to view bookings** or the role `owners`can have **permissions to add/view bookings to a trip.**
29
+
For example, the role `viewer` of a `trip` can have permissions to view bookings, while the role `owners`has permissions to add or view bookings to a trip.
30
30
31
31
<CardBoxtitle="When to use"appearance="filled">
32
32
33
-
When trying to create a role and permissions model within <ProductNameformat={ProductNameFormat.ShortForm}/>.:
33
+
When creating a role and permissions model within <ProductNameformat={ProductNameFormat.ShortForm}/>, you should:
34
34
35
-
- Create roles by creating relations that can be directly assigned to users
36
-
- Assign permissions by creating relations that users get through other relations
35
+
- Create roles by creating relations that can be directly assigned to users.
36
+
- Assign permissions by creating relations that users get through other relations.
37
37
38
38
For example:
39
39
@@ -43,20 +43,19 @@ For example:
43
43
44
44
There are advantages to implementing roles and permissions within <ProductNameformat={ProductNameFormat.ShortForm}/>, such as:
45
45
46
-
- Breaking down existing roles to have more fine grained permissions. This allows your application to check whether a _user_ has access to a certain object without having to explicitly check that specific _users_ role.
47
-
- Introduce new roles/permissions or consolidate roles without affecting your application behavior. For example: if in your app all the checks are for the fine permissions `check('bob', 'booking_adder', 'trip:Europe')` instead of `check('bob', 'owner', 'trip:Europe')`, and then you later decide `owners` can no longer add bookings to a `trip`, you can remove the relation within the `trip` type with no code changes in your application, and all the permissions will automatically honor the change.
46
+
- Breaking down existing roles to have more fine grained permission, which enables your application to check whether a user has access to a certain object without having to explicitly check that specific user's role.
47
+
- Introduce new roles/permissions or consolidate roles without affecting your application behavior. For example: if your app's checks are for the fine permissions `check('bob', 'booking_adder', 'trip:Europe')` instead of `check('bob', 'owner', 'trip:Europe')`, and you later decide `owners` can no longer add bookings to a `trip`, you can remove the relation within the `trip` type with no code changes in your application, and all the permissions will automatically honor the change.
48
48
49
49
</CardBox>
50
50
51
51
## Before you start
52
52
53
-
In order to understand this guide correctly you must be familiar with some <ProductConcept /> and know how to develop the things that we will list below.
53
+
Familiarize yourself with the <ProductConcept />.
54
54
55
55
<details>
56
56
<summary>
57
57
58
-
Assume that you have the following <ProductConceptsection="what-is-an-authorization-model"linkName="authorization model" />.<br />
59
-
You have a <ProductConceptsection="what-is-a-type"linkName="type" /> called `trip` that _users_ can be related to as `viewer` and/or an `owner`.
58
+
Assume you have the following <ProductConceptsection="what-is-an-authorization-model"linkName="authorization model" /><br /> and that you have a <ProductConceptsection="what-is-a-type"linkName="type" /> called `trip` that users can be related to as `viewer` and/or as an `owner`.
60
59
61
60
</summary>
62
61
@@ -90,41 +89,41 @@ You have a <ProductConcept section="what-is-a-type" linkName="type" /> called `t
90
89
91
90
<hr />
92
91
93
-
In addition, you will need to know the following:
92
+
In addition, you need to know the following:
94
93
95
94
### Direct Access
96
95
97
-
You need to know how to create an authorization model and create a relationship tuple to grant a user access to an object. [Learn more →](./direct-access.mdx)
96
+
Learn how to create an authorization model and create a relationship tuple to grant a user access to an object. For more information, see [Direct Access.](./direct-access.mdx)
- A <ProductConceptsection="what-is-a-type"linkName="Type" />: a class of objects that have similar characteristics
102
101
- A <ProductConceptsection="what-is-a-user"linkName="User" />: an entity in the system that can be related to an object
103
-
- A <ProductConceptsection="what-is-a-relation"linkName="Relation" />: is a string defined in the type definition of an authorization model that defines the possibility of a relationship between an object of the same type as the type definition and a user in the system
102
+
- A <ProductConceptsection="what-is-a-relation"linkName="Relation" />: a string defined in the type definition of an authorization model that defines the possibility of a relationship between an object of the same type as the type definition and a user in the system
104
103
- An <ProductConceptsection="what-is-an-object"linkName="Object" />: represents an entity in the system. Users' relationships to it can be define through relationship tuples and the authorization model
105
-
- A <ProductConceptsection="what-is-a-relationship-tuple"linkName="Relationship Tuple" />: a grouping consisting of a user, a relation and an object stored in Auth <ProductNameformat={ProductNameFormat.ShortForm}/>
104
+
- A <ProductConceptsection="what-is-a-relationship-tuple"linkName="Relationship Tuple" />: a group consisting of a user, a relation, and an object stored in Auth <ProductNameformat={ProductNameFormat.ShortForm}/>
106
105
- A <ProductConceptsection="what-is-a-relationship"linkName="Relationship" />: <ProductNameformat={ProductNameFormat.ShortForm}/> will be called to check if there is a relationship between a user and an object, indicating that the access is allowed
107
106
-[Direct Relationship Type Restrictions](../configuration-language.mdx#the-direct-relationship-type-restrictions): can be used to indicate direct relationships between users and objects
108
-
- A <ProductConceptsection="what-is-a-check-request"linkName="Check API Request" /> the Check API Request is used to check for relationships between users and objects
107
+
- A <ProductConceptsection="what-is-a-check-request"linkName="Check API Request" />: used to check for relationships between users and objects
109
108
110
109
</details>
111
110
112
111
<Playground />
113
112
114
113
## Step By Step
115
114
116
-
To illustrate modeling Roles and Permissions in <ProductNameformat={ProductNameFormat.ShortForm}/>, we will use a trip booking system where you can have `owners` and/or `viewers` that can have more granular permissions such as adding bookings to a trip or viewing bookings on it.
115
+
To illustrate modeling Roles and Permissions in <ProductNameformat={ProductNameFormat.ShortForm}/>, imagine a trip booking system that has `owners` and/or `viewers`. It can also have granular permissions like adding bookings or viewing bookings on a trip.
117
116
118
-
In order to represent this, we need to:
117
+
To represent this, you need to:
119
118
120
-
1. Understand how roles are related to direct relations for our trip booking system
121
-
2.Adding implied relations to existing authorization model to define permissions for bookings
122
-
3. <ProductConceptsection="what-is-a-check-request"linkName="Checking" /> user roles and their permissions based on *relationship
123
-
tuples* for direct and implied relations
119
+
1. Understand how roles are related to direct relations for the trip booking system
120
+
2.Add implied relations to the existing authorization model to define permissions for bookings
121
+
3. <ProductConceptsection="what-is-a-check-request"linkName="Check" /> user roles and their permissions based on relationship
122
+
tuples for direct and implied relations
124
123
125
124
### 01. Understand How Roles Work Within Our Trip Booking System
126
125
127
-
Relating roles within <ProductNameformat={ProductNameFormat.ShortForm}/> can be best described as the following: **Roles are relations that can be directly assigned to users.** Looking at our authorization model, our roles would then be `owner` and `viewer`. Meaning that a specific _user_ can be an `owner` and/or a `viewer`.
126
+
In <ProductNameformat={ProductNameFormat.ShortForm}/>, roles are relations that can be directly assigned to users. In this authorization model, your roles are `owner` and `viewer`, so a specific user can be an `owner` and/or a `viewer`.
128
127
129
128
<AuthzModelSnippetViewer
130
129
configuration={{
@@ -156,13 +155,13 @@ Relating roles within <ProductName format={ProductNameFormat.ShortForm}/> can be
156
155
}}
157
156
/>
158
157
159
-
### 02. Adding Permissions For Bookings
158
+
### 02. Add Permissions For Bookings
160
159
161
-
Permissions within <ProductNameformat={ProductNameFormat.LongForm}/> can be best described as the following: **Permissions are relations that users get only through other relations.** To represent permissions, we avoid adding a [**direct relationship type restriction**](../configuration-language.mdx#the-direct-relationship-type-restrictions) to the relation in the authorization model. Instead, we define the relation from other relations to indicate that it is a permission granted to and implied from a different relation.
160
+
In <ProductNameformat={ProductNameFormat.LongForm}/>, permissions are relations that users get only through other relations. To represent permissions, define the relation by other relations to indicate that it is a permission both granted to and implied from a different relation. Doing so avoids adding a [direct relationship type restriction](../configuration-language.mdx#the-direct-relationship-type-restrictions) to the relation in the authorization model.
162
161
163
-
To add permissions related to bookings, we can add new relations to the `trip`_object_ type denoting the various actions a user can take on `trips` (view, edit, delete, rename, etc...)
162
+
To add permissions related to bookings, add new relations to the `trip`object type denoting the various actions a user can take on `trips`, like view, edit, or delete.
164
163
165
-
To allow `viewers` of a `trip` to have **permissions to view bookings** and `owners` to have **permissions to add/view bookings,** we would modify the type as the following:
164
+
To allow `viewers` of a `trip` to view bookings and `owners` to add/view bookings,modify the type as seen below:
166
165
167
166
<AuthzModelSnippetViewer
168
167
configuration={{
@@ -219,16 +218,16 @@ To allow `viewers` of a `trip` to have **permissions to view bookings** and `own
219
218
}}
220
219
/>
221
220
222
-
> Note: notice how both `booking_viewer` and `booking_adder` don't have [direct relationship type restrictions](../configuration-language.mdx#the-direct-relationship-type-restrictions). This is to ensure that the relation can only be assigned through the **role** and not directly.
221
+
> Note: Both `booking_viewer` and `booking_adder` don't have [direct relationship type restrictions](../configuration-language.mdx#the-direct-relationship-type-restrictions). This ensures that the relation can only be assigned through the role and not directly.
223
222
224
223
### 03. Checking User Roles And Their Permissions
225
224
226
-
Now that our type definitions reflects the roles and permissions on how bookings can be viewed/added. Let's create _<ProductConceptsection="what-is-a-relationship-tuple"linkName="relationship tuples" />_ to assign roles to _users_ and then *<ProductConceptsection="what-is-a-check-request"linkName="check" />* if _users_ have the proper permissions.
225
+
Now that your type definitions reflect the roles and permissions governing how bookings can be viewed and added, create <ProductConceptsection="what-is-a-relationship-tuple"linkName="relationship tuples" /> to assign roles to users, then *<ProductConceptsection="what-is-a-check-request"linkName="check" />* if users have the proper permissions.
227
226
228
-
Let us create two relationship tuples:
227
+
Create two relationship tuples:
229
228
230
-
1.that gives **bob** the role of `viewer` on `trip`: **Europe**.
231
-
2.that gives **alice** the role of `owner` on `trip`: **Europe**.
229
+
1. gives `bob` the role of `viewer` on `trip:Europe`.
230
+
2. gives `alice` the role of `owner` on `trip:Europe`.
232
231
233
232
<WriteRequestViewer
234
233
relationshipTuples={[
@@ -247,40 +246,40 @@ Let us create two relationship tuples:
247
246
]}
248
247
/>
249
248
250
-
Now we can check: **is bob allowed to view bookings on trip Europe?**
249
+
Now check: `is bob allowed to view bookings on trip Europe?`
**alice** is a `booking_viewer` and `booking_adder` because of the following chain of resolution:
268
+
`alice` is a `booking_viewer` and `booking_adder` because of the following chain of resolution:
270
269
271
-
1.**alice** is a `owner` on `trip`: **Europe**
272
-
2. Any user related to the _object_`trip:`**Europe** as `owner` is also related as a `booking_viewer`
273
-
3. Any user related to the _object_`trip:`**Europe** as `owner` is also related as a `booking_adder`
270
+
1.`alice` is a `owner` on `trip:Europe`
271
+
2. Any user related to the _object_`trip:``Europe` as `owner` is also related as a `booking_viewer`
272
+
3. Any user related to the _object_`trip:``Europe` as `owner` is also related as a `booking_adder`
274
273
4. Therefore, all `owners` on a given `trip` are `booking_viewers` and `booking_adders` on that trip
275
274
276
275
:::caution
277
-
**Note:** Make sure to use unique ids for each object and user within your application domain when creating relationship tuples for <ProductNameformat={ProductNameFormat.LongForm}/>. We are using first names and simple ids to just illustrate an easy-to-follow example.
276
+
Note: Use unique IDs for each object and user within your application domain when creating relationship tuples for <ProductNameformat={ProductNameFormat.LongForm}/>. This guide uses first names and simple IDs as an easy-to-follow example.
278
277
:::
279
278
280
279
## Related Sections
281
280
282
281
<RelatedSection
283
-
description="Check the following sections for more on how to model for roles and permissions."
282
+
description="See following sections for more on how to model for roles and permissions."
0 commit comments