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 TlsConfigHelper for additional TLS configurability #5246

Merged
merged 14 commits into from
Mar 7, 2023

Conversation

breedx-splk
Copy link
Contributor

Related to #5211.

Before touching the exporter builder API surface, I wanted to try and get some of these changes in first. The main goal was to allow configuring some of the TLS components directly, but it turned out to also consolidate a small amount of duplicated code between the internal GPRC and HTTP builders.

There are warnings logged if the helper is not used in an expected way (ie. parts are configured without the trust manager [the primary important thing!] being configured).

The hope is that this can pave a way forward to add a few methods to the exporter builders, that will eventually allow users to bring their own:

  • X509TrustManager
  • X509KeyManager
  • SSLSocketFactory

...eventually providing more complete configurability of TLS within HTTP behavior, while also keeping the simple things easy.

@breedx-splk breedx-splk requested a review from a team as a code owner February 24, 2023 02:10
Copy link
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

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

I like this idea. Maybe we can prototype the API by offering an internal API for users to play around with and confirm all our bases are covered. Maybe something like the internal API for setting retry policy.

}

/** Configures TLS for the provided OkHttp client builder by setting the SSL Socket Factory. */
public void configure(OkHttpClient.Builder clientBuilder) {
Copy link
Member

Choose a reason for hiding this comment

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

How about having this accept a Consumer<SSLSocketFactory> so this isn't coupled to okhttp?

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 totally....I started down this path when I realized there are like 2 or 3 other implementations doing exactly the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So please have a look at how it ended up. Unfortunately, the managed channel stuff inside GRPC uses a different approach and I had to create two different callback interfaces. I think it worked out ok. I also wanted to be able to handle SSLException in the helper, which required the checked exception to be on the interface method.

exporters/jaeger/src/test/resources/tls-test.key Outdated Show resolved Hide resolved
@breedx-splk breedx-splk marked this pull request as draft February 24, 2023 21:56
@codecov
Copy link

codecov bot commented Feb 25, 2023

Codecov Report

Patch coverage: 83.65% and project coverage change: -0.07 ⚠️

Comparison is base (696d3f0) 91.10% compared to head (0446b73) 91.03%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5246      +/-   ##
============================================
- Coverage     91.10%   91.03%   -0.07%     
- Complexity     4876     4891      +15     
============================================
  Files           549      550       +1     
  Lines         14420    14456      +36     
  Branches       1371     1368       -3     
============================================
+ Hits          13137    13160      +23     
- Misses          890      901      +11     
- Partials        393      395       +2     
Impacted Files Coverage Δ
...va/io/opentelemetry/exporter/internal/TlsUtil.java 85.93% <ø> (ø)
...xporter/internal/okhttp/OkHttpExporterBuilder.java 83.63% <60.00%> (-9.47%) ⬇️
...race/jaeger/sampler/DefaultGrpcServiceBuilder.java 79.66% <80.00%> (+3.85%) ⬆️
...entelemetry/exporter/internal/TlsConfigHelper.java 81.13% <81.13%> (ø)
...try/exporter/internal/grpc/ManagedChannelUtil.java 87.50% <88.88%> (+1.29%) ⬆️
...ry/exporter/internal/grpc/GrpcExporterBuilder.java 100.00% <100.00%> (+1.21%) ⬆️
...exporter/jaeger/JaegerGrpcSpanExporterBuilder.java 80.64% <100.00%> (ø)
...lp/http/metrics/OtlpHttpMetricExporterBuilder.java 95.00% <100.00%> (ø)
...r/otlp/http/trace/OtlpHttpSpanExporterBuilder.java 89.28% <100.00%> (ø)
...er/otlp/metrics/OtlpGrpcMetricExporterBuilder.java 100.00% <100.00%> (ø)
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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

@breedx-splk breedx-splk marked this pull request as ready for review February 27, 2023 23:11
Copy link
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

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

Small comments plus an approach that would allow us to simplify by removing TlsConfigHelper#configureWithKeyManager.

tlsConfigHelper.configureWithKeyManager(
(tm, km) ->
ManagedChannelUtil.setClientKeysAndTrustedCertificatesPem(
managedChannelBuilder, tm, km));
Copy link
Member

Choose a reason for hiding this comment

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

Its strange that we for the other gRPC clients (otlp, jaeger) we don't bother trying to configure the managed channel with certificates. We take the stance that if you bring your own ManagedChannel, you're responsible for configuring it.

In fact, this is the only usage of ManagedChannelUtil.setClientKeysAndTrustedCertificatesPem outside of tests.

We should adopt the same policy here. Doing so allows us to move ManagedChannelUtil.setClientKeysAndTrustedCertificatesPem to test code, where its used by ManagedChannelTelemetryExporterBuilder. This allows us to simplify tlsConfigHelper as we can get rid of the configureWithKeyManager method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, this is interesting and I would love to simplify. I was absolutely bummed when I discovered this "other path" for configuring TLS related stuff, and unifying/simplifying would be great.

I think that removing configureWithKeyManager() from the helper would then require the DefaultGrpcServiceBuilder to call setClientKeysAndTrustedCertificatesPem() with a key manager and trust manager that it has constructed itself. I'm not sure immediately how to do with without duplicating some of the guts of TlsConfigHelper.

Copy link
Member

Choose a reason for hiding this comment

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

I think that removing configureWithKeyManager() from the helper would then require the DefaultGrpcServiceBuilder to call setClientKeysAndTrustedCertificatesPem() with a key manager and trust manager that it has constructed itself.

I'm suggesting we drop any configuration of ManagedChannel in DefaultGrpcServiceBuilder, as we've done with the other grpc clients that allow you to "bring your own channel". If we do so, the call to setClientKeysAndTrustedCertificatesPem goes away completely. I'm happy to do this in a separate PR to avoid expanding the scope of this PR.

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 support a separate PR (which I could also do if you want), since I think it will be a user-facing change.

Copy link
Member

Choose a reason for hiding this comment

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

Go for it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we merge this first? There are a lot of cherries on this tree now....

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me

@jack-berg
Copy link
Member

@jkwatson please take a look when you have a chance

@jkwatson
Copy link
Contributor

jkwatson commented Mar 7, 2023

@jkwatson please take a look when you have a chance

seems fine to me. No API changes, so as long as it's working and it seems fine, then I'm totally fine with it.

@jack-berg jack-berg merged commit 895075f into open-telemetry:main Mar 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

3 participants