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

OtlpExporter: Integration test testing https support #1795

Closed
wants to merge 23 commits into from

Conversation

alanwest
Copy link
Member

@alanwest alanwest commented Feb 5, 2021

Based on the conversation in #1778, I think it may be safe to re-enable TLS support for the simple case.

We use two gRPC libraries

1. Google gRPC library (used for apps prior to .NET Core 3.0)

If the scheme is https then the channel is constructed with new SslCredentials().

Documentation of SslCredentials states:

Creates client-side SSL credentials loaded from disk file pointed to by the GRPC_DEFAULT_SSL_ROOTS_FILE_PATH environment variable. If that fails, gets the roots certificates from a well known place on disk.

2. gRPC .NET (used for apps supporting netstandard2.1)

gRPC channel can be constructed from a Uri with an https scheme, so I think TLS will just work.

I think this is enough to get us basic support for TLS over http. The spec still has some in-flight changes to configuration options that may allow us to provide a more flexible solution in the future. Also, support for unix sockets could come later too.

I'm going to try to expand the integration tests we have for the OtlpExporter to vet out these changes to ensure TLS works as I expect.

@alanwest alanwest requested a review from a team as a code owner February 5, 2021 02:48
@codecov
Copy link

codecov bot commented Feb 5, 2021

Codecov Report

Merging #1795 (9d812d0) into main (90d2906) will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1795      +/-   ##
==========================================
- Coverage   79.71%   79.70%   -0.02%     
==========================================
  Files         254      254              
  Lines        8404     8404              
==========================================
- Hits         6699     6698       -1     
- Misses       1705     1706       +1     
Impacted Files Coverage Δ
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 71.96% <0.00%> (-1.87%) ⬇️
...Telemetry/Internal/SelfDiagnosticsEventListener.cs 96.85% <0.00%> (-0.79%) ⬇️
...emetry.Api/Internal/OpenTelemetryApiEventSource.cs 82.35% <0.00%> (+5.88%) ⬆️

{
throw new NotSupportedException("Https Endpoint is not supported.");
throw new NotSupportedException($"Endpoint URI scheme ({options.Endpoint.Scheme}) is not supported.");
}

#if NETSTANDARD2_1
this.channel = GrpcChannel.ForAddress(options.Endpoint);
Copy link
Member

Choose a reason for hiding this comment

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

From https://docs.microsoft.com/en-us/aspnet/core/grpc/client?view=aspnetcore-5.0#configure-tls
To configure a gRPC channel to use TLS, ensure the server address starts with https. For example, GrpcChannel.ForAddress("https://localhost:5001") uses HTTPS protocol. The gRPC channel automatically negotiates a connection secured by TLS and uses a secure connection to make gRPC calls.

Copy link
Member

@cijothomas cijothomas 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.
Not explicitly approving, as we are trying to add integration test for secure connection

@cijothomas
Copy link
Member

@pjanotti @CodeBlanch @reyang @pcwiese Please help review.

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

LGTM.

ChannelCredentials channelCredentials;
if (options.Endpoint.Scheme == Uri.UriSchemeHttps)
{
channelCredentials = new SslCredentials();
Copy link
Contributor

@pcwiese pcwiese Feb 5, 2021

Choose a reason for hiding this comment

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

So those that want a secure channel I guess would specify the cert path via the environment variable? If so this seems like it would work for the simple case. I hope the additional tests prove this out and this gets into 1.0!

LGTM also.

Copy link
Member

Choose a reason for hiding this comment

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

https://grpc.github.io/grpc/csharp/api/Grpc.Core.SslCredentials.html#Grpc_Core_SslCredentials__ctor
We shouldn't recommend customers to rely on this env variable. Its an implementation detail that it works, so they shouldn't bet on it.

Instead, the actual environment variable, as per otel spec should be added in 1.1.

Copy link
Contributor

Choose a reason for hiding this comment

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

Make sense.

Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

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

LGTM.

Comment on lines +43 to +44
// TODO: Should test both http and https
Endpoint = new System.Uri($"https://{CollectorEndpoint}"),
Copy link
Member Author

Choose a reason for hiding this comment

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

Just to vet out https support, I just changed the test to use https. I plan to follow up and have it test both.

Copy link
Member

Choose a reason for hiding this comment

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

If we use a self-signed cert might need to manually pass validation somehow?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we use a self-signed cert might need to manually pass validation somehow?

The cert gets installed as a trusted cert here, so no need to manually pass validation:

RUN apt-get update && apt-get install ca-certificates
COPY --from=build /repo/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/otel-collector-config/otel-collector.crt /usr/local/share/ca-certificates/
RUN update-ca-certificates --verbose

I had actually tried this first:

ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, policyErrors) => true;

For some reason this did not work... I've used this kind of thing in test applications before, but for some reason the callback was not getting invoked by the test.

Copy link
Member

Choose a reason for hiding this comment

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

ServicePointManager.ServerCertificateValidationCallback doesn't work for the Google library or .NET or both? I'm not too surprised if it doesn't work in the Google library. .NET would be more of a surprise 😄

@cijothomas
Copy link
Member

Related to this area in spec: open-telemetry/opentelemetry-specification#1426

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

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

LGTM

@alanwest alanwest changed the title OtlpExporter: Enable support for both http and https OtlpExporter: Integration test testing https support Mar 6, 2021
@alanwest
Copy link
Member Author

@cijothomas I think this is good to go. I had one comment that could be followed up on about expanding this test to test both http and https.

@github-actions
Copy link
Contributor

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

@github-actions github-actions bot added the Stale label Jan 28, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2022

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Feb 5, 2022
@alanwest alanwest deleted the alanwest/otlp-allow-tls branch February 23, 2022 19:40
@alanwest alanwest restored the alanwest/otlp-allow-tls branch July 31, 2023 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants