Skip to content

Commit 78c076e

Browse files
feat: new page (querying data) (#451)
Co-authored-by: Sohan <[email protected]>
1 parent a31fc09 commit 78c076e

File tree

7 files changed

+220
-67
lines changed

7 files changed

+220
-67
lines changed

app/authzed/guides/setting-up-private-networking/page.mdx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,30 +114,30 @@ Most users of AuthZed Dedicated on GCP privately connect to SpiceDB with GCP [Pr
114114
1. Navigate to “Private Service Connect” and make sure you are on the “Connected Endpoints” tab.
115115
1. Click “Connect Endpoint”
116116

117-
| Option | Selection |
118-
|------------------------|------------------------------------------------|
119-
| Target | “Published service” |
120-
| Target service | This will be provided to you by Authzed |
121-
| Endpoint name | Name this whatever you want |
122-
| Network and subnetwork | Select the networks you need connectivity from |
123-
| IP address | Choose whatever IP you'd like |
117+
| Option | Selection |
118+
| ---------------------- | ---------------------------------------------- |
119+
| Target | “Published service” |
120+
| Target service | This will be provided to you by Authzed |
121+
| Endpoint name | Name this whatever you want |
122+
| Network and subnetwork | Select the networks you need connectivity from |
123+
| IP address | Choose whatever IP you'd like |
124124

125125
### Enable DNS
126126

127127
1. Navigate to Cloud DNS and create a zone
128128

129-
| Option | Selection |
130-
|-----------|---------------------------------------------------------------------------|
131-
| Zone type | private |
132-
| DNS Name | This will be provided to you by Authzed |
133-
| Networks | Select the network where the Private Service Connect endpoint is deployed |
129+
| Option | Selection |
130+
| --------- | ------------------------------------------------------------------------- |
131+
| Zone type | private |
132+
| DNS Name | This will be provided to you by Authzed |
133+
| Networks | Select the network where the Private Service Connect endpoint is deployed |
134134

135135
1. Add record set
136136

137-
| Option | Selection |
138-
|------------|------------------------------------------------|
139-
| DNS name | This will be provided to you by Authzed |
140-
| IP address | Enter your Private Service Connect endpoint IP |
137+
| Option | Selection |
138+
| ---------- | ---------------------------------------------- |
139+
| DNS name | This will be provided to you by Authzed |
140+
| IP address | Enter your Private Service Connect endpoint IP |
141141

142142
### Add Permission System
143143

@@ -150,15 +150,15 @@ Most users of AuthZed Dedicated on GCP privately connect to SpiceDB with GCP [Pr
150150

151151
Verify connectivity from client machine with the [Zed CLI tool](https://github.com/authzed/zed)
152152

153-
``` zed
153+
```zed
154154
zed context set permission_system_name example.com:443 sdbst_h256_123
155155
```
156156

157-
``` zed
157+
```zed
158158
zed schema write example.yaml
159159
```
160160

161-
``` zed
161+
```zed
162162
zed schema read
163163
```
164164

app/spicedb/concepts/_meta.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default {
44
relationships: "Writing Relationships",
55
caveats: "Writing Relationships with Caveats",
66
"expiring-relationships": "Writing Relationships that Expire",
7+
"querying-data": "Querying Data",
78
commands: "SpiceDB Commands & Parameters",
89
consistency: "Consistency",
910
datastores: "Datastores",

app/spicedb/concepts/commands/page.mdx

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ A database that stores and computes permissions
2727

2828
### Children commands
2929

30-
- [spicedb datastore](#reference-spicedb-datastore) - datastore operations
31-
- [spicedb lsp](#reference-spicedb-lsp) - serve language server protocol
32-
- [spicedb man](#reference-spicedb-man) - Generate man page
33-
- [spicedb serve](#reference-spicedb-serve) - serve the permissions database
34-
- [spicedb serve-testing](#reference-spicedb-serve-testing) - test server with an in-memory datastore
35-
- [spicedb version](#reference-spicedb-version) - displays the version of SpiceDB
36-
30+
- [spicedb datastore](#reference-spicedb-datastore) - datastore operations
31+
- [spicedb lsp](#reference-spicedb-lsp) - serve language server protocol
32+
- [spicedb man](#reference-spicedb-man) - Generate man page
33+
- [spicedb serve](#reference-spicedb-serve) - serve the permissions database
34+
- [spicedb serve-testing](#reference-spicedb-serve-testing) - test server with an in-memory datastore
35+
- [spicedb version](#reference-spicedb-version) - displays the version of SpiceDB
3736

3837
## Reference: `spicedb datastore`
3938

@@ -49,11 +48,10 @@ Operations against the configured datastore
4948

5049
### Children commands
5150

52-
- [spicedb datastore gc](#reference-spicedb-datastore-gc) - executes garbage collection
53-
- [spicedb datastore head](#reference-spicedb-datastore-head) - compute the head (latest) database migration revision available
54-
- [spicedb datastore migrate](#reference-spicedb-datastore-migrate) - execute datastore schema migrations
55-
- [spicedb datastore repair](#reference-spicedb-datastore-repair) - executes datastore repair
56-
51+
- [spicedb datastore gc](#reference-spicedb-datastore-gc) - executes garbage collection
52+
- [spicedb datastore head](#reference-spicedb-datastore-head) - compute the head (latest) database migration revision available
53+
- [spicedb datastore migrate](#reference-spicedb-datastore-migrate) - execute datastore schema migrations
54+
- [spicedb datastore repair](#reference-spicedb-datastore-repair) - executes datastore repair
5755

5856
## Reference: `spicedb datastore gc`
5957

@@ -148,8 +146,6 @@ spicedb datastore gc [flags]
148146
--skip-release-check if true, skips checking for new SpiceDB releases
149147
```
150148

151-
152-
153149
## Reference: `spicedb datastore head`
154150

155151
compute the head (latest) database migration revision available
@@ -181,8 +177,6 @@ spicedb datastore head [flags]
181177
--skip-release-check if true, skips checking for new SpiceDB releases
182178
```
183179

184-
185-
186180
## Reference: `spicedb datastore migrate`
187181

188182
Executes datastore schema migrations for the datastore.
@@ -222,8 +216,6 @@ spicedb datastore migrate [revision] [flags]
222216
--skip-release-check if true, skips checking for new SpiceDB releases
223217
```
224218

225-
226-
227219
## Reference: `spicedb datastore repair`
228220

229221
Executes a repair operation for the datastore
@@ -317,8 +309,6 @@ spicedb datastore repair [flags]
317309
--skip-release-check if true, skips checking for new SpiceDB releases
318310
```
319311

320-
321-
322312
## Reference: `spicedb lsp`
323313

324314
serve language server protocol
@@ -342,20 +332,17 @@ spicedb lsp [flags]
342332
--skip-release-check if true, skips checking for new SpiceDB releases
343333
```
344334

345-
346-
347335
## Reference: `spicedb man`
348336

349337
Generate a man page for SpiceDB.
350-
The output can be redirected to a file and installed to the system:
338+
The output can be redirected to a file and installed to the system:
351339

352340
```
353341
spicedb man > spicedb.1
354342
sudo mv spicedb.1 /usr/share/man/man1/
355343
sudo mandb # Update man page database
356344
```
357345

358-
359346
```
360347
spicedb man
361348
```
@@ -368,8 +355,6 @@ spicedb man
368355
--skip-release-check if true, skips checking for new SpiceDB releases
369356
```
370357

371-
372-
373358
## Reference: `spicedb serve`
374359

375360
start a SpiceDB server
@@ -558,8 +543,6 @@ spicedb serve [flags]
558543
--skip-release-check if true, skips checking for new SpiceDB releases
559544
```
560545

561-
562-
563546
## Reference: `spicedb serve-testing`
564547

565548
An in-memory spicedb server which serves completely isolated datastores per client-supplied auth token used.
@@ -621,8 +604,6 @@ spicedb serve-testing [flags]
621604
--skip-release-check if true, skips checking for new SpiceDB releases
622605
```
623606

624-
625-
626607
## Reference: `spicedb version`
627608

628609
displays the version of SpiceDB
@@ -644,6 +625,3 @@ spicedb version [flags]
644625
--log-level string verbosity of logging ("trace", "debug", "info", "warn", "error") (default "info")
645626
--skip-release-check if true, skips checking for new SpiceDB releases
646627
```
647-
648-
649-
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import { Callout } from "nextra/components";
2+
3+
# Querying Data
4+
5+
This page walks through the main ways to query data in SpiceDB. The options are listed roughly in the order of how often you should be calling them, and roughly in order of their expected performance. Choose the one that makes sense for your use case, but consider whether your use case actually requires the call you're looking at.
6+
7+
<Callout type="info">
8+
In most of the APIs below, if you want to be able to read your write, you can
9+
pass a `consistency` parameter to the queries. Use either `fully_consistent`
10+
or `at_least_as_fresh(revision)` depending on how strict you need to be. See
11+
[Consistency](consistency) for more details.
12+
</Callout>
13+
14+
<Callout type="important">
15+
When invoking any of our APIs, you can send a header `X-Request-ID=somevalue`
16+
and it will be echoed back in the response, which makes correlating logs or
17+
tracing requests easy.
18+
</Callout>
19+
20+
## Check Permission
21+
22+
Send:
23+
24+
- Subject Type
25+
- Subject ID
26+
- Permission (or relation)
27+
- Object Type
28+
- Object ID
29+
30+
Receive:
31+
32+
- Yes/no (or a provisional response if missing caveat data)
33+
34+
[`CheckPermission`](https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.PermissionsService.CheckPermission) is the go-to for most access checks. It’s designed for high-traffic workloads.
35+
36+
You can debug a check locally with `zed permission check resource:someresource somepermission user:someuser --explain` to understand how the decision was made.
37+
38+
When your schema uses [caveats](caveats) and you don't provide all the required context in the request parameters, the API will tell you that in the response that the result is "conditional" instead of simply denying or allowing, and it's up to you to inspect that result.
39+
40+
The `subject` of the query can be a single user (e.g. `user:someuser`) or a set of users (e.g. `group:engineering#member`).
41+
42+
### CheckBulkPermissions
43+
44+
Send Many:
45+
46+
- Subject Type
47+
- Subject ID
48+
- Permission (or relation)
49+
- Object Type
50+
- Object ID
51+
52+
Receive Many:
53+
54+
- Yes/no (or a provisional response if missing caveat data)
55+
56+
If your app needs to do multiple checks (for example, for various subjects), use the [`CheckBulkPermissions`](https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.PermissionsService.CheckBulkPermissions) API. It's great for UI workloads where you need to check multiple permissions at once: think tables, lists, and dashboards.
57+
58+
It's also the recommended way to ask "what permissions does a given subject have on a resource?"
59+
Make a check for each permission in your schema. This will require you to update calling code when you add permissions,
60+
but the consuming code will need to be changed to include the logic associated with the new permission in any case.
61+
62+
It's always preferable to perform one call to `CheckBulkPermissions` with N checks than N calls to `CheckPermission`, unless you don't want to wait for the N checks to finish.
63+
64+
## LookupResources
65+
66+
Send Many:
67+
68+
- Subject Type
69+
- Subject ID
70+
- Permission (or relation)
71+
- Object Type
72+
73+
Receive many:
74+
75+
- Object ID
76+
77+
[`LookupResources`](https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.PermissionsService.LookupResources) is a good choice when you need to find all resources of a given type that a specific subject can access. It supports cursoring and works well for moderate result sizes.
78+
79+
It's a good way to do [prefiltering of results](/spicedb/modeling/protecting-a-list-endpoint#filtering-with-lookupresources) in
80+
a List endpoint, but it's a heavy request that can cause performance problems when more than 10k results are involved.
81+
In that case we recommend postfiltering with [CheckBulk](#checkbulkpermissions), and if that still doesn't work,
82+
we recommend evaluating [Materialize](/authzed/concepts/authzed-materialize).
83+
84+
## LookupSubjects
85+
86+
Send Many:
87+
88+
- Subject Type
89+
- Permission (or relation)
90+
- Object Type
91+
- Object ID
92+
93+
Receive many:
94+
95+
- Subject ID
96+
97+
[`LookupSubjects`](https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.PermissionsService.LookupSubjects) returns
98+
all subjects that have access to a specific resource. It does not support cursoring.
99+
100+
It's commonly used to drive UIs and APIs that list users with given permission or set of permissions, such as a table of Admins
101+
on a particular Organization.
102+
103+
Note that LookupSubjects will do a full path walk between an object and a subject, and will consider all valid paths between object and subject.
104+
If you are looking to find all the subjects that are on a specific relation, use `ReadRelationships` instead of `LookupSubjects`.
105+
106+
If your schema includes exclusions and wildcards, the response can include a list of subjects that have been explicitly excluded.
107+
108+
For example, if the schema is
109+
110+
```zed
111+
definition user {}
112+
113+
definition document {
114+
relation blocked: user
115+
relation view: user:*
116+
permission viewer = view - blocked
117+
}
118+
```
119+
120+
and the relationships are
121+
122+
```relationship filename="Relationships"
123+
document:finance#view@user:*
124+
document:finance#blocked@user:anne
125+
document:finance#blocked@user:bob
126+
```
127+
128+
Then `LookupSubjects` for `document:finance` will return a response of the form `{user:* - [user:anne,user:bob]}`.
129+
130+
## ReadRelationships
131+
132+
[`ReadRelationships`](https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.PermissionsService.ReadRelationships) is intended a an escape hatch,
133+
and should only be considered if no other API matches your use case.
134+
135+
It's considerably more flexible in that you can send any combination of:
136+
137+
- Subject Type
138+
- Subject ID
139+
- Permission (or relation)
140+
- Object Type
141+
- Object ID
142+
143+
And receive all relationships that match that filter, but it comes with some important caveats:
144+
145+
- It's generally less optimized than the `Check` and `Lookup` APIs because of that flexibility
146+
- It does no caching. The `Check` and `Lookup` APIs gain much of their performance by caching the results of subproblem computation; `ReadRelationships` does no caching and will go directly to the database every time.
147+
- The indexes in the backing [datastores](/spicedb/concepts/datastores) are optimized around the `Check` and `Lookup` APIs, so it's possible to
148+
craft a `ReadRelationships` request that misses indexes and requires a full table scan. This is because covering all combinations of filters
149+
with an index would impact write performance too much.
150+
151+
Some use cases where `ReadRelationships` may be warranted:
152+
153+
- Deleting all relationships in a subtree, where a simple [RelationshipFilter](https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.RelationshipFilter) in a [DeleteRelationships](https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.DeleteRelationshipsRequest) would be insufficient
154+
- Admin UIs that show lists of roles or relationships between objects
155+
156+
## Watch
157+
158+
The Watch API is not meant to answer permission questions but to serve other use-cases, like auditing. See [the Watch API documentation](/spicedb/concepts/watch) for more details.
159+
160+
## ExpandPermissionTree
161+
162+
This [ExpandPermissionTree](https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.PermissionsService.ExpandPermissionTree) API
163+
comes from the [Zanzibar Paper](https://authzed.com/zanzibar#2.4.5-expand). It allows you to examine the subtree of relationships
164+
around a particular point in the graph, and is useful in scenarios like your UI needing to show which users _and groups_ have access to something.
165+
166+
In practice we don't see many uses of this API, especially because it only resolves one "hop" in the graph at a time and must be called
167+
repeatedly to get a full picture of a subtree.

app/spicedb/getting-started/faq/page.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ Choose based on your scale: start with LookupResources, move to CheckBulkPermiss
6060

6161
[Learn more]: ../modeling/protecting-a-list-endpoint
6262

63+
## How do I get all of the permissions a subject has on a resource?
64+
65+
There isn't an API that answers this question directly. Instead, you should use the
66+
[`CheckBulkPermissions`](https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.PermissionsService.CheckBulkPermissions) API and send a check for each of the permissions you want to check.
67+
68+
It means that you'll need to update your permission checks when you add a new permission, but you'd need to update the calling code
69+
to handle the concept that a new permission represents anyway.
70+
6371
## How can I get involved with SpiceDB?
6472

6573
The best first step is to join [Discord].

app/spicedb/getting-started/first-steps/page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import { InlinePlayground } from "@/components/playground";
2222
We've documented the concepts SpiceDB users should understand:
2323

2424
<Cards>
25-
<Cards.Card arrow={true} title="Zanzibar" href="../concepts/zanzibar" />
2625
<Cards.Card arrow={true} title="Writing a Schema" href="../concepts/schema" />
2726
<Cards.Card arrow={true} title="Writing Relationships" href="../concepts/relationships" />
27+
<Cards.Card arrow={true} title="Querying Data" href="../concepts/querying-data" />
2828
</Cards>
2929

3030
After these, we recommend these concepts for running SpiceDB:

0 commit comments

Comments
 (0)