Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat: initial implementation of the LookupWatch API #255

Closed
wants to merge 116 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
4ad9ff8
cmd: consistent flags for http/grpc servers
jzelinskie Nov 3, 2021
9bc9ea1
feat: initial implementation of the LookupWatch API
jon-whit Nov 3, 2021
7885d4a
use the grpc_health_probe binary from the official images
ecordell Nov 3, 2021
14184b9
Merge pull request #257 from ecordell/grpc-health-probe-img
jakedt Nov 3, 2021
4651842
cmd: rename internal dispatch to cluster dispatch
jzelinskie Nov 3, 2021
49a9a05
cmd: remove no-tls, rename tls, dispatch flags
jzelinskie Nov 3, 2021
d0a3f5c
README: remove --no-tls flags from read and k8s
jzelinskie Nov 3, 2021
0ea5f20
gomod: bump to cobrautil v0.0.6
jzelinskie Nov 4, 2021
b8694a8
Merge pull request #254 from jzelinskie/bump-cobrautil
jzelinskie Nov 4, 2021
8baf841
Add github container registry as release target
samkim Nov 4, 2021
8334b55
support https in download API
ecordell Nov 5, 2021
3fc8076
use buffered channels for lookup results
ecordell Nov 4, 2021
964b7a7
Merge pull request #259 from ecordell/fix-lookup-goroutine-leak
ecordell Nov 5, 2021
cc8b142
Remove duplicate image templates
samkim Nov 5, 2021
c5d6461
Merge pull request #243 from ecordell/https-download
ecordell Nov 5, 2021
3b3c9c6
Merge pull request #260 from samkim/ghcr-release
samkim Nov 5, 2021
072c285
cmd/serve: revert dispatch-cluster flags changes
jzelinskie Nov 5, 2021
b203981
Merge pull request #262 from jzelinskie/fix-dispatch-flags
jzelinskie Nov 5, 2021
3abfbba
support UDS listening on grpc servers
ecordell Nov 9, 2021
70023bf
Merge pull request #267 from ecordell/uds
ecordell Nov 9, 2021
dc7f7a0
Add a middleware to generate and propagate requestIDs.
jakedt Nov 9, 2021
9c3c69e
add middleware to copy metadata from context to logger
jakedt Nov 9, 2021
4ee60e1
use logger from context
jakedt Nov 9, 2021
aca9e71
Add docker login action for ghcr
samkim Nov 9, 2021
026c978
Merge pull request #272 from authzed/x-request-id
jakedt Nov 10, 2021
559d0c4
.github: pin gofumports version
jzelinskie Nov 10, 2021
dba3d6f
Merge pull request #276 from jzelinskie/fix-gofumpt
jzelinskie Nov 10, 2021
e690053
.github: add 5m timeout to golangci-lint
jzelinskie Nov 10, 2021
797a464
.github: bump golangci-lint version
jzelinskie Nov 10, 2021
a212b2c
Merge pull request #277 from jzelinskie/golangci-timeout
jzelinskie Nov 10, 2021
77de42c
prevent duplicate tuple creation in memdb datastore
jakedt Nov 10, 2021
7bd1445
add a String implementation for memdb tuple entries
jakedt Nov 10, 2021
9a5da89
have crdb raise an error on duplicate tuple create
jakedt Nov 10, 2021
5a315b0
.github: move golangci timeout into config
jzelinskie Nov 10, 2021
edd7ddf
feat: add v1 Watch API implementation
jonwhitty Nov 10, 2021
e46698d
Merge pull request #275 from authzed/memdb-duplicates
jakedt Nov 10, 2021
138ce62
services/v1: fix intersection tree conversion
jzelinskie Nov 11, 2021
b27b5b1
Merge pull request #281 from jzelinskie/fix-intersection
jzelinskie Nov 11, 2021
bf3718e
Use token for package write permission
samkim Nov 12, 2021
e5ebe46
Merge pull request #274 from samkim/ghcr-login
jzelinskie Nov 12, 2021
668d115
Have consistency tests run Expand on all permissions
josephschorr Nov 12, 2021
8550273
Add cross version API consistency tests
josephschorr Nov 12, 2021
ed9385a
Add log warning to emphasize persistence/scale issues in memdb
buraksekili Nov 12, 2021
2610d94
use consistent-hash load balancer with kubernetes endpoint resolver for
ecordell Nov 12, 2021
d6dec12
Merge pull request #278 from jzelinskie/golangci-no-gc
jzelinskie Nov 13, 2021
031b6ca
remove dot at the end of the log
buraksekili Nov 13, 2021
e228ba9
.github: add more automatic labeling patterns
jzelinskie Nov 14, 2021
3498f6f
README: fix flags, links, and project description
jzelinskie Nov 9, 2021
009dd46
rm -rf servok
ecordell Nov 12, 2021
c155d1a
hashring: use uint16 for replication factor
ecordell Nov 12, 2021
256911b
separate flag for optional dispatch cluster CA config
ecordell Nov 15, 2021
2fa4b08
share key func between cache and consistent hash
ecordell Nov 15, 2021
6779f26
Merge pull request #284 from ecordell/consistent-lb
ecordell Nov 15, 2021
d91b529
Merge pull request #283 from josephschorr/additional-expansion-testing
jzelinskie Nov 15, 2021
48475da
Merge pull request #285 from buraksekili/add-warning-log-for-memdb
jzelinskie Nov 15, 2021
021896f
Merge pull request #287 from jzelinskie/more-labels
jzelinskie Nov 15, 2021
97be5dd
Merge pull request #273 from jzelinskie/readme-new-flags
jzelinskie Nov 15, 2021
414835d
enable caching on local subproblems
jakedt Nov 8, 2021
3c90d25
Merge pull request #263 from jonwhitty/feat/v1-watchapi
josephschorr Nov 15, 2021
40ee18b
Add tracking of excluded relations in Lookup and only cache if no rel…
josephschorr Nov 9, 2021
974cf96
Add revision support to v1alpha1 schema API
josephschorr Nov 9, 2021
28e2f5a
Merge pull request #268 from josephschorr/multi-level-caching
josephschorr Nov 16, 2021
55bc286
Move buf to 1.0.0-rc8
josephschorr Nov 16, 2021
a75cd64
Merge pull request #271 from josephschorr/schema-revision
josephschorr Nov 16, 2021
7251d77
Add proper dispatch and cached dispatch tracking
josephschorr Nov 16, 2021
6600338
Merge pull request #289 from josephschorr/cached-dispatch-count
jakedt Nov 23, 2021
face486
properly calculate virtualnode ids for uint16 replicationFactor
ecordell Nov 23, 2021
b0370b6
Merge pull request #294 from ecordell/16bitreplication
jakedt Nov 23, 2021
f163c91
Add follower read delay option
samkim Nov 23, 2021
7bdf54e
Add follower read documentation
samkim Nov 29, 2021
f21988b
Use the same default follower read delay as crdb
samkim Nov 30, 2021
d1a31c1
Merge pull request #297 from samkim/follower-reads
samkim Nov 30, 2021
0ca0a44
Add dispatch and cached dispatch counts to response trailer metadata
josephschorr Nov 23, 2021
13f0b61
Merge pull request #295 from josephschorr/responsemeta
josephschorr Nov 30, 2021
eb4a5d4
Bump golang from 1.17.2-alpine3.13 to 1.17.3-alpine3.13
dependabot[bot] Dec 1, 2021
bc4ab1f
Bump go.opentelemetry.io/otel/trace from 1.1.0 to 1.2.0
dependabot[bot] Dec 1, 2021
64b1d23
Bump github.com/aws/aws-sdk-go from 1.41.15 to 1.42.16
dependabot[bot] Dec 1, 2021
0ff5b0f
Bump github.com/jackc/pgtype from 1.8.1 to 1.9.1
dependabot[bot] Dec 1, 2021
a7a84ac
Bump github.com/grpc-ecosystem/grpc-gateway/v2 from 2.6.0 to 2.7.0
dependabot[bot] Dec 1, 2021
c804120
Bump github.com/Masterminds/squirrel from 1.5.1 to 1.5.2
dependabot[bot] Dec 1, 2021
6bff060
Merge pull request #300 from authzed/dependabot/docker/golang-1.17.3-…
josephschorr Dec 1, 2021
b3b07b6
Merge pull request #306 from authzed/dependabot/go_modules/github.com…
josephschorr Dec 1, 2021
6ed02ba
Bump alpine from 3.14.2 to 3.15.0
dependabot[bot] Dec 1, 2021
b5b0c3f
Merge pull request #305 from authzed/dependabot/go_modules/github.com…
josephschorr Dec 1, 2021
dc1ae8c
Merge pull request #301 from authzed/dependabot/docker/alpine-3.15.0
josephschorr Dec 1, 2021
ff19a70
Merge pull request #303 from authzed/dependabot/go_modules/github.com…
josephschorr Dec 1, 2021
b3551ee
Bump github.com/lib/pq from 1.10.3 to 1.10.4
dependabot[bot] Dec 1, 2021
fd7bddb
Merge pull request #304 from authzed/dependabot/go_modules/github.com…
josephschorr Dec 1, 2021
8b8a27d
Merge pull request #308 from authzed/dependabot/go_modules/github.com…
josephschorr Dec 1, 2021
0f3fbb6
Merge pull request #302 from authzed/dependabot/go_modules/go.opentel…
josephschorr Dec 1, 2021
380c9c8
Bump github.com/jackc/pgx/v4 from 4.13.0 to 4.14.1
dependabot[bot] Dec 1, 2021
d4a511c
Merge pull request #309 from authzed/dependabot/go_modules/github.com…
josephschorr Dec 1, 2021
37b0137
Bump go.opentelemetry.io/contrib/instrumentation/google.golang.org/gr…
dependabot[bot] Dec 1, 2021
21c7d8c
Bump github.com/benbjohnson/clock from 1.2.0 to 1.3.0
dependabot[bot] Dec 1, 2021
1c465e1
Merge pull request #314 from authzed/dependabot/go_modules/github.com…
josephschorr Dec 1, 2021
4c655c3
Merge pull request #313 from authzed/dependabot/go_modules/go.opentel…
josephschorr Dec 1, 2021
a083502
Bump github.com/ory/dockertest/v3 from 3.8.0 to 3.8.1
dependabot[bot] Dec 1, 2021
f5f8193
Bump go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp
dependabot[bot] Dec 1, 2021
f5a6911
Merge pull request #307 from authzed/dependabot/go_modules/github.com…
josephschorr Dec 1, 2021
d31071b
Merge pull request #310 from authzed/dependabot/go_modules/go.opentel…
josephschorr Dec 1, 2021
d1d0f62
goreleaser: fix tag in docker release notes
jzelinskie Dec 2, 2021
d82bb4e
Merge pull request #316 from jzelinskie/fix-releaser-docker-notes
jzelinskie Dec 2, 2021
fb38a88
pin an old watchmaker
ecordell Dec 6, 2021
cdd4c7f
Merge pull request #322 from ecordell/fix-e2e
ecordell Dec 6, 2021
a75c641
internal/dispatch: extract combined dispatcher
jzelinskie Dec 5, 2021
1015f37
Merge pull request #321 from jzelinskie/dispatch-pull
jzelinskie Dec 6, 2021
f13ae90
extract out change tracking across revisions from postgres
jakedt Dec 3, 2021
3e33ff9
test that namespaces are removed from list when deleted
jakedt Dec 3, 2021
a1cef57
fix v1 watch test to not delete non-existent relationship
jakedt Dec 3, 2021
d6dadff
change memdb datastore to use a single transaction log for namespaces…
jakedt Dec 3, 2021
9673916
use canonical terms for memdb datastore
jakedt Dec 6, 2021
44523b6
Merge pull request #319 from authzed/memdb-mvcc
jakedt Dec 6, 2021
23a8287
feat: initial implementation of the LookupWatch API
jon-whit Nov 3, 2021
2f2f240
chore: rework lookupwatch server cmd entrypoint
jon-whit Dec 7, 2021
cd80f52
Merge branch 'lookup-watch-api' of https://github.com/jon-whit/spiced…
jon-whit Dec 7, 2021
b60b8e4
chore: fix unmerged paths
jon-whit Dec 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
---
area/dependencies:
"area/api devtools":
- "cmd/spicedb/developer.go"
"area/api http":
- "internal/gateway/**/*"
"area/api v0":
- "internal/services/v0/**/*"
"area/api v1":
- "internal/services/v1/**/*"
- "internal/services/v1alpha1/**/*"
"area/cli":
- "cmd/**/*"
"area/dashboard":
- "internal/dashboard/**/*"
"area/datastore":
- "internal/datastore/**/*"
"area/dependencies":
- "Dockerfile"
- "go.mod"
- "go.sum"
area/tooling:
- "**/*_test.go"
- ".github/**/*"
- ".*"
- "Dockerfile*"
area/docs:
"area/dispatch":
- "internal/dispatch/**/*"
"area/docs":
- "CODE-OF-CONDUCT.md"
- "CONTRIBUTING.md"
- "DCO"
- "LICENSE"
- "README.md"
"area/api v0":
- "internal/services/v0/**/*"
"area/api v1":
- "internal/services/v1/**/*"
- "internal/services/v1alpha1/**/*"
"area/datastore":
- "internal/datastore/**/*"
"area/schema":
- "pkg/schemadsl/**/*"
"area/tooling":
- "**/*_test.go"
- ".github/**/*"
- ".*"
- "Dockerfile*"
5 changes: 3 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
# chaosd doesn't yet include time modification, install it separately
git clone https://github.com/chaos-mesh/chaos-mesh/
pushd chaos-mesh
git reset --hard 72d2bc17febc7f2a4a10c97417f11c5eb1d86a13
CGO_ENABLED=1 go build ./cmd/watchmaker/
popd
mv ./chaos-mesh/watchmaker ./watchmaker
Expand Down Expand Up @@ -115,9 +116,9 @@ jobs:
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1
go install github.com/envoyproxy/protoc-gen-validate@v0.6.1
- uses: "bufbuild/buf-setup-action@v0.3.1"
- uses: "bufbuild/buf-setup-action@v0.6.0"
with:
version: "0.52.0"
version: "1.0.0-rc8"
- name: "Generate & Diff Protos"
run: "./buf.gen.yaml && git diff && bash -c '[ $(git status --porcelain | tee /dev/fd/2 | wc -c) -eq 0 ]'"
- uses: "bufbuild/buf-breaking-action@v0.4.0"
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ jobs:
- name: "Install linting tools"
run: |
# This is done before checking out, as to not modify go.mod
go install mvdan.cc/gofumpt/gofumports@latest
go install github.com/mgechev/revive@latest
go install mvdan.cc/gofumpt/gofumports@v0.1.1
go install golang.org/x/tools/cmd/stringer@latest
- uses: "actions/checkout@v2"
- name: "Go Mod Tidy"
Expand All @@ -34,7 +33,7 @@ jobs:
fi
- uses: "golangci/golangci-lint-action@v2"
with:
version: "v1.42"
version: "v1.43"
skip-go-installation: true
skip-pkg-cache: true
skip-build-cache: false
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
registry: "quay.io"
username: "${{ secrets.QUAYIO_USER }}"
password: "${{ secrets.QUAYIO_PASSWORD }}"
- uses: "docker/login-action@v1"
with:
registry: "ghcr.io"
username: "${{ github.actor }}"
password: "${{ secrets.GHCR_TOKEN }}"
- uses: "actions/setup-go@v2"
with:
go-version: "^1.17"
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
run:
timeout: "5m"
output:
sort-results: true
linters-settings:
Expand Down
12 changes: 11 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ brews:
dockers:
- image_templates:
- &amd_image "quay.io/authzed/spicedb:v{{ .Version }}-amd64"
- &amd_image_gh "ghcr.io/authzed/spicedb:v{{ .Version }}-amd64"
dockerfile: &dockerfile "Dockerfile.release"
goos: "linux"
goarch: "amd64"
Expand All @@ -66,6 +67,7 @@ dockers:
- "--platform=linux/amd64"
- image_templates:
- &arm_image "quay.io/authzed/spicedb:v{{ .Version }}-arm64"
- &arm_image_gh "ghcr.io/authzed/spicedb:v{{ .Version }}-arm64"
dockerfile: *dockerfile
goos: "linux"
goarch: "arm64"
Expand All @@ -81,6 +83,14 @@ docker_manifests:
image_templates:
- *amd_image
- *arm_image
- name_template: "ghcr.io/authzed/spicedb:v{{ .Version }}"
image_templates:
- *amd_image_gh
- *arm_image_gh
- name_template: "ghcr.io/authzed/spicedb:latest"
image_templates:
- *amd_image_gh
- *arm_image_gh
checksum:
name_template: "checksums.txt"
snapshot:
Expand All @@ -92,4 +102,4 @@ release:
prerelease: "auto"
footer: |
## Docker Images
This release is available at `quay.io/authzed/spicedb:{{ .Version }}`
This release is available at `quay.io/authzed/spicedb:v{{ .Version }}` and `ghcr.io/authzed/spicedb:v{{ .Version }}`
12 changes: 3 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
FROM golang:1.17.2-alpine3.13 AS spicedb-builder

ARG GRPC_HEALTH_PROBE_VERSION=0.3.6
RUN apk add curl
RUN curl -Lo /go/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64
RUN chmod +x /go/bin/grpc_health_probe

FROM golang:1.17.3-alpine3.13 AS spicedb-builder
WORKDIR /go/src/app

# Prepare dependencies
Expand All @@ -14,9 +8,9 @@ RUN go mod download
COPY . .
RUN go build ./cmd/spicedb/

FROM alpine:3.14.2
FROM alpine:3.15.0

RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
COPY --from=spicedb-builder /go/bin/grpc_health_probe /usr/local/bin/
COPY --from=ghcr.io/grpc-ecosystem/grpc-health-probe:v0.4.6 /ko-app/grpc-health-probe /usr/local/bin/grpc_health_probe
COPY --from=spicedb-builder /go/src/app/spicedb /usr/local/bin/spicedb
ENTRYPOINT ["spicedb"]
11 changes: 1 addition & 10 deletions Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# vim: syntax=dockerfile
FROM alpine AS grpc
ARG TARGETARCH
ARG GRPC_HEALTH_PROBE_VERSION=0.3.6
RUN apk update && \
apk add curl && \
curl -Lo /grpc_health_probe \
https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v$GRPC_HEALTH_PROBE_VERSION/grpc_health_probe-linux-$TARGETARCH && \
chmod +x /grpc_health_probe

FROM gcr.io/distroless/base
COPY --from=grpc /grpc_health_probe /usr/local/bin/grpc_health_probe
COPY --from=ghcr.io/grpc-ecosystem/grpc-health-probe:v0.4.6 /ko-app/grpc-health-probe /usr/local/bin/grpc_health_probe
COPY spicedb /usr/local/bin/spicedb
ENTRYPOINT ["spicedb"]
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
[![Discord Server](https://img.shields.io/discord/844600078504951838?color=7289da&logo=discord "Discord Server")](https://discord.gg/jTysUaxXzM)
[![Twitter](https://img.shields.io/twitter/follow/authzed?color=%23179CF0&logo=twitter&style=flat-square "@authzed on Twitter")](https://twitter.com/authzed)

SpiceDB is a [Zanzibar]-inspired database that stores, computes, and validates application permissions.
SpiceDB is a database system for managing security-critical application permissions.

Developers create a schema that models their permissions requirements and use a [client library] to apply the schema to the database, insert data into the database, and query the data to efficiently check permissions in their applications.

Features that distinguish SpiceDB from other systems include:

- Expressive [gRPC] and [HTTP] APIs for checking permissions, listing access, and powering devtools
- An architecture faithful to the [Google Zanzibar] paper, including resistance to the [New Enemy Problem]
- An architecture faithful to [Google's Zanzibar paper], including resistance to the [New Enemy Problem]
- An intuitive and expressive [schema language] complete with a [playground] dev environment
- A powerful graph engine that supports distributed, parallel evaluation
- Pluggable storage that supports [in-memory], [PostgreSQL], and [CockroachDB]
Expand All @@ -25,8 +25,7 @@ See [CONTRIBUTING.md] for instructions on how to contribute and perform common t
[client library]: https://docs.authzed.com/reference/api#client-libraries
[gRPC]: https://buf.build/authzed/api
[HTTP]: https://petstore.swagger.io/?url=https://raw.githubusercontent.com/authzed/authzed-go/main/proto/apidocs.swagger.json
[Zanzibar]: https://authzed.com/blog/what-is-zanzibar/
[Google Zanzibar]: https://authzed.com/blog/what-is-zanzibar/
[Google's Zanzibar paper]: https://authzed.com/blog/what-is-zanzibar/
[New Enemy Problem]: https://authzed.com/blog/new-enemies/
[schema language]: https://docs.authzed.com/guides/schema
[playground]: https://play.authzed.com
Expand Down Expand Up @@ -81,14 +80,14 @@ SpiceDB is also available as a container image:

```sh
docker pull quay.io/authzed/spicedb:latest
docker run quay.io/authzed/spicedb serve --grpc-preshared-key "somerandomkeyhere" --grpc-no-tls --http-no-tls
docker run quay.io/authzed/spicedb serve --grpc-preshared-key "somerandomkeyhere"
```

SpiceDB supports environment variables. You can replace any command's argument with an environment variable by adding the `SPICEDB` prefix.
For example `--log-level` becomes `SPICEDB_LOG_LEVEL`.

```sh
docker run -e SPICEDB_GRPC_PRESHARED_KEY=somerandomkeyhere -e SPICEDB_GRPC_NO_TLS=1 -e SPICEDB_HTTP_NO_TLS=1 quay.io/authzed/spicedb serve
docker run -e SPICEDB_GRPC_PRESHARED_KEY=somerandomkeyhere quay.io/authzed/spicedb serve
```

For production usage, we **highly** recommend using a tag that corresponds to the [latest release], rather than `latest`.
Expand All @@ -98,7 +97,7 @@ For production usage, we **highly** recommend using a tag that corresponds to th
### Running SpiceDB locally

```sh
spicedb serve --grpc-preshared-key "somerandomkeyhere" --grpc-no-tls --http-no-tls
spicedb serve --grpc-preshared-key "somerandomkeyhere"
```

Visit [http://localhost:8080](http://localhost:8080) to see next steps, including loading the schema
Expand All @@ -114,7 +113,7 @@ By using unique tokens in each of your application's integration tests, they can

A [SpiceDB GitHub action] is also available to run SpiceDB as part of your integration test workflows.

[Bearer Token]: https://docs.authzed.com/concepts/terminology/#api-token
[Bearer Token]: https://docs.authzed.com/reference/api#authentication
[SpiceDB GitHub action]: https://github.com/authzed/action-spicedb

### Developing your own schema
Expand Down
2 changes: 1 addition & 1 deletion buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S ./proto/buf-generate.sh
#!/usr/bin/env -S buf generate -o internal/proto proto/internal --template
---
version: "v1"
managed:
Expand Down
50 changes: 22 additions & 28 deletions cmd/spicedb/developer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"errors"
"fmt"
"net"
"net/http"
"os"
"os/signal"

Expand All @@ -18,6 +16,7 @@ import (
grpcprom "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/jzelinskie/cobrautil"
"github.com/jzelinskie/stringz"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
Expand All @@ -30,15 +29,17 @@ import (

func registerDeveloperServiceCmd(rootCmd *cobra.Command) {
developerServiceCmd := &cobra.Command{
Use: "serve-devtools",
Short: "runs the developer tools service",
Long: "Serves the authzed.api.v0.DeveloperService which is used for development tooling such as the Authzed Playground",
Run: developerServiceRun,
Args: cobra.ExactArgs(0),
Use: "serve-devtools",
Short: "runs the developer tools service",
Long: "Serves the authzed.api.v0.DeveloperService which is used for development tooling such as the Authzed Playground",
PreRunE: defaultPreRunE,
Run: developerServiceRun,
Args: cobra.ExactArgs(0),
}

cobrautil.RegisterGrpcServerFlags(developerServiceCmd.Flags())
cobrautil.RegisterMetricsServerFlags(developerServiceCmd.Flags())
cobrautil.RegisterGrpcServerFlags(developerServiceCmd.Flags(), "grpc", "gRPC", ":50051", true)
cobrautil.RegisterHttpServerFlags(developerServiceCmd.Flags(), "metrics", "metrics", ":9090", true)
cobrautil.RegisterHttpServerFlags(developerServiceCmd.Flags(), "http", "download", ":8443", false)

developerServiceCmd.Flags().String("share-store", "inmemory", "kind of share store to use")
developerServiceCmd.Flags().String("share-store-salt", "", "salt for share store hashing")
Expand All @@ -47,13 +48,12 @@ func registerDeveloperServiceCmd(rootCmd *cobra.Command) {
developerServiceCmd.Flags().String("s3-bucket", "", "s3 bucket name for s3 share store")
developerServiceCmd.Flags().String("s3-endpoint", "", "s3 endpoint for s3 share store")
developerServiceCmd.Flags().String("s3-region", "auto", "s3 region for s3 share store")
developerServiceCmd.Flags().String("download-addr", ":8443", "address to listen for download requests")

rootCmd.AddCommand(developerServiceCmd)
}

func developerServiceRun(cmd *cobra.Command, args []string) {
grpcServer, err := cobrautil.GrpcServerFromFlags(cmd, grpc.ChainUnaryInterceptor(
grpcServer, err := cobrautil.GrpcServerFromFlags(cmd, "grpc", grpc.ChainUnaryInterceptor(
grpclog.UnaryServerInterceptor(grpczerolog.InterceptorLogger(log.Logger)),
otelgrpc.UnaryServerInterceptor(),
grpcprom.UnaryServerInterceptor,
Expand All @@ -70,39 +70,33 @@ func developerServiceRun(cmd *cobra.Command, args []string) {
registerDeveloperGrpcServices(grpcServer, shareStore)

go func() {
addr := cobrautil.MustGetStringExpanded(cmd, "grpc-addr")
l, err := net.Listen("tcp", addr)
if err != nil {
log.Fatal().Str("addr", addr).Msg("failed to listen on addr for gRPC server")
}

log.Info().Str("addr", addr).Msg("gRPC server started listening")
if err := grpcServer.Serve(l); err != nil {
if err := cobrautil.GrpcListenFromFlags(cmd, "grpc", grpcServer, zerolog.InfoLevel); err != nil {
log.Warn().Err(err).Msg("gRPC service did not shutdown cleanly")
}
}()

metricsrv := cobrautil.MetricsServerFromFlags(cmd)
// Start the metrics endpoint.
metricsSrv := cobrautil.HttpServerFromFlags(cmd, "metrics")
metricsSrv.Handler = metricsHandler()
go func() {
log.Info().Str("addr", metricsrv.Addr).Msg("metrics server started listening")
if err := metricsrv.ListenAndServe(); err != http.ErrServerClosed {
if err := cobrautil.HttpListenFromFlags(cmd, "metrics", metricsSrv, zerolog.InfoLevel); err != nil {
log.Fatal().Err(err).Msg("failed while serving metrics")
}
}()

downloadSrv := v0svc.NewHTTPDownloadServer(cobrautil.MustGetString(cmd, "download-addr"), shareStore)
// start the http download api
downloadSrv := cobrautil.HttpServerFromFlags(cmd, "http")
downloadSrv.Handler = v0svc.NewHTTPDownloadServer(cobrautil.MustGetString(cmd, "http-addr"), shareStore).Handler
go func() {
log.Info().Str("addr", downloadSrv.Addr).Msg("download server started listening")
if err := downloadSrv.ListenAndServe(); err != http.ErrServerClosed {
log.Fatal().Err(err).Msg("failed while serving http api")
if err := cobrautil.HttpListenFromFlags(cmd, "http", downloadSrv, zerolog.InfoLevel); err != nil {
log.Fatal().Err(err).Msg("failed while serving download http api")
}
}()

signalctx, _ := signal.NotifyContext(context.Background(), os.Interrupt)
<-signalctx.Done()
log.Info().Msg("received interrupt")
grpcServer.GracefulStop()
if err := metricsrv.Close(); err != nil {
if err := metricsSrv.Close(); err != nil {
log.Fatal().Err(err).Msg("failed while shutting down metrics server")
}
}
Expand Down
Loading