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

[receiver/mongodb] Respect TLS in all situations #12093

Merged
merged 8 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion receiver/mongodbreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *Config) ClientOptions() *options.ClientOptions {
}

tlsConfig, err := c.LoadTLSConfig()
if err != nil && tlsConfig != nil {
if err == nil && tlsConfig != nil {
clientOptions.SetTLSConfig(tlsConfig)
}

Expand Down
22 changes: 22 additions & 0 deletions receiver/mongodbreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package mongodbreceiver // import "github.com/open-telemetry/opentelemetry-colle

import (
"errors"
"path/filepath"
"testing"
"time"

Expand Down Expand Up @@ -175,3 +176,24 @@ func TestOptions(t *testing.T) {
)
require.Equal(t, "rs-1", *clientOptions.ReplicaSet)
}

func TestOptionsTLS(t *testing.T) {
// loading valid ca file
caFile := filepath.Join("testdata", "certs", "ca-1.cert")

cfg := &Config{
Hosts: []confignet.NetAddr{
{
Endpoint: "localhost:27017",
},
},
TLSClientSetting: configtls.TLSClientSetting{
Insecure: false,
TLSSetting: configtls.TLSSetting{
CAFile: caFile,
},
},
}
opts := cfg.ClientOptions()
require.NotNil(t, opts.TLSConfig)
}
4 changes: 3 additions & 1 deletion receiver/mongodbreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func TestMongodbIntegration(t *testing.T) {
Endpoint: net.JoinHostPort(hostname, "27017"),
},
}
cfg.Insecure = true

consumer := new(consumertest.MetricsSink)
settings := componenttest.NewNopReceiverCreateSettings()
Expand Down Expand Up @@ -108,6 +109,7 @@ func TestMongodbIntegration(t *testing.T) {
Endpoint: net.JoinHostPort(hostname, "27018"),
},
}
cfg.Insecure = true

consumer := new(consumertest.MetricsSink)
settings := componenttest.NewNopReceiverCreateSettings()
Expand All @@ -126,7 +128,7 @@ func TestMongodbIntegration(t *testing.T) {
expectedMetrics, err := golden.ReadMetrics(expectedFile)
require.NoError(t, err)

scrapertest.CompareMetrics(expectedMetrics, actualMetrics, scrapertest.IgnoreMetricValues())
require.NoError(t, scrapertest.CompareMetrics(expectedMetrics, actualMetrics, scrapertest.IgnoreMetricValues()))
})
}

Expand Down
20 changes: 20 additions & 0 deletions receiver/mongodbreceiver/testdata/certs/ca-1.cert
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
djaglowski marked this conversation as resolved.
Show resolved Hide resolved
MIIDQTCCAikCFBRvACBtxF6AcNBP7lGKJj1DyZxeMA0GCSqGSIb3DQEBCwUAMF0x
CzAJBgNVBAYTAkFVMRIwEAYDVQQIDAlBdXN0cmFsaWExDzANBgNVBAcMBlN5ZG5l
eTESMBAGA1UECgwJTXlPcmdOYW1lMRUwEwYDVQQDDAxNeUNvbW1vbk5hbWUwHhcN
MjIwMTI2MTAyMzE2WhcNMzIwMTI0MTAyMzE2WjBdMQswCQYDVQQGEwJBVTESMBAG
A1UECAwJQXVzdHJhbGlhMQ8wDQYDVQQHDAZTeWRuZXkxEjAQBgNVBAoMCU15T3Jn
TmFtZTEVMBMGA1UEAwwMTXlDb21tb25OYW1lMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEA0EKdPNVpHFQ2tlBSUfBBTR7D7Zv2Ip5aWACvyjnqxwIWv+Jz
gtOAJYpKP22Tc4ADLQlZldDwDUTuRZ/BMpcf66M5DDbXBnDZUy0xyRmX6PgPMWPY
wa1syQkawh80k/UEbFAkSRSp7NvIrevP42ox36Ex4u0LtXVr0xUHs8Q2uB6FawMY
NOcn9l5xBR1ghj8xCMCWKdKfn5FcjJQ+sW/37lOR5xmWbldKqw73eu3tuKKEWUoo
fU9Em/DOQcw3EkHAyWXSrhhWWYQ5ejscF2ON9xhoElx4FMm+lub6lh3jiiMAQo5x
kQc5sFjbKqHQFZtLL2xeVsfT9CX2+SksxbtxxwIDAQABMA0GCSqGSIb3DQEBCwUA
A4IBAQASMYvTPoh+pv4dco9OAZQeW5KZbndiIqo6QsO9ZFPyYsuJl21jexLN9nUN
vhLj38rFmYpzw8smA6fOyhl4wQDxrftj/ODyVN29gqwF9RhcElGiUg34heqO+ntE
ozGZC4MfZdQffjAJr9I7E9Y6vsuNjdVVaUmcSCya/DcDDGQUWE29io3bIsAkvpSK
Qp3Ub9ZYgCi2RPfVteWJXS/en6X8xtJsxQeujkWaXqxszU2NTYFkKyDM4lOiJTPm
yflM/1sCGZiPmLWMOXl54ULE2qHX4Mx0YVschFt7t3e/k6XgCTdUrHShOWIUs5cv
3jw3wJGOdBA753OFGmf9n5rGUw8P
-----END CERTIFICATE-----
11 changes: 11 additions & 0 deletions unreleased/mongodb-rcvr-fix-tls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: mongodbreceiver

# A brief description of the change
note: do not ignore TLS Settings in mongodbreceiver

# One or more tracking issues related to the change
issues: [12092]