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

Add support for multiple preshared keys #537

Merged
merged 3 commits into from
Apr 20, 2022

Conversation

josephschorr
Copy link
Member

@josephschorr josephschorr commented Apr 18, 2022

Fixes #288
Fixes AUTHZ-500

@josephschorr josephschorr requested a review from a team as a code owner April 18, 2022 22:15
@github-actions github-actions bot added area/CLI Affects the command line area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Apr 18, 2022
@@ -339,7 +352,7 @@ type completedServerConfig struct {

unaryMiddleware []grpc.UnaryServerInterceptor
streamingMiddleware []grpc.StreamServerInterceptor
presharedKey string
presharedKey []string
Copy link
Member

Choose a reason for hiding this comment

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

presharedKey => presharedKeys

@@ -103,7 +103,11 @@ func (c *Config) Complete() (RunnableServer, error) {
}

if c.GRPCAuthFunc == nil {
log.Trace().Int("preshared-key-length", len(c.PresharedKey)).Msg("using gRPC auth with preshared key")
log.Trace().Int("preshared-keys", len(c.PresharedKey)).Msg("using gRPC auth with preshared key(s)")
Copy link
Member

Choose a reason for hiding this comment

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

preshared-keys-count

@@ -141,10 +145,15 @@ func (c *Config) Complete() (RunnableServer, error) {
return nil, fmt.Errorf("failed to create dispatcher: %w", cerr)
}

presharedKey := ""
Copy link
Member

Choose a reason for hiding this comment

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

presharedKey => dispatchKey

Copy link
Member Author

Choose a reason for hiding this comment

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

used dispatchPresharedKey

@@ -141,10 +145,15 @@ func (c *Config) Complete() (RunnableServer, error) {
return nil, fmt.Errorf("failed to create dispatcher: %w", cerr)
}

presharedKey := ""
if len(c.PresharedKey) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Why check this? Shouldn't it error before here if len(c.PresharedKeys) == 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not if no keys were given; remember: preshared keys are ignored if a custom auth function is specified

Copy link
Member

Choose a reason for hiding this comment

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

Oh, gotcha.

I wonder if it makes more sense to hoist this up to where all of the other preshared key logic is.

pkg/cmd/server/server.go Show resolved Hide resolved
require.NoError(err)
require.Equal(healthpb.HealthCheckResponse_SERVING, resp.GetStatus())

client := v1alpha1.NewSchemaServiceClient(conn)
Copy link
Member

Choose a reason for hiding this comment

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

why not use v1?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy paste

Comment on lines 46 to 49
var conn *grpc.ClientConn
var err error
if key == "" {
conn, err = grpc.Dial(fmt.Sprintf("localhost:%s", tester.port), grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
conn, err = grpc.Dial(fmt.Sprintf("localhost:%s", tester.port),
grpc.WithInsecure(),
grpcutil.WithInsecureBearerToken(key),
)
}
Copy link
Member

Choose a reason for hiding this comment

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

opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
if key != "" {
    opts = append(opts, grpcutil.WithInsecureBearerToken(key))
}
conn, err := grpc.Dial(fmt.Sprintf("localhost:%s", tester.port), opts...)

@josephschorr josephschorr force-pushed the preshared-keys branch 3 times, most recently from 9439f23 to caa0998 Compare April 19, 2022 16:41
@josephschorr josephschorr marked this pull request as draft April 19, 2022 16:58
@josephschorr josephschorr force-pushed the preshared-keys branch 3 times, most recently from 6a8a912 to a8bad15 Compare April 19, 2022 17:54
@josephschorr josephschorr marked this pull request as ready for review April 19, 2022 17:55
- uses: "docker/build-push-action@v1"
with:
push: false
tags: "currentpr"
Copy link
Member

Choose a reason for hiding this comment

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

make this dev instead of currentpr

Copy link
Member Author

Choose a reason for hiding this comment

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

dev has a risk of overloading with a, well, development image. I wanted to be explicitly different from all other contexts

@@ -50,7 +50,10 @@ jobs:
- uses: "actions/setup-go@v3"
with:
go-version: "^1.17"
- uses: "authzed/actions/docker-build@main"
- uses: "docker/build-push-action@v1"
Copy link
Member

Choose a reason for hiding this comment

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

probably need to rename this job

image-build => docker-tests
Build Container Image => Build & Test Container Image

Copy link
Member Author

Choose a reason for hiding this comment

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

If we do, it'll break the CI submit checks, so I left it as is (unless we should change those too)

Copy link
Member

Choose a reason for hiding this comment

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

It's really easy to change them. I'd rather spend two seconds in the GitHub settings than live with names and descriptions of things that don't make sense.

tester, err := newTester(t,
&dockertest.RunOptions{
Repository: "authzed/spicedb",
Tag: "currentpr",
Copy link
Member

Choose a reason for hiding this comment

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

dev

cmd/spicedb/serve_integration_test.go Show resolved Hide resolved
opts = append(opts, grpcutil.WithInsecureBearerToken(key))
}
conn, err := grpc.Dial(fmt.Sprintf("localhost:%s", tester.port), opts...)

Copy link
Member

Choose a reason for hiding this comment

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

why the new line here?

require.NoError(err)
defer conn.Close()

resp, err := healthpb.NewHealthClient(conn).Check(context.Background(), &healthpb.HealthCheckRequest{Service: "authzed.api.v1alpha1.SchemaService"})
Copy link
Member

Choose a reason for hiding this comment

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

This is against v1alpha1, but then you use v1

Copy link
Member Author

Choose a reason for hiding this comment

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

Its mostly to make sure the service is running at all, but I can change it

} else {
s, ok := status.FromError(err)
require.True(ok)
require.Equal(codes.Unknown, s.Code())
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be codes.Unauthenticated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, we don't return that code if the key does not match

Copy link
Member

Choose a reason for hiding this comment

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

that seems... like a bug

@@ -29,7 +29,7 @@ func TestTestServer(t *testing.T) {
tester, err := newTester(t,
&dockertest.RunOptions{
Repository: "authzed/spicedb",
Tag: "latest",
Tag: "currentpr",
Copy link
Member

Choose a reason for hiding this comment

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

dev

client := v1.NewSchemaServiceClient(conn)
_, err = client.WriteSchema(context.Background(), &v1.WriteSchemaRequest{
Schema: `
definition user {}
Copy link
Member

Choose a reason for hiding this comment

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

Why not use a simpler schema? It's not really relevant to the test

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy-pasted it; I can make it simpler, but it wasn't a big deal to change either way

@@ -141,10 +145,15 @@ func (c *Config) Complete() (RunnableServer, error) {
return nil, fmt.Errorf("failed to create dispatcher: %w", cerr)
}

presharedKey := ""
if len(c.PresharedKey) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Oh, gotcha.

I wonder if it makes more sense to hoist this up to where all of the other preshared key logic is.

@josephschorr josephschorr force-pushed the preshared-keys branch 3 times, most recently from 0d2d311 to 0652856 Compare April 19, 2022 20:36
@josephschorr josephschorr merged commit afa8057 into authzed:main Apr 20, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 20, 2022
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/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Multiple Preshared Keys
2 participants