Skip to content

Commit 2f4de99

Browse files
Merge pull request #599 from authzed/federated-authorization-tutorial
Updates to the federated authz tutorial
2 parents 8286bde + 77d9585 commit 2f4de99

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

‎app/spicedb/tutorials/federated-authorization/page.mdx‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ This tutorial illustrates how you can use SpiceDB to centralize permissions by m
99
The central idea is: don't point your resources at "the GitHub user" or "the Keycloak user."
1010
Point them at an internal user you own, and bind each external account to it.
1111

12-
![Many identity providers, one federated authorization: the app resolves each login from a swappable IdP to an internal user via a bound_to lookup in SpiceDB, which stores the identity bindings and governs document access for internal users only](/images/federated-architecture.png)
12+
![Many identity providers, one federated authorization: the app resolves each login from a swappable IdP to an internal user via a bound_to lookup in SpiceDB, which stores the identity bindings and governs document access for internal users only, persisting both to PostgreSQL so they survive a restart](/images/federated-architecture.png)
13+
14+
<Callout type="info">
15+
The full runnable demo for this tutorial lives in the [`authzed/examples`
16+
repository](https://github.com/authzed/examples/tree/main/federated-authorization). It wires up
17+
Keycloak, GitHub OAuth, SpiceDB, and PostgreSQL with Docker Compose, so you can run
18+
`docker-compose up --build` and follow along against a live stack.
19+
</Callout>
1320

1421
## Prerequisites
1522

@@ -18,7 +25,7 @@ Point them at an internal user you own, and bind each external account to it.
1825
- The [`zed` CLI](/spicedb/getting-started/installing-zed), pointed at your instance:
1926

2027
```sh
21-
zed context set tutorial localhost:50051 "your-preshared-key" --insecure
28+
zed context set tutorial localhost:50051 "demo-token-do-not-use-in-prod" --insecure
2229
```
2330

2431
- An app that already authenticates users and can read each token's stable id: the `sub` claim for OIDC providers like Keycloak, the numeric account id for GitHub.
@@ -244,6 +251,16 @@ for resp in client.LookupResources(LookupResourcesRequest(
244251
This uses SpiceDB's `LookupResources` API. Instead of asking "can this user view this document?", it answers "which documents can this user view?".
245252
That returns everything reachable through any path (owner, editor, or viewer) without those rules living in your app.
246253

254+
## A note on persistence
255+
256+
The demo backs SpiceDB with PostgreSQL (`--datastore-engine=postgres`), with a one-shot `datastore migrate head` that runs before SpiceDB starts.
257+
258+
The bindings are the federation, so they have to outlive a restart.
259+
If SpiceDB forgot `keycloak_account:9f3c #bound_to user:7b1e`, the next login would find nothing bound and mint a second `user:<uuid>` — the same failure the Step 2 warning guards against — and the first user's document grants would be stranded on the old id.
260+
Persisting to Postgres is what keeps a returning user mapped to the same internal user, and their access, across restarts.
261+
262+
The app keeps its own user profiles and document metadata in a local SQLite database, but SpiceDB stays the source of truth for identity bindings and authorization.
263+
247264
## A note on consistency
248265

249266
The demo reads default to `minimize_latency`, which is fast but can be a few seconds stale.
@@ -256,3 +273,5 @@ See [Consistency](/spicedb/concepts/consistency) for the details.
256273

257274
This pattern is provider-agnostic: add a third IdP by adding one more `*_account` type, and nothing downstream changes.
258275
To run this in production instead of a local container, provision a managed instance on [AuthZed Cloud](https://authzed.com/cloud/signup).
276+
277+
The [`authzed/examples` repository](https://github.com/authzed/examples/tree/main/federated-authorization) has the complete demo — schema, app, and the Docker Compose stack. You could also add a third IdP or point it at your own documents.

‎lib/changed-pages.json‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
{
2-
"/authzed/guides/picking-a-product": {
3-
"status": "updated"
4-
},
5-
"/materialize/getting-started/overview": {
6-
"status": "updated"
7-
},
8-
"/spicedb/getting-started/faq": {
9-
"status": "updated"
10-
},
11-
"/spicedb/modeling/protecting-a-list-endpoint": {
2+
"/spicedb/tutorials/federated-authorization": {
123
"status": "updated"
134
}
145
}
50.4 KB
Loading

0 commit comments

Comments
 (0)