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: app/spicedb/concepts/schema/page.mdx
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -417,6 +417,36 @@ In the above example, the user must be in the `member` relation for _all_ groups
417
417
results for the arrow.
418
418
</Callout>
419
419
420
+
### The `self` Keyword
421
+
422
+
_Available in SpiceDB v1.49.0_
423
+
424
+
A common piece of authorization logic is that a `user` should always be able to view themselves.
425
+
Using the `self` keyword provides a simple way to express this:
426
+
427
+
```zed
428
+
use self
429
+
430
+
definition user {
431
+
relation viewer: user
432
+
permission view = viewer + self
433
+
}
434
+
```
435
+
436
+
With the `self` keyword, any check for that permission that has the same subject and object (e.g. `user:alice#view@user:alice`) will evaluate to true.
437
+
438
+
This can be expressed without the `self` keyword as well:
439
+
440
+
```zed
441
+
definition user {
442
+
relation viewer: user
443
+
permission view = viewer
444
+
}
445
+
```
446
+
447
+
But in order to express that a user should be able to view themselves, you'll need to write a corresponding relationship (e.g. `user:alice#viewer@user:alice`)
448
+
for the check to evaluate to true. The `self` keyword requires less DB space and computation to achieve the same result.
449
+
420
450
### Naming Permissions
421
451
422
452
Permissions define a set of objects that can perform an action or have some attribute, and thus **permissions should be named as verbs or nouns**, read as `(is/can) {permission name} (the object)`.
Copy file name to clipboardExpand all lines: app/spicedb/modeling/attributes/page.mdx
+28-26Lines changed: 28 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,40 @@ SpiceDB is a Relationship Based Access control system.
9
9
This gives SpiceDB the flexibility to evaluate attributes for access control alongside more complicated access control logic like roles and/or relationships.
10
10
11
11
The sections below will provide practical examples for implementing various kinds of attributes in the SpiceDB schema language.
12
-
Before reading this guide, it's recommended that you have some familiarity with the SpiceDB schema language. [These documents](/spicedb/modeling/developing-a-schema) are a good place to start.
12
+
Before reading this guide, it's recommended that you have some familiarity with the SpiceDB schema language.
13
+
[This guide](/spicedb/modeling/developing-a-schema) is a good place to start.
13
14
14
15
## Boolean Attributes
15
16
16
17
A boolean attribute is an attribute on an object that affects authorization by enabling or disabling an authorization setting.
17
18
Boolean attributes can often be thought of as a toggle.
18
19
Feature flag authorization can be enabled with boolean attributes.
19
20
21
+
### Loop Relationships
22
+
23
+
Loop relationships are one way to implement boolean attributes.
24
+
25
+
In the example below, there is a schema that enforces the following authorization logic: a user can
26
+
only view a document if the user is related to the document as viewer and editing is enabled for the
27
+
document (this is the same authorization logic used in the wildcard example below).
28
+
29
+
In the example below, to enable editing for a document, a loop relationship using the `edit_enabled` relation must be written.
30
+
When a `document` is related to itself with the `edit_enabled` relation, that relation can be walked to itself
31
+
(with the arrow) to determine who relates to the document as an `editor`.
32
+
33
+
In summary, a `user` has permission to edit a `document` if they are related to that document as an `editor`
34
+
and that document is related to itself with `edit_enabled`.
35
+
36
+
<InlinePlaygroundreference="ifgMyLGN-Hjw" />
37
+
38
+
<Callouttype="warning">
39
+
There is no mechanism in the SpiceDB schema language that enforces that a
40
+
relation be used as a loop relation. In order to avoid accidentally misusing a
41
+
loop relation (e.g. relating an object to a different instance of the same
42
+
type) it is recommended to implement client side logic that enforces only
43
+
using the loop relation for its intended purpose.
44
+
</Callout>
45
+
20
46
### Wildcards
21
47
22
48
[Wildcards](/spicedb/concepts/schema#wildcards) are a way to implement boolean attributes.
@@ -32,31 +58,7 @@ To enable document editing, you need to establish a relationship that connects a
32
58
Wildcards are adequate for most binary attribute scenarios; however, wildcards
33
59
are not currently supported by [Authzed
34
60
Materialize](/authzed/concepts/authzed-materialize). Those who plan to use
35
-
Materialize should use self relationships for binary attributes.
36
-
</Callout>
37
-
38
-
### Self Relationships
39
-
40
-
Self relationships are another way to implement boolean attributes.
41
-
Self relationships relate an object to itself.
42
-
A self relationship is walked with an [arrow](/spicedb/concepts/schema#--arrow) back to an object's self.
43
-
In practice, relating something to itself toggles something on.
44
-
45
-
In the example below, there is a schema that enforces the following authorization logic: a user can only view a document if the user is related to the document as viewer and editing is enabled for the document (this is the same authorization logic used in the wildcard example above).
46
-
47
-
In the example below, to enable editing for a document, a self relationship using the `edit_enabled` relation must be written.
48
-
When a `document` is related to itself with the `edit_enabled` relation, that relation can be walked to itself (with the arrow) to determine who relates to the document as an `editor`.
49
-
50
-
In summary, a `user` has permission to edit a `document` if they are related to that document as an `editor` and that document is related to itself with `edit_enabled`.
51
-
52
-
<InlinePlaygroundreference="ifgMyLGN-Hjw" />
53
-
54
-
<Callouttype="warning">
55
-
There is no mechanism in the SpiceDB schema language that enforces that a
56
-
relation be used as a self relation. In order to avoid accidentally misusing a
57
-
self relation (e.g. relating an object to a different instance of the same
58
-
type) it is recommended to implement client side logic that enforces only
59
-
using the self relation for it's intended purpose.
61
+
Materialize should use loop relationships for binary attributes.
0 commit comments