Add federated-authorization example - #48
Conversation
A self-contained demo of federated authentication with centralized fine-grained authorization in SpiceDB: users log in through different identity providers (Keycloak OIDC and GitHub OAuth), each external account binds to a canonical internal user, and a single SpiceDB instance enforces document access control across all of them. Signed-off-by: Sohan Maheshwar <1119120+sohanmaheshwar@users.noreply.github.com>
Signed-off-by: Sohan Maheshwar <1119120+sohanmaheshwar@users.noreply.github.com>
Add document-start marker and quote all string values to satisfy the repo's quoted-strings yamllint rule. Signed-off-by: Sohan Maheshwar <1119120+sohanmaheshwar@users.noreply.github.com>
The edit/share/unshare handlers interpolated the user-controlled doc_id path parameter straight into a redirect Location, which CodeQL flagged as URL redirection from a remote source. Document ids are always uuid.uuid4(), so normalize doc_id through uuid.UUID() at the top of each handler: invalid ids now return 404, and the redirect target can only contain hex digits and hyphens, so it cannot escape the /documents/ path. Signed-off-by: Sohan Maheshwar <1119120+sohanmaheshwar@users.noreply.github.com>
e4c2d14 to
1d43f54
Compare
SpiceDB's REST gateway listens on :8443 inside the container, but the port was mapped from host 8090 to container 8080, so the documented http://localhost:8090 endpoint was unreachable (connection refused). Map 8090:8443 so the REST API is actually exposed. Signed-off-by: Sohan Maheshwar <1119120+sohanmaheshwar@users.noreply.github.com>
Signed-off-by: Sohan Maheshwar <1119120+sohanmaheshwar@users.noreply.github.com>
Replace the diagram with the corrected version (identity bindings shown stored in SpiceDB, resolved via a LookupSubjects bound_to call) and update the image alt text to match.
…on README The image diagram (architecture.png) is the source of truth; the ASCII version still showed the old framing (bound_to binding inside the app rather than in SpiceDB).
| <strong>{{ user.display_name }}</strong> | ||
| <small>{{ user.email }}</small> | ||
| </span> | ||
| <a href="/auth/logout" class="btn btn-sm btn-outline">Logout</a> |
There was a problem hiding this comment.
this button doesn't work - it takes me back to the login page which is great but it doesn't really log me out
|
I was testing this sample and stumbled upon a bug which I think could use some discussion. Basically there is a duplication of users if you restart the container, this is because in-memory SpiceDB loses IdP bindings on restart while SQLite persists → duplicate rows. (this also shows up when a user can share a document with themself). To fix this, claude recommends: I think for a sample app Option 1 is better. Would this resemble a production-ish pattern? AppDB owns identity mapping and SpiceDB does only authZ. I think @tstirrat15 's comment on the docs was something to this effect. imo, the postgres option is overkill for a demo. |
|
What's wrong with postgres?
It would still be self-contained and zero-setup. You can have a docker-compose that does all of that for you. We have one that you can use, I use it all the time :) https://github.com/authzed/spicedb/blob/main/docker-compose.postgres.yaml |
What
Adds a new
federated-authorizationexample: a self-contained demo of federated authentication with centralized fine-grained authorization in SpiceDB.Users log in through different identity providers (Keycloak OIDC and GitHub OAuth). Each external account (
keycloak_account,github_account) binds to a canonical internaluser, and a single SpiceDB instance enforcesdocumentaccess control across all of them — so users from different IdPs can share resources with each other.Contents
app.py) with Keycloak + GitHub login flowsspicedb/schema.zed) with the*_account → bound_to → userbinding patterndocker-compose.ymlbringing up SpiceDB, Keycloak, and the appEverything runs locally via
docker compose. Secrets are demo placeholders only; no real credentials are included.Notes
spicedb/tutorials/federated-authorization.