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

Allow specifying simple gRPC transport credentials #508

Merged
merged 2 commits into from
Sep 21, 2018

Conversation

tcolgate
Copy link
Contributor

@tcolgate tcolgate commented Sep 7, 2018

No description provided.

@tcolgate tcolgate mentioned this pull request Sep 7, 2018
@tcolgate
Copy link
Contributor Author

tcolgate commented Sep 7, 2018

This is a preliminary PR to see if you are interested in this, if so I'll fix up the tests.

@tcolgate tcolgate changed the title Allow specifying simple gRPC transport credentials [WIP] Allow specifying simple gRPC transport credentials Sep 7, 2018
Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

I feel like we should differentiate between server certs and client certs. What if that is different? Also you state that in description that those flags are for incoming request and then you use it for store client connections.

Also, what if each storeAPI will required different key?

cmd/thanos/flags.go Outdated Show resolved Hide resolved
grpcBindAddr := cmd.Flag("grpc-address", "Listen ip:port address for gRPC endpoints (StoreAPI). Make sure this address is routable from other components if you use gossip, 'grpc-advertise-address' is empty and you require cross-node connection.").
Default("0.0.0.0:10901").String()

grpcAdvertiseAddr := cmd.Flag("grpc-advertise-address", "Explicit (external) host:port address to advertise for gRPC StoreAPI in gossip cluster. If empty, 'grpc-address' will be used.").
String()

grpcTLSInsecure := cmd.Flag("grpc-tls-insecure", "Do not use gRPC transport credentials to verify connections").Default("true").Bool()
Copy link
Member

Choose a reason for hiding this comment

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

Let's make sure in the name to be clear that this touches incoming requests.

Just note that only thanos query calls those grpc Requests. Rest is only serving those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

cmd/thanos/main.go Outdated Show resolved Hide resolved
@tcolgate
Copy link
Contributor Author

tcolgate commented Sep 7, 2018

For the first stab I went for the simplest setup, but TBH this isn't what I'd do for production services (this is how the gRPC examples set things up).
If may not be immediately obvious, but the client cert there is not a client cert, it's just a client CA to trust.

Ideally we'd have:

  • explicit CA for verifying clients
  • explicit CA for verifying servers
  • explicit client cert/key
  • explicit server cert/key
  • options for client verification

Unfortunately this ends up amounting to an awful lot of cli flags.
Perhaps we should stick to only offering server verification first, but make that clearer from the name?

grpc-server-cert
grpc-server-key
grpc-client-ca

Thoughts?

@tcolgate tcolgate force-pushed the grpccreds branch 2 times, most recently from fb740ea to 25678f5 Compare September 7, 2018 15:30
@tcolgate
Copy link
Contributor Author

tcolgate commented Sep 7, 2018

@Bplotka updated the arg names, they still aren't very pretty. If you have specific ideas, please do say. (personally I'd have something like --query.tls.caCert , --grpc.tls.cert --grpc.tls.key, some of the existing args seem to follow that kind of format, but I've not been able to discern a pattern to them.

opted for creds rather than tlsCreds, it's a little more accurate, and matches the functions they are then used with.

@tcolgate
Copy link
Contributor Author

tcolgate commented Sep 8, 2018

Mostly note to self. Will add client key/cert and server client verification CA. Need this (or actual per roc auth cress) for minimal secure use case

@tcolgate
Copy link
Contributor Author

@Bplotka updated to provide full client cert and server side verification.

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

It looks really really nice! Some minor issues only. Thanks!

cmd/thanos/main.go Outdated Show resolved Hide resolved
*insecure,
*srvcert,
*srvkey,
*srvclientca,
Copy link
Member

Choose a reason for hiding this comment

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

let's make it camelCase everywhere: srvKey srvClientCA etc

cmd/thanos/query.go Outdated Show resolved Hide resolved
cmd/thanos/flags.go Outdated Show resolved Hide resolved
cmd/thanos/query.go Outdated Show resolved Hide resolved
@bwplotka bwplotka mentioned this pull request Sep 12, 2018
4 tasks
@tcolgate tcolgate force-pushed the grpccreds branch 3 times, most recently from b448646 to 0c41c21 Compare September 13, 2018 09:55
@bwplotka
Copy link
Member

Can we have some rebase?

@tcolgate
Copy link
Contributor Author

@Bplotka opened a whole can of rebase!

@tcolgate
Copy link
Contributor Author

@Bplotka fixed my dep woes, docs and deps updated.

cmd/thanos/main.go Outdated Show resolved Hide resolved
Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments. Two more suggestions before merging.

cmd/thanos/main.go Outdated Show resolved Hide resolved
cmd/thanos/flags.go Outdated Show resolved Hide resolved
@tcolgate tcolgate force-pushed the grpccreds branch 4 times, most recently from 00622b2 to 113a71e Compare September 14, 2018 15:08
@tcolgate
Copy link
Contributor Author

@bwplotka we're running this locally with seeming success. Have yet to confirm query -> multiple store gateways over a WAN, but single query to single gateway in cluster is fine.

@bwplotka
Copy link
Member

Let's change the WIP title and will do review today (:

@tcolgate tcolgate changed the title [WIP] Allow specifying simple gRPC transport credentials Allow specifying simple gRPC transport credentials Sep 19, 2018
@tcolgate
Copy link
Contributor Author

@bwplotka rebased on master, not quite sure what is going on with the Gopkg.lock, possible my version of dep is too old/new?

@bwplotka
Copy link
Member

what do you use for deps? Can you use reset your changes on .lock and do make deps? this is installing and using pinned version of dep (:

@tcolgate
Copy link
Contributor Author

@bwplotka reset it and make dep, looks better now

@bwplotka
Copy link
Member

finally some tooling work paid off 😅

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Nice work, I added some minor suggestions, but looks really good! Thanks!

cmd/thanos/main.go Show resolved Hide resolved
@@ -227,6 +231,43 @@ func defaultGRPCServerOpts(logger log.Logger, reg *prometheus.Registry, tracer o
grpc_recovery.StreamServerInterceptor(grpc_recovery.WithRecoveryHandler(grpcPanicRecoveryHandler)),
),
}

if key == "" || cert == "" {
Copy link
Member

Choose a reason for hiding this comment

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

I think we need error if any of this is filled but not all. Also if clientCA is filled but those keys not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure if you want a log and an error, or just an error, and is returning an errors.New OK?

cmd/thanos/flags.go Outdated Show resolved Hide resolved
cmd/thanos/query.go Show resolved Hide resolved
cmd/thanos/query.go Outdated Show resolved Hide resolved
cmd/thanos/query.go Show resolved Hide resolved
creds := credentials.NewTLS(tlsCfg)
dialOpts = append(dialOpts, grpc.WithTransportCredentials(creds))

return dialOpts, nil
Copy link
Member

Choose a reason for hiding this comment

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

ditto, we can just inline this.

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Almost there, sorry for being so strict (: Hope you are not mad... but I think this is the very last suggestion and we are rdy to merge! Approving in advance.

level.Info(logger).Log("msg", "gRPC server TLS client verification enabled")
}

creds := credentials.NewTLS(tlsCfg)
Copy link
Member

Choose a reason for hiding this comment

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

i don't think you need creds variable

So our thinking in Thanos is - if you do a variable it means that you need this in more places than just one. Otherwise just inline (: Do you agree with this?

@@ -28,18 +31,24 @@ import (
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/tsdb/labels"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"gopkg.in/alecthomas/kingpin.v2"
)

// registerQuery registers a query command.
Copy link
Member

Choose a reason for hiding this comment

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

BTW what happened to GitHub - coloring for golang sucks ... now there is some red mark on go comments??

Copy link
Member

Choose a reason for hiding this comment

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

or is it only my browser?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's doing it for me too, I've no idea what is going on there.

cmd/thanos/main.go Show resolved Hide resolved
@tcolgate
Copy link
Contributor Author

No, review is completely cool, very important to match the project style (it's also a better patch for it)

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

LGTM 🏷️

@bwplotka bwplotka merged commit 1e1f9e5 into thanos-io:master Sep 21, 2018
@bwplotka
Copy link
Member

Thanks! That is epic addition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants