-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Extract gRPC TLS configuration into a shared package #1840
Extract gRPC TLS configuration into a shared package #1840
Conversation
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ready for review? If so, what's the deal with the commented out tests?
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
flags.String(collectorTLSCA, "", "Path to a TLS CA file used to verify the remote server. (default use the systems truststore)") | ||
flags.String(collectorTLSServerName, "", "Override the TLS server name we expected in the remote certificate") | ||
flags.String(agentCert, "", "Path to a TLS client certificate file, used to identify this agent to the collector") | ||
flags.String(agentKey, "", "Path to the TLS client key for the client certificate") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now:
$ go run ./cmd/agent help | grep tls
--reporter.grpc.tls Enable TLS when talking to the remote server(s)
--reporter.grpc.tls.ca string Path to a TLS CA (Certification Authority) file used to verify the remote server(s) (by default will use the system truststore)
--reporter.grpc.tls.cert string Path to a TLS Certificate file, used to identify this process to the remote server(s)
--reporter.grpc.tls.key string Path to a TLS Private Key file, used to identify this process to the remote server(s)
--reporter.grpc.tls.server-name string Override the TLS server name we expect in the certificate of the remove server(s)
Signed-off-by: Yuri Shkuro <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #1840 +/- ##
==========================================
+ Coverage 98.21% 98.44% +0.22%
==========================================
Files 195 197 +2
Lines 9603 9619 +16
==========================================
+ Hits 9432 9469 +37
+ Misses 134 114 -20
+ Partials 37 36 -1
Continue to review full report at Codecov.
|
flags.Bool(collectorGRPCTLS, false, "Enable TLS for the gRPC collector port") | ||
flags.String(collectorGRPCCert, "", "Path to TLS certificate for the gRPC collector TLS service") | ||
flags.String(collectorGRPCKey, "", "Path to TLS key for the gRPC collector TLS cert") | ||
flags.String(collectorGRPCClientCA, "", "Path to a TLS CA to verify certificates presented by clients (if unset, all clients are permitted)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now:
$ go run ./cmd/collector help | grep grpc.tls
--collector.grpc.tls Enable TLS on the server
--collector.grpc.tls.cert string Path to a TLS Certificate file, used to identify this server to clients
--collector.grpc.tls.client-ca string Path to a TLS CA (Certification Authority) file used to verify certificates presented by clients (if unset, all clients are permitted)
--collector.grpc.tls.client.ca string (deprecated) see --collector.grpc.tls.client-ca
--collector.grpc.tls.key string Path to a TLS Private Key file, used to identify this server to clients
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Sorry, I pushed as WIP to show @backjo the approach I was taking. It's now ready for review. |
|
||
if test.checkSuffixOnly { | ||
assert.True(t, strings.HasSuffix(conn.Target(), test.target)) | ||
} else { | ||
assert.True(t, conn.Target() == test.target) | ||
} | ||
} else { | ||
require.Error(t, err) | ||
assert.Contains(t, err.Error(), test.expectedError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That function performs exact comparison of the error message. Since the error is wrapped multiple times, the message consists of multiple segments. I don't know or care what the underlying stdlib error was, I only care about the substring introduced by the code under test.
) * Extract TLS flags and cert loading logic Signed-off-by: Yuri Shkuro <[email protected]> * Rename package Signed-off-by: Yuri Shkuro <[email protected]> * Refactor grpc Signed-off-by: Yuri Shkuro <[email protected]> * Repair tests Signed-off-by: Yuri Shkuro <[email protected]> * Refactor gRPC server in collector Signed-off-by: Yuri Shkuro <[email protected]> * Add ShowCA option Signed-off-by: Yuri Shkuro <[email protected]> * Switch options order Signed-off-by: Yuri Shkuro <[email protected]> * Separate client and server TLS options Signed-off-by: Yuri Shkuro <[email protected]> * Update usage Signed-off-by: Yuri Shkuro <[email protected]> * Rename test, add filepath.Clean Signed-off-by: Yuri Shkuro <[email protected]> Signed-off-by: Jonah Back <[email protected]>
Part of #1837
Moves TLS configuration from gRPC client (agent) and server (collector) into a shared package
pkg/config/tlscfg
. This allows fewer unit tests to be written for the call sites, since all error handling of TLS certificates loading is covered in the new package.