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

Support HTTP/JSON via gRPC Gateway #188

Merged
merged 14 commits into from Oct 25, 2021
Merged

Conversation

jzelinskie
Copy link
Member

@jzelinskie jzelinskie commented Oct 13, 2021

This change adds an additional port that the spicedb serve command uses to serve an HTTP/JSON API.
It uses gRPC Gateway to forward requests to the --grpc-addr. Each RPC is represented as an HTTP POST with the protobuf messages encoded in JSON in the body of the request.

Example usage:

$ spicedb serve --grpc-preshared-key "somerandomkeyhere" --grpc-no-tls --http-no-tls --log-level debug &
$ curl -X POST -H "Authorization: Bearer somerandomkeyhere" localhost:443/v1/schema/write -d @write_schema.json
$ curl -X POST -H "Authorization: Bearer somerandomkeyhere" localhost:443/v1/schema/read -v
$ curl -X POST -H "Authorization: Bearer somerandomkeyhere" localhost:443/v1/relationships/write -d @write_relationships.json
$ curl -H "Authorization: Bearer somerandomkeyhere" -X POST localhost:443/v1/permissions/check -d @check.json
$ kill %1

TODO:

  • Generate Gateway & OpenAPI in authzed-go
  • add spicedb serve --http-addr
  • Copy over authorization header to gRPC
  • Copy over OpenTelemetry header to gRPC
  • Serve OpenAPI schema endpoint
  • Record HTTP metrics via Prometheus
  • Support flags for configuring TLS
  • Cleanup go.mod

@jzelinskie jzelinskie added area/CLI Affects the command line priority/2 medium This needs to be done area/api v1 Affects the v1 API area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) area/observability Affects telemetry data labels Oct 13, 2021
@jzelinskie jzelinskie linked an issue Oct 13, 2021 that may be closed by this pull request
@github-actions github-actions bot added area/dependencies Affects dependencies and removed area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) area/api v1 Affects the v1 API labels Oct 13, 2021
@jzelinskie jzelinskie force-pushed the gateway branch 2 times, most recently from 749f5fc to 79dfd78 Compare October 14, 2021 22:19
@github-actions github-actions bot added the area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) label Oct 19, 2021
@@ -346,28 +360,60 @@ func serveRun(cmd *cobra.Command, args []string) {
}
}()

// Start the REST gateway to serve HTTP/JSON.
gatewaySrv, err := gateway.NewHttpServer(context.TODO(), gateway.Config{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should all be skippable; either if the http server endpoint is either empty or we add a new flag

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea is that we could run the dashboard, metrics, and HTTP API all on the same port.

go.mod Outdated
// TODO(jschorr): Remove once https://github.com/dgraph-io/ristretto/pull/286 is merged
replace github.com/dgraph-io/ristretto => github.com/josephschorr/ristretto v0.1.1-0.20211008180146-169a43af0a0d
replace (
github.com/authzed/authzed-go => ../authzed-go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this change needs to be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep this will remain a draft until the the following are merged:

internal/gateway/gateway.go Outdated Show resolved Hide resolved
// Addr is the address on which the HTTP server will be configured to listen.
Addr string

// UpstreamAddr is the address of the gRPC serve to which requests will be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server?

Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
gRPC Gateway performs this automatically.

Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
This drops a local rewrite that used in development.

Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Signed-off-by: Jimmy Zelinskie <jimmy@zelinskie.com>
Copy link
Contributor

@ecordell ecordell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jzelinskie jzelinskie merged commit 4e70dde into authzed:main Oct 25, 2021
@jzelinskie jzelinskie deleted the gateway branch October 25, 2021 15:23
@github-actions github-actions bot locked and limited conversation to collaborators Oct 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/CLI Affects the command line area/dependencies Affects dependencies area/observability Affects telemetry data area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) priority/2 medium This needs to be done
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for REST HTTP/1.1 to support more clients.
3 participants