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 a mTLS gRPC server to veneur-proxy. #1029

Merged
merged 4 commits into from
Feb 1, 2023
Merged

Conversation

arnavdugar-stripe
Copy link
Contributor

Summary

Add a mTLS gRPC server to veneur-proxy.

@@ -72,6 +72,7 @@ func main() {
if err != nil {
logger.WithError(err).Fatal("failed to create statsd client")
}
defer statsClient.Flush()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm missing this on the 'left side'. Is this newly needed for mTLS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, this is just missing in general.

@@ -72,6 +81,21 @@ func Create(params *CreateParams) *Proxy {
IsClient: false,
Statsd: params.Statsd,
})),
grpcTlsAddress: params.Config.GrpcTlsAddress,
grpcTlsServer: grpc.NewServer(
Copy link
Contributor

Choose a reason for hiding this comment

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

If TLS is specified, the service will still also open a non-TLS, is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Both will be there.

@@ -39,6 +40,9 @@ type Proxy struct {
grpcAddress string
grpcListener net.Listener
grpcServer *grpc.Server
grpcTlsAddress string
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -7,18 +7,18 @@ import (
"os"
)

type config struct {
type Config struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is config now being exposed? (it appears the original intent was for it to be hidden & an implementation detail. Exposing it, I believe, would imply we need to reevaluate the API it entails (In this case, specifically the GetTlsConfig() method)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed it in the unit test here, couldn't find a way to do it without making it public:
https://github.com/stripe/veneur/pull/1029/files#diff-8d5bed61a3c0b7b0bfdd65dd4c93e647568b1a402840f5e302c0c922f6c58ea3R38

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah the need for type Config struct seems redundant if the fields are exposed anyways. Could prolly just use type Tls struct

Copy link
Contributor Author

@arnavdugar-stripe arnavdugar-stripe Feb 1, 2023

Choose a reason for hiding this comment

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

Could prolly just use type Tls struct

Doing this causes infinite recursion when unmarshalling yaml, because then

err := unmarshal(&config.Config)

will call

func (config *Tls) UnmarshalYAML(unmarshal func(interface{}) error) error {

The type passed into unmarshal must be different than the receiver type of UnmarshalYAML.

proxy/proxy.go Outdated
Comment on lines 270 to 279
// Start gRPC TLS server
grpcTlsExit := make(chan error, 1)
proxy.logger.WithFields(logrus.Fields{
"address": proxy.GetGrpcTlsAddress(),
"tls": "true",
}).Debug("serving grpc")
waitGroup.Add(1)
go func() {
defer waitGroup.Done()

Copy link
Contributor

Choose a reason for hiding this comment

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

The grpcTLS server seems like a dupe of grpc Server above. I would at least want to see a separate function for the deep nesting of goroutines like go start(server))

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 subtlety different enough that I figured it would be more readable to keep it separate. Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the anonymous function at line 292 should at least be a separate function as right now it handles ~a lot of different tasks.

go handleShutdown(proxy.grpcServer) seems easy enough. (may add a logger field so that the logger outputs "server_type: grpcTls" or "server_type: grpc" to distinguish the logs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I was able to refactor this cleanly.

proxy/proxy.go Outdated
Comment on lines 292 to 298
go func() {
defer func() {
proxy.grpcTlsListener.Close()
close(grpcTlsError)
waitGroup.Done()
}()

Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be a separate function rather than anonymous?

Copy link
Contributor

@mimran-stripe mimran-stripe left a comment

Choose a reason for hiding this comment

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

LGTM

@arnavdugar-stripe arnavdugar-stripe merged commit fbf9c10 into master Feb 1, 2023
@arnavdugar-stripe arnavdugar-stripe deleted the arnavdugar/mtls branch February 1, 2023 19:49
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.

3 participants