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
@@ -12,7 +12,8 @@ You can experiment with schemas in real-time with the [Playground](https://play.
12
12
13
13
The following video provides an overview of schema development using the Playground:
14
14
15
-
<br /><YouTubevideoId="AoK0LrkGFDY" />
15
+
<br />
16
+
<YouTubevideoId="AoK0LrkGFDY" />
16
17
17
18
After studying this page's content, you may want to also read the [Developing a Schema] doc.
18
19
@@ -22,7 +23,6 @@ After studying this page's content, you may want to also read the [Developing a
22
23
23
24
The top level of a Schema consists of zero or more [Object Type definitions](#object-type-definitions) and [Caveats](./caveats).
24
25
25
-
26
26
```zed
27
27
/**
28
28
* somecaveat is a caveat defined
@@ -38,8 +38,9 @@ definition someobjecttype {}
38
38
```
39
39
40
40
<Callouttype="info">
41
-
Note that the examples are unprefixed.
42
-
You'll need to add the prefix from your permissions system if calling `WriteSchema` for a permissions system hosted in Serverless.
41
+
Note that the examples are unprefixed. You'll need to add the prefix from your
42
+
permissions system if calling `WriteSchema` for a permissions system hosted in
43
+
Serverless.
43
44
</Callout>
44
45
45
46
### Object Type Definitions
@@ -84,7 +85,8 @@ definition document {
84
85
<Callouttype="info">
85
86
In the above example, the `user` on `reader` does not contain a sub-relation
86
87
87
-
Occasionally you will see a subject which has a sub-relation such as `usergroup:admins#members` which refers not just to the `usergroup` as a whole, but the set of members which have that relation to the `usergroup`.
88
+
Occasionally you will see a subject which has a sub-relation such as `usergroup:admins#members` which refers not just to the `usergroup` as a whole, but the set of members which have that relation to the `usergroup`.
89
+
88
90
</Callout>
89
91
90
92
### Subject Relations
@@ -105,7 +107,8 @@ definition group {
105
107
```
106
108
107
109
<Callouttype="info">
108
-
Subject Relations are useful in RBAC-style permissions systems to grant "roles" to _sets_ of subjects, such as the members of a team.
110
+
Subject Relations are useful in RBAC-style permissions systems to grant
111
+
"roles" to _sets_ of subjects, such as the members of a team.
Arrows allow for "walking" the heirarchy of relations (and permissions) defined for an object, referencing a permission or relation on the _resulting_ object.
224
+
Arrows allow for "walking" the heirarchy of relations (and permissions) defined for an **object** of a subject, referencing a permission or relation on the _resulting_ subject's object.
222
225
223
226
For example, imagine a schema where a document is found under a folder:
224
227
@@ -283,8 +286,38 @@ definition document {
283
286
```
284
287
285
288
<Callouttype="info">
286
-
It is _recommended_ that the right side of all arrows refer to **permissions**, instead
287
-
of relations. This allows for easy nested computation, and is more readable.
289
+
It is _recommended_ that the right side of all arrows refer to
290
+
**permissions**, instead of relations, as this allows for easy nested
291
+
computation, and is more readable.
292
+
</Callout>
293
+
294
+
##### Subject relations and Arrows
295
+
296
+
<Callouttype="warning">
297
+
Arrows operate on the **object** of the subject(s) found on a `relation`. They
298
+
*do not* operate on the relation/permission of a subject, *even if the subject
299
+
refers to a relation or permission*.
300
+
</Callout>
301
+
302
+
For example, in:
303
+
304
+
```
305
+
defintion resource {
306
+
relation parent: group#member
307
+
permission someperm = parent->something
308
+
}
309
+
```
310
+
311
+
`parent->something` refers to the `something` permission on the **group**, and `#member` will be ignored for the arrow.
312
+
313
+
It is recommended to not use arrows over relations that allow for subject relations without noting that
314
+
fact via a comment.
315
+
316
+
<Callouttype="info">
317
+
Why is this the case? In one word: **performance**. If arrows operated over
318
+
the subject's relation or permission, a full LookupSubjects call would be
319
+
necessary for the arrow to correctly "walk", which would make these
You'll note that we also used `member` above in the relation example. Defining `member` as a **permission** might be found when you have multiple "ways" a subject can be a member of a resource, thus changing it from a simple relation to a _computed_ set of subjects.
337
+
You'll note that we also used `member` above in the relation example. Defining
338
+
`member` as a **permission** might be found when you have multiple "ways" a
339
+
subject can be a member of a resource, thus changing it from a simple relation
340
+
to a _computed_ set of subjects.
305
341
</Callout>
306
342
307
343
## Comments
308
344
309
345
### Documentation Comments
310
346
311
347
<Callouttype="info">
312
-
It is **highly** recommended to put doc comments on all definitions, relations and permissions.
348
+
It is **highly** recommended to put doc comments on all definitions, relations
349
+
and permissions.
313
350
</Callout>
314
351
315
352
```zed
@@ -327,7 +364,7 @@ It is **highly** recommended to put doc comments on all definitions, relations a
327
364
328
365
## Full Example
329
366
330
-
<InlinePlaygroundreference="vlduOcwEOmVY"/>
367
+
<InlinePlaygroundreference="vlduOcwEOmVY"/>
331
368
332
369
## Common Patterns
333
370
@@ -340,7 +377,7 @@ Both admins and members are considered to have membership in the group.
340
377
A role can be applied to individual users and groups.
341
378
All individually applied users as well as members for applied groups will have the `allowed` permission.
342
379
343
-
<InlinePlaygroundreference="CNe3PXNuhypm"/>
380
+
<InlinePlaygroundreference="CNe3PXNuhypm"/>
344
381
345
382
### Global admin permissions
346
383
@@ -350,7 +387,7 @@ In lieu of adding a <code>super_admin</code> relation on every object that can b
350
387
Super admin users can be applied to <code>platform</code> and a relation to <code>platform</code> on top level objects.
351
388
Admin permission on resources is then defined as the direct owner of the resource as well as through a traversal of the object hierarchy to the platform super admin.
352
389
353
-
<InlinePlaygroundreference="m1lRfaaYf9XP"/>
390
+
<InlinePlaygroundreference="m1lRfaaYf9XP"/>
354
391
355
392
### Synthetic relations
356
393
@@ -375,15 +412,16 @@ In this example, a folder can have users with read permission.
375
412
Additionally, users that can read the parent folder can also read the current folder.
376
413
Checking read permission on a folder will recursively consider these relations as the answer is computed.
377
414
378
-
<InlinePlaygroundreference="8tE13O7iMM8W"/>
415
+
<InlinePlaygroundreference="8tE13O7iMM8W"/>
379
416
380
417
<Callouttype="info">
381
-
Note that since `parent->read` calls the same `read` permission, it will form a recursive lookup across the chain of parent folder(s).
418
+
Note that since `parent->read` calls the same `read` permission, it will form
419
+
a recursive lookup across the chain of parent folder(s).
382
420
</Callout>
383
421
384
422
### Recursive permissions across different resource types
385
423
386
424
If a non-recursive resource is used as the starting point for a recursive lookup, it is
387
425
**very important** that the permission name used on the right side of the arrow is the **same** in both the starting resource type and the parent resource type(s):
0 commit comments