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
+63-7Lines changed: 63 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -117,21 +117,31 @@ A few important notes:
117
117
Otherwise, the values in the `Relationship` take precedence over those in the `CheckPermissionRequest`.
118
118
- Context of a caveat provided in `Relationship` is stored alongside the relationship and is provided to the caveat expression at runtime.
119
119
This allows for **partial** binding of data at write time.
120
-
- The Context is a `structpb`, which is defined by Google and represents JSON-like data: [https://pkg.go.dev/google.golang.org/protobuf/types/known/structpb](https://pkg.go.dev/google.golang.org/protobuf/types/known/structpb)
120
+
- The Context is a `structpb`, which is defined by Google [and represents JSON-like data](https://pkg.go.dev/google.golang.org/protobuf/types/known/structpb).
121
121
- To send 64-bit integers, encode them as strings.
122
122
- A relationship cannot be duplicated, with or without a caveat, e.g. two relationships that differ only on their use of a caveat cannot both exist.
123
123
- When deleting a relationship, a caveat does not need to be specified; the matching relationship will be deleted if present.
124
124
125
-
## Issuing Checks
125
+
## Providing Caveat Context via the API
126
+
127
+
### `CheckPermission`
126
128
127
129
When issuing a [CheckPermission request][check-req], additional caveat context can be specified to represent the known context at the time of the check:
128
130
129
131
```textproto
130
132
CheckPermissionRequest {
131
-
Resource: …,
132
-
Permission: …,
133
-
Subject: …,
134
-
Context: { "user_ip": "1.2.3.4" }
133
+
resource: {
134
+
object_type: "book",
135
+
object_id: "specificbook",
136
+
},
137
+
permission: "view",
138
+
subject: {
139
+
object: {
140
+
object_type: "user",
141
+
object_id: "specificuser",
142
+
},
143
+
},
144
+
context: { "user_ip": "1.2.3.4" }
135
145
}
136
146
```
137
147
@@ -147,10 +157,56 @@ In the case of `PERMISSIONSHIP_CONDITIONAL_PERMISSION`, SpiceDB will also return
Similarly to **CheckPermission**, both **LookupResources** and **LookupSubjects** can be provided with additional context and will return one of the two permission states for each of the results found (either has permission or conditionally has permission).
153
163
164
+
```textproto
165
+
LookupResourcesRequest {
166
+
resource_object_type: "book",
167
+
permission: "view",
168
+
subject: {
169
+
object: {
170
+
object_type: "user",
171
+
object_id: "specificuser",
172
+
},
173
+
},
174
+
context: { "user_ip": "1.2.3.4" }
175
+
}
176
+
```
177
+
178
+
### Providing Caveat Context with `zed CLI
179
+
180
+
When using `zed` command-line tool to interact with SpiceDB, the context can be provided using the `--caveat-context` flag.
181
+
The caveat context should be a JSON representation that matches the types defined in the schema.
Please note the use of single quotes to escape the characters in the JSON representation of the context.
207
+
You don't need character escaping when providing context using zed in the Authzed Playground.
208
+
</Callout>
209
+
154
210
## Full Example
155
211
156
212
A full example of a schema with caveats can be found below, which allows users to `view` a resource if they are directly a `viewer` or they are a`viewer` within the correct IP CIDR range:
0 commit comments