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

Extract gRPC TLS configuration into a shared package #1840

Merged
merged 10 commits into from
Oct 8, 2019

Conversation

yurishkuro
Copy link
Member

@yurishkuro yurishkuro commented Oct 7, 2019

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.

Yuri Shkuro added 3 commits October 6, 2019 21:22
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Copy link
Contributor

@jpkrohling jpkrohling left a 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?

cmd/agent/app/reporter/grpc/builder_test.go Outdated Show resolved Hide resolved
@yurishkuro yurishkuro changed the title Refactor tls certs WIP: Refactor tls certs Oct 7, 2019
Yuri Shkuro added 3 commits October 7, 2019 18:21
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")
Copy link
Member Author

@yurishkuro yurishkuro Oct 8, 2019

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
Copy link

codecov bot commented Oct 8, 2019

Codecov Report

Merging #1840 into master will increase coverage by 0.22%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
cmd/collector/app/grpcserver/grpc_server.go 100% <ø> (+47.5%) ⬆️
cmd/agent/app/reporter/grpc/collector_proxy.go 100% <ø> (ø) ⬆️
cmd/agent/app/reporter/grpc/flags.go 100% <100%> (ø) ⬆️
pkg/config/tlscfg/options.go 100% <100%> (ø)
pkg/config/tlscfg/flags.go 100% <100%> (ø)
cmd/collector/app/builder/builder_flags.go 100% <100%> (ø) ⬆️
cmd/agent/app/reporter/grpc/builder.go 100% <100%> (+3.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fcc0adb...207c01b. Read the comment docs.

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)")
Copy link
Member Author

@yurishkuro yurishkuro Oct 8, 2019

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

Yuri Shkuro added 3 commits October 7, 2019 22:33
Signed-off-by: Yuri Shkuro <[email protected]>
@yurishkuro yurishkuro changed the title WIP: Refactor tls certs Move TLS logic from gRPC client/server into a shared package Oct 8, 2019
@yurishkuro yurishkuro changed the title Move TLS logic from gRPC client/server into a shared package Move TLS configuration from gRPC client/server into a shared package Oct 8, 2019
@yurishkuro
Copy link
Member Author

Is this ready for review? If so, what's the deal with the commented out tests?

Sorry, I pushed as WIP to show @backjo the approach I was taking. It's now ready for review.

@yurishkuro yurishkuro changed the title Move TLS configuration from gRPC client/server into a shared package Extract gRPC TLS configuration into a shared package Oct 8, 2019

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

@yurishkuro yurishkuro Oct 8, 2019

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.

@yurishkuro yurishkuro merged commit d553583 into jaegertracing:master Oct 8, 2019
@yurishkuro yurishkuro deleted the refactor-tls-certs branch October 8, 2019 21:33
@yurishkuro yurishkuro added this to the Release 1.15 milestone Nov 7, 2019
backjo pushed a commit to backjo/jaeger that referenced this pull request Dec 19, 2019
)

* 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]>
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