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

Refactor SecureReceiverSettings to use TLSSetting #1015

Conversation

ccaraman
Copy link
Contributor

Description:
Address the second part of issue #933 to clean up existing server settings with TLS.
Removed SecureReceiverSettings and replaced instances with a reference to configtls.TLSSetting
Renamed LoadGRPCTLSCredentials -> LoadgRPCTLSClientCredentials
Created issue #1014 to track merging gRPC Server settings into a common struct.

Link to tracking Issue: #933 and handles issue #963

Testing: Ran all tests.

Documentation: Doc pr will come up next.

@codecov
Copy link

codecov bot commented May 22, 2020

Codecov Report

Merging #1015 into master will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1015      +/-   ##
==========================================
+ Coverage   86.33%   86.37%   +0.04%     
==========================================
  Files         199      198       -1     
  Lines       14072    14058      -14     
==========================================
- Hits        12149    12143       -6     
+ Misses       1461     1457       -4     
+ Partials      462      458       -4     
Impacted Files Coverage Δ
receiver/jaegerreceiver/config.go 100.00% <ø> (ø)
config/configgrpc/configgrpc.go 100.00% <100.00%> (ø)
config/configtls/configtls.go 100.00% <100.00%> (ø)
receiver/jaegerreceiver/factory.go 91.66% <100.00%> (-1.67%) ⬇️
receiver/opencensusreceiver/config.go 94.44% <100.00%> (+9.44%) ⬆️
receiver/opencensusreceiver/factory.go 94.59% <100.00%> (-0.28%) ⬇️
receiver/otlpreceiver/config.go 94.44% <100.00%> (+9.44%) ⬆️
receiver/otlpreceiver/factory.go 94.59% <100.00%> (-0.28%) ⬇️
translator/internaldata/resource_to_oc.go 76.47% <0.00%> (+2.94%) ⬆️

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 4c3125a...3ad3f7a. Read the comment docs.

configmodels.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
// Configures the receiver to use TLS.
// The default value is nil, which will cause the receiver to not use TLS.
TLSCredentials *configtls.TLSSetting `mapstructure:"tls_credentials, omitempty"`
Copy link
Contributor

@jrcamp jrcamp May 22, 2020

Choose a reason for hiding this comment

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

tls_credentials makes sense for a server scenario but for a client they may just be be configuring the CA but no client certificates so there's no credentials. In those cases I think we'd want to name this tls_config or just tls. Would it make sense to have a universal config key for the TLS settings and call this the same thing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah renaming the config field is an option and something that should be figured out in a separate issue. The goal of this pr is to deprecate the SecureReceiverSettings used by several server connection scenarios.

type SecureSetting struct {
configmodels.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
// Configures the receiver to use TLS.
// The default value is nil, which will cause the receiver to not use TLS.
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we decided that for whether TLS was enabled or not it would be part of the endpoint? Maybe we were discussing more in the context of clients but I think maybe that should also apply to listening receivers so that things are uniform?

Copy link
Contributor Author

@ccaraman ccaraman May 29, 2020

Choose a reason for hiding this comment

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

Created this issue #1055 to track creating HTTPSettings so we can offer a config similar to the gRPCSettigs

@ccaraman ccaraman force-pushed the feature/ccaraman/refactor_server_tls branch from cccfe1c to 13de6e2 Compare May 26, 2020 17:22
@tigrannajaryan
Copy link
Member

@jrcamp assigning to you since you already started reviewing this.

Comment on lines 80 to 86
if rOpts.TLSCredentials != nil {
tlsCredsOptions, er := rOpts.TLSCredentials.LoadgRPCTLSServerCredentials()
if er != nil {
return nil, fmt.Errorf("error initializing OpenCensus receiver %q TLS Credentials: %v", rOpts.NameVal, er)
}
opts = append(opts, WithGRPCServerOptions(tlsCredsOptions))
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be better to use all named return values or none at all to avoid having the er which might be easy to mix up.

Suggested change
if rOpts.TLSCredentials != nil {
tlsCredsOptions, er := rOpts.TLSCredentials.LoadgRPCTLSServerCredentials()
if er != nil {
return nil, fmt.Errorf("error initializing OpenCensus receiver %q TLS Credentials: %v", rOpts.NameVal, er)
}
opts = append(opts, WithGRPCServerOptions(tlsCredsOptions))
if rOpts.TLSCredentials != nil {
var tlsCredOptions someType
tlsCredsOptions, err = rOpts.TLSCredentials.LoadgRPCTLSServerCredentials()
if err != nil {
return
}
opts = append(opts, WithGRPCServerOptions(tlsCredsOptions))

Then at the bottom can also just do a plain return to use the named arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to go to no named return values since when using err there it complains shadow: declaration of "err" shadows declaration at line 79 (govet)

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 it should only shadow if you're assigning err with :=, but not using named is fine as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah but then the vars for tlsCredOptions looks a bit weird having it declared above when there is no error and it is the only case where an error can be returned.

},
}
_, err := cfg.buildOptions()
assert.EqualError(t, err, "error initializing OpenCensus receiver \"IncorrectTLS\" TLS Credentials: failed to load TLS config: for auth via TLS, either both certificate and key must be supplied, or neither")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert.EqualError(t, err, "error initializing OpenCensus receiver \"IncorrectTLS\" TLS Credentials: failed to load TLS config: for auth via TLS, either both certificate and key must be supplied, or neither")
assert.EqualError(t, err, `error initializing OpenCensus receiver "IncorrectTLS" TLS Credentials: failed to load TLS config: for auth via TLS, either both certificate and key must be supplied, or neither`)

opts = append(opts, tlsCredsOption)
if rOpts.TLSCredentials != nil {
tlsCredsOptions, er := rOpts.TLSCredentials.LoadgRPCTLSServerCredentials()
if er != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@ccaraman ccaraman force-pushed the feature/ccaraman/refactor_server_tls branch from 13de6e2 to 3ad3f7a Compare May 29, 2020 18:25
@ccaraman
Copy link
Contributor Author

@jrcamp - updated to address your comments.

@jrcamp jrcamp removed their assignment May 29, 2020
@jrcamp
Copy link
Contributor

jrcamp commented May 29, 2020

@tigrannajaryan ptal

config/configtls/configtls.go Show resolved Hide resolved
@tigrannajaryan
Copy link
Member

OK to merge this?

@bogdandrutu bogdandrutu merged commit ed5a8de into open-telemetry:master Jun 2, 2020
wyTrivail pushed a commit to mxiamxia/opentelemetry-collector that referenced this pull request Jul 13, 2020
* Refactor SecureReceiverSettings to use TLSSetting

* Address test code coverage failure

* Update file to use new license format

* Address few small comments
Troels51 pushed a commit to Troels51/opentelemetry-collector that referenced this pull request Jul 5, 2024
swiatekm pushed a commit to swiatekm/opentelemetry-collector that referenced this pull request Oct 9, 2024
…try#1015)

* set gomemlimit correctly

* minor fixes

* update chart version

* update var

* remove unittest

* remove unittest
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.

4 participants