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 support to TLSSetting to not only read from file path, but from memory #7676

Merged
merged 8 commits into from
Jun 7, 2023

Conversation

erikbaranowski
Copy link
Contributor

@erikbaranowski erikbaranowski commented May 15, 2023

Description: This implements a version of the proposed changes requested in the linked issue.

Related: A PR accomplishing similar was accepted into Prometheus recently.

Link to tracking Issue: #7313

Testing: Added tests for a variety of scenarios around filepath vs in memory certs.

Documentation: Added new parameters to the README

Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 15, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@erikbaranowski erikbaranowski marked this pull request as ready for review May 15, 2023 19:47
@erikbaranowski erikbaranowski requested a review from a team as a code owner May 15, 2023 19:47
@erikbaranowski
Copy link
Contributor Author

erikbaranowski commented May 16, 2023

I have been poking at the unit test issue and I noticed this isn't the only PR getting it.

#7486
https://github.com/open-telemetry/opentelemetry-collector/actions/runs/4983229007/jobs/8919996685

EDIT: I can recreate with go test -race -timeout 120s -run TestErrorRecordedIfFileDeleted

@erikbaranowski
Copy link
Contributor Author

Found the related issue I think #7537

Copy link
Member

@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.

This looks good to me. I feel like there's an opportunity to optimize the periodic reloading of certs if the PEM-encoded string was provided, but I recognize that this PR solves a concrete problem already.


switch {
case c.hasCAFile() && c.hasCAPem():
return nil, fmt.Errorf("failed to load CA CertPool: CA File and PEM cannot both be provided")
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to get a native speaker to check this wording, as it sounds a bit strange to my ears. I would use something like:

failed to load CA CertPool: provide either a CA file or the PEM-encoded string, but not both

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 updated some of the verbiage to match the suggested pattern. Let me know if you think more needs to be changed. It's no big deal on my end.

Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
@mx-psi
Copy link
Member

mx-psi commented May 17, 2023

Tests need fixing (not related to #7537 AFAICT)

--- FAIL: TestOptionsToConfig (0.02s)
    --- FAIL: TestOptionsToConfig/should_fail_with_missing_TLS_KeyFile (0.00s)
        configtls_test.go:236: 
            	Error Trace:	/home/runner/work/opentelemetry-collector/opentelemetry-collector/config/configtls/configtls_test.go:236
            	Error:      	"failed to load TLS cert and key: for auth via TLS, provide both certificate and key, or neither" does not contain "both certificate and key must be supplied"
            	Test:       	TestOptionsToConfig/should_fail_with_missing_TLS_KeyFile
    --- FAIL: TestOptionsToConfig/should_fail_with_missing_TLS_Cert (0.00s)
        configtls_test.go:236: 
            	Error Trace:	/home/runner/work/opentelemetry-collector/opentelemetry-collector/config/configtls/configtls_test.go:236
            	Error:      	"failed to load TLS cert and key: for auth via TLS, provide both certificate and key, or neither" does not contain "both certificate and key must be supplied"
            	Test:       	TestOptionsToConfig/should_fail_with_missing_TLS_Cert
    --- FAIL: TestOptionsToConfig/should_fail_Cert_file_and_PEM_both_provided (0.00s)
        configtls_test.go:236: 
            	Error Trace:	/home/runner/work/opentelemetry-collector/opentelemetry-collector/config/configtls/configtls_test.go:236
            	Error:      	"failed to load TLS cert and key: for auth via TLS, provide either a certificate or the PEM-encoded string, but not both" does not contain "for auth via TLS, certificate file and PEM cannot both be provided"
            	Test:       	TestOptionsToConfig/should_fail_Cert_file_and_PEM_both_provided
    --- FAIL: TestOptionsToConfig/should_fail_Key_file_and_PEM_both_provided (0.00s)
        configtls_test.go:236: 
            	Error Trace:	/home/runner/work/opentelemetry-collector/opentelemetry-collector/config/configtls/configtls_test.go:236
            	Error:      	"failed to load TLS cert and key: for auth via TLS, provide either a key or the PEM-encoded string, but not both" does not contain "for auth via TLS, key file and PEM cannot both be provided"
            	Test:       	TestOptionsToConfig/should_fail_Key_file_and_PEM_both_provided
    --- FAIL: TestOptionsToConfig/should_fail_with_missing_TLS_KeyPem (0.00s)
        configtls_test.go:236: 
            	Error Trace:	/home/runner/work/opentelemetry-collector/opentelemetry-collector/config/configtls/configtls_test.go:236
            	Error:      	"failed to load TLS cert and key: for auth via TLS, provide both certificate and key, or neither" does not contain "both certificate and key must be supplied"
            	Test:       	TestOptionsToConfig/should_fail_with_missing_TLS_KeyPem
    --- FAIL: TestOptionsToConfig/should_fail_with_missing_TLS_Cert_PEM (0.00s)
        configtls_test.go:236: 
            	Error Trace:	/home/runner/work/opentelemetry-collector/opentelemetry-collector/config/configtls/configtls_test.go:236
            	Error:      	"failed to load TLS cert and key: for auth via TLS, provide both certificate and key, or neither" does not contain "both certificate and key must be supplied"
            	Test:       	TestOptionsToConfig/should_fail_with_missing_TLS_Cert_PEM

mx-psi
mx-psi previously requested changes May 17, 2023
config/configtls/configtls.go Outdated Show resolved Hide resolved
Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
@codecov
Copy link

codecov bot commented May 18, 2023

Codecov Report

Patch coverage: 97.84% and project coverage change: -0.30 ⚠️

Comparison is base (6542100) 91.31% compared to head (762fe16) 91.02%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7676      +/-   ##
==========================================
- Coverage   91.31%   91.02%   -0.30%     
==========================================
  Files         296      295       -1     
  Lines       14485    14617     +132     
==========================================
+ Hits        13227    13305      +78     
- Misses        995     1048      +53     
- Partials      263      264       +1     
Impacted Files Coverage Δ
config/configtls/configtls.go 97.34% <97.84%> (-0.23%) ⬇️

... and 294 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mx-psi
Copy link
Member

mx-psi commented May 19, 2023

Tests are failing on Windows:

--- FAIL: TestHTTPServerSettingsError (0.00s)
    --- FAIL: TestHTTPServerSettingsError/failed_to_load_client_CA_CertPool:_failed_to_load_CA_/doesnt/exist:_open_/doesnt/exist: (0.00s)
        confighttp_test.go:443: 
            	Error Trace:	D:/a/opentelemetry-collector/opentelemetry-collector/config/confighttp/confighttp_test.go:443
            	Error:      	Expect "failed to load client CA CertPool: failed to load CA /doesnt/exist: open \doesnt\exist: The system cannot find the path specified." to match "failed to load client CA CertPool: failed to load CA /doesnt/exist: open /doesnt/exist:"

@mx-psi mx-psi dismissed their stale review May 19, 2023 06:52

Now using configopaque

@bogdandrutu
Copy link
Member

Need a fix on windows.

Signed-off-by: Erik Baranowski <39704712+erikbaranowski@users.noreply.github.com>
@erikbaranowski
Copy link
Contributor Author

Fixed test in windows

@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2023

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jun 6, 2023
@erikbaranowski
Copy link
Contributor Author

hey all, is there anything else needed on this PR before merge?

@github-actions github-actions bot removed the Stale label Jun 7, 2023
@bogdandrutu bogdandrutu merged commit 07262f2 into open-telemetry:main Jun 7, 2023
29 checks passed
@github-actions github-actions bot added this to the next release milestone Jun 7, 2023
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.

None yet

4 participants