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: pages/spicedb/concepts/caveats.mdx
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,17 @@ import { Callout } from 'nextra/components'
2
2
3
3
# Caveats
4
4
5
-
Caveats are a feature within SpiceDB that allows for relationships to be defined conditionally: the relationship will only be considered present if the caveat expression evaluates to true.
5
+
Caveats are expressions that can return true or false, and they can be attached (by name) to relationships.
6
+
7
+
They allow relationships to be defined conditionally: when executing permission checks (e.g. [CheckPermission]), the caveated relationship will only be considered present if the caveat expression evaluates to true at the time you run the `CheckPermission`.
Caveats allow for an elegant way to model dynamic policies and ABAC-style (Attribute Based Access Control) decisions while still providing scalability and performance guarantees.
8
12
9
13
## Defining Caveats
10
14
11
-
Caveats are named expressions that are defined in schema alongside definitions for object types.
15
+
Caveats are named expressions that are defined in the [schema](./schema) alongside definitions for object types.
12
16
A caveat definition includes a name, one or more well-typed parameters, and a [CEL expression] returning a boolean value.
Copy file name to clipboardExpand all lines: pages/spicedb/concepts/relationships.mdx
+76-23Lines changed: 76 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,56 +2,75 @@ import { Callout } from 'nextra/components'
2
2
3
3
# Relationships
4
4
5
-
Relationships bind together two Objects (a Subject and a Resource) via a Relation.
6
-
The concept behind ReBAC authorization systems is that by following a chain of relationships, one can determine access.
7
-
8
-
In SpiceDB, a functioning Permissions System is the combination of [Schema], which defines the structure of data, and Relationships which are the data.
5
+
In SpiceDB, a functioning Permissions System is the combination of [Schema], which defines the structure of data, and Relationships, which are the data.
9
6
10
7
[schema]: ./schema
11
8
12
9
## Understanding Relationships
13
10
14
-
At its core, authorization logic fundamentally reduces to asking a single question:
11
+
Let's start with a simple schema that models a document sharing system:
15
12
16
-
> Is this actor allowed to perform this action on this resource?
13
+
```zed
14
+
definition user {}
17
15
18
-
This question can be broken down into core components:
16
+
definition team {
17
+
relation member: user
18
+
}
19
19
20
-
```
21
-
Is this actor allowed to perform this action on this resource?
22
-
/¯¯¯¯¯¯¯/ /¯¯¯¯¯¯¯¯¯/ /¯¯¯¯¯¯¯¯¯¯¯/
23
-
object permission or object
24
-
(subject) relation (resource)
20
+
definition document {
21
+
# both specific users and all members of specific teams can edit the document
22
+
relation editor: user | team#member
23
+
}
25
24
```
26
25
27
-
In SpiceDB parlance, _this actor_ and _this resource_ are both [Objects] and _this action_ is a [Permission] or [Relation] (consider them equivalant for now).
28
-
By focusing solely on these components of the question, it becomes clear that this is the same structure as a Relationship: two Objects and a Relation.
26
+
This schema defines three types of [Objects]: `user`, `team` and `document`. The `document` type has one **relation** defined on it: `editor`.
29
27
30
-
The power of ReBAC comes from transforming this basic question into another one:
28
+
A **relation** is like a class definition in Object-Oriented programming or a type in a strongly-typed language: it represents a possible type of connection defined in your schema. For example: "documents have editors".
31
29
32
-
> Does there exist a chain of relationships starting at this resource through this relation that ultimately reaches this subject?
30
+
A **relationship** is a specific instance of a relation - it's the actual data. For example: "user `emilia` is an editor of document `readme`"
33
31
34
-
This new question is one of [graph reachability].
35
-
General purpose graph databases optimize for a couple different types of graph traversals; usually [breadth-first search] and [depth-first search], but ReBAC systems are optimized for scalably and efficiently computing reachability along with all of the assumptions that come with the domain of authorization.
32
+
### Relationship Syntax
36
33
37
-
The syntax used for relationships in the [paper that popularized ReBAC](./zanzibar)is as follows:
34
+
The syntax used for relationships in the [paper that popularized ReBAC](./zanzibar)and that we use throughout this website is:
38
35
39
36
```
40
37
document:readme#editor@user:emilia
41
38
```
42
39
43
-
Here it is with labels explaining each section around the delimiters:
40
+
Let's break this down:
44
41
45
42
```
46
43
resource subject
47
44
ID type
48
45
\ˍˍˍˍˍ\ \ˍˍ\
49
46
document:readme#editor@user:emilia
50
47
/¯¯¯¯¯¯¯/ /¯¯¯¯¯/ /¯¯¯¯¯/
51
-
resource permission subject
52
-
type or relation ID
48
+
resource relation subject
49
+
type ID
50
+
```
51
+
52
+
This relationship can be read as: "user `emilia` is an `editor` of document `readme`". Note how this is connecting two specific objects.
53
+
54
+
We can also write relationships that link one object to a set of objects.
55
+
56
+
```
57
+
document:readme#editor@team:engineering#member
58
+
```
59
+
60
+
Let's break this down:
61
+
62
+
```
63
+
resource subject
64
+
ID type
65
+
\ˍˍˍˍˍ\ \ˍˍ\
66
+
document:readme#editor@team:engineering#member
67
+
/¯¯¯¯¯¯¯/ /¯¯¯¯¯/ /¯¯¯¯¯¯¯¯¯¯//¯¯¯¯¯/
68
+
resource relation subject subject
69
+
type ID relation
53
70
```
54
71
72
+
This relationship can be read as: "every object that has the `member` relation to `team:engineering` is an `editor` of document `readme`".
73
+
55
74
<Callouttype="info">
56
75
In a real system, Object IDs are most likely a computer-friendly string than something human readable.
57
76
Many use-cases use UUIDs or unsigned integers representing the primary key from that data's canonical datastore.
@@ -61,11 +80,45 @@ resource permission subject
61
80
Regardless of their representation, Object IDs must be **unique and stable** within the set of IDs for an Object Type.
62
81
</Callout>
63
82
64
-
Relationships are powerful because of their duality: they are both the question and, when written in aggregate, the answer.
83
+
### Graph traversals
84
+
85
+
At its core, authorization logic fundamentally reduces to asking:
86
+
87
+
> Is this actor allowed to perform this action on this resource?
88
+
89
+
For example: "Is user `emilia` allowed to `edit` document `readme`?"
90
+
91
+
If you had these relationships written in SpiceDB:
92
+
93
+
-`document:readme#editor@user:emilia`
94
+
95
+
Then the answer is trivial: yes, `emilia` can edit the document.
96
+
97
+
If, instead, you had these relationships written in SpiceDB:
98
+
99
+
-`team:engineering#member@user:emilia` - emilia is on the engineering team
100
+
-`document:readme#editor@team:engineering#member` - every member on the engineering team can edit the readme
101
+
102
+
When checking "Can user `emilia` edit document `readme`?", SpiceDB:
103
+
104
+
1. Starts at `document:readme#editor`
105
+
2. Follows the `editor` relation to find `team:engineering#member`
106
+
3. Follows the `member` relation to find `user:emilia`
107
+
108
+
[//]: #(TODO add drawing)
109
+
110
+
Note how we followed a chain of relationships to answer the question. Or, put differently, we traversed a [graph].
111
+
112
+
The real power of ReBAC comes from transforming authorization questions into [graph reachability] problems, and then answering them efficiently:
113
+
114
+
> Is there a chain of **relationships** starting at this resource and relation that ultimately reaches this subject?
115
+
116
+
This is what makes relationships powerful: they are both **the question you ask** ("does this relationship path exist?") and, when you write many of them together, **they form the answer** (by creating paths through the graph that SpiceDB can traverse).
0 commit comments