-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize the documentation and add some missing sections
- Loading branch information
1 parent
74d5498
commit 51bb149
Showing
11 changed files
with
2,620 additions
and
855 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Installing SpiceDB | ||
|
||
:::info | ||
Want to use SpiceDB as a service without any installation? Visit the [Authzed Dashboard] to create a new permissions system | ||
::: | ||
|
||
[Authzed Dashboard]: https://app.authzed.com | ||
|
||
## Running SpiceDB in local mode | ||
|
||
To run [SpiceDB] for local testing, either Docker or brew can be used: | ||
|
||
[SpiceDB]: https://github.com/authzed/spicedb | ||
|
||
:::warning | ||
Running SpiceDB in this way is only to be used for local testing, as TLS is disabled and the data stored will disappear when SpiceDB is shut down. | ||
::: | ||
|
||
### Running via Docker | ||
|
||
```sh | ||
docker pull quay.io/authzed/spicedb | ||
``` | ||
|
||
```sh | ||
docker run --name spicedb -d -p 50051:50051 quay.io/authzed/spicedb serve --grpc-preshared-key "somerandomkeyhere" | ||
``` | ||
|
||
### Running via brew | ||
|
||
```sh | ||
brew install spicedb | ||
``` | ||
|
||
```sh | ||
spicedb serve --grpc-preshared-key "somerandomkeyhere" | ||
``` | ||
|
||
## Verifying that SpiceDB is running | ||
|
||
The [zed] tool can be used to check that SpiceDB is running, write schema and relationships, and perform other operations against SpiceDB: | ||
|
||
[zed]: https://github.com/authzed/zed | ||
|
||
### Running via brew | ||
|
||
```sh | ||
brew install zed | ||
``` | ||
|
||
```sh | ||
zed context set local localhost:50051 "somerandomkeyhere" --insecure | ||
zed schema read --insecure | ||
``` | ||
|
||
## Next Steps | ||
|
||
Continue with the [Protecting Your First App] guide to learn how to use SpiceDB to protect your application | ||
|
||
[Protecting Your First App]: /guides/first-app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Using REST API | ||
|
||
:::note | ||
Want more information about the REST API and how to use it? Read our [blog post about the REST API] | ||
::: | ||
|
||
[blog post about the REST API]: https://authzed.com/blog/authzed-http-api/ | ||
|
||
The standard means of calling the [SpiceDB API] is via **gRPC**. | ||
|
||
For environments where gRPC is not available, SpiceDB provides a REST gateway that exposes a REST API for making calls. | ||
|
||
[SpiceDB API]: https://buf.build/authzed/api/docs/main/authzed.api.v1 | ||
|
||
## Running SpiceDB with the REST API | ||
|
||
To enable the REST API gateway on SpiceDB, add the flag `--http-enabled` to the SpiceDB arguments: | ||
|
||
```sh | ||
spicedb serve --grpc-preshared-key "secrettoken" --http-enabled | ||
``` | ||
|
||
This will serve the REST API on port `8443` by default. | ||
|
||
## API Reference | ||
|
||
See the [REST API Reference]. | ||
|
||
[REST API Reference]: /rest-api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Writing Relationships | ||
|
||
:::note | ||
Want to learn more about writing relationships to SpiceDB, the various strategies and their pros and cons? Read our [blog post about writing relationships] | ||
::: | ||
|
||
[blog post about writing relationships]: https://authzed.com/blog/writing-relationships-to-spicedb/ | ||
|
||
In [SpiceDB], a permissions system is defined by two items: the [schema] which defines *how* data can be represented, and the *relationships*, defining the way the objects are actually related to one another. | ||
|
||
[schema]: /guides/schema | ||
[SpiceDB]: https://github.com/authzed/spicedb | ||
|
||
It is the application's responsibility to keep the relationships within SpiceDB up-to-date and reflecting the state of the application; how an application does so can vary based on the specifics of the application, so below we outline a few approaches. | ||
|
||
## Two writes + commit | ||
|
||
The most common and straightforward way to store relationships in SpiceDB is to use a 2 phase commit-like approach, making use of a transaction from the relational database along with a [WriteRelationships] call to SpiceDB. | ||
|
||
[WriteRelationships]: https://buf.build/authzed/api/docs/main/authzed.api.v1#WriteRelationships | ||
|
||
```python title='Example of a 2PC-like approach' | ||
# Open the database transaction | ||
try: | ||
with db.transaction() as transaction: | ||
# Update the relationship in the database. | ||
document = Document( | ||
id="somedoc", | ||
owner=some_user, | ||
) | ||
transaction.add(document) | ||
|
||
# Add the relationship(s) in SpiceDB. | ||
resp = client.WriteRelationships(...) | ||
|
||
# Store the ZedToken we've received. | ||
document.zedtoken = result.written_at | ||
|
||
# Transaction is committed on close | ||
except: | ||
# Delete the relationship(s) just written | ||
client.DeleteRelationships(...) | ||
raise | ||
``` | ||
|
||
## Streaming commits | ||
|
||
Another approach is to stream updates to both a relational database and SpiceDB via a third party streaming system such as [Kafka], using a pattern known as [Command Query Responsibility Segregation] (CQRS) | ||
|
||
[Kafka]: https://kafka.apache.org/ | ||
[Command Query Responsibility Segregation]: https://www.confluent.io/blog/event-sourcing-cqrs-stream-processing-apache-kafka-whats-connection/ | ||
|
||
In this design, any updates to the relationships in both databases are published as **events** to the streaming service, with each event being consumed by a system which performs the updates in both the database and in SpiceDB. | ||
|
||
## SpiceDB-only relationships | ||
|
||
Sometimes, an application does not even need to store permissions-related relationships in its relational database. | ||
|
||
Consider a permissions system that allows for teams of users to be created and used to access a resource. | ||
In SpiceDB's schema, this could be represented as: | ||
|
||
```haskell | ||
definition user {} | ||
|
||
definition team { | ||
relation member: user | ||
} | ||
|
||
definition resource { | ||
relation reader: user | team#member | ||
permission view = reader | ||
} | ||
``` | ||
|
||
In the above example, the relationship between a resource and its teams, as well as a team and its members does not need to be stored in the application's database **at all**. | ||
|
||
Rather, this information can be stored solely in SpiceDB, and accessed by the application via a [ReadRelationships] or [ExpandPermissionsTree] call when necessary. | ||
|
||
[ReadRelationships]: https://buf.build/authzed/api/docs/main/authzed.api.v1#ReadRelationships | ||
[ExpandPermissionsTree]: https://buf.build/authzed/api/docs/main/authzed.api.v1#ExpandPermissionTree | ||
|
||
## Asynchronous Updates | ||
|
||
**NOTE:** This should *only* be used if your application supports less rigid consistency guarantees. | ||
|
||
If an application does not require up-to-the-second consistent permissions checking, and some replication lag in permissions checking is acceptable, then asynchronous updates of the relationships in SpiceDB can be used. | ||
|
||
In this design, a synchronization process, typically running in the background, is used to write relationships to SpiceDB in reaction to any changes that occur in the primary relational database. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.