Repository navigation
[13.1] Use WithHttpsCertificateConfiguration to configure tls cert for Otel Collector
#1058
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,42 +34,20 @@ public static IResourceBuilder<OpenTelemetryCollectorResource> AddOpenTelemetryC | |||||||||
| var settings = new OpenTelemetryCollectorSettings(); | ||||||||||
| configureSettings?.Invoke(settings); | ||||||||||
|
|
||||||||||
| var isHttpsEnabled = !settings.ForceNonSecureReceiver && url.StartsWith("https", StringComparison.OrdinalIgnoreCase); | ||||||||||
|
|
||||||||||
| var resource = new OpenTelemetryCollectorResource(name); | ||||||||||
| var resourceBuilder = builder.AddResource(resource) | ||||||||||
| .WithImage(settings.CollectorImage, settings.CollectorTag) | ||||||||||
| .WithEnvironment("ASPIRE_ENDPOINT", new HostUrl(url)) | ||||||||||
| .WithEnvironment("ASPIRE_API_KEY", builder.Configuration[DashboardOtlpApiKeyVariableName]) | ||||||||||
| .WithIconName("DesktopPulse"); | ||||||||||
|
|
||||||||||
| if (settings.EnableGrpcEndpoint) | ||||||||||
| resourceBuilder.WithEndpoint(targetPort: 4317, name: OpenTelemetryCollectorResource.GrpcEndpointName, scheme: isHttpsEnabled ? "https" : "http"); | ||||||||||
| if (settings.EnableHttpEndpoint) | ||||||||||
| resourceBuilder.WithEndpoint(targetPort: 4318, name: OpenTelemetryCollectorResource.HttpEndpointName, scheme: isHttpsEnabled ? "https" : "http"); | ||||||||||
|
|
||||||||||
|
|
||||||||||
| if (!settings.ForceNonSecureReceiver && isHttpsEnabled && builder.ExecutionContext.IsRunMode) | ||||||||||
| { | ||||||||||
| resourceBuilder.RunWithHttpsDevCertificate(); | ||||||||||
| var useHttpsForReceivers = !settings.ForceNonSecureReceiver && url.StartsWith("https", StringComparison.OrdinalIgnoreCase); | ||||||||||
|
|
||||||||||
| // Not using `Path.Combine` as we MUST use unix style paths in the container | ||||||||||
| var certFilePath = $"{DevCertHostingExtensions.DEV_CERT_BIND_MOUNT_DEST_DIR}/{DevCertHostingExtensions.CERT_FILE_NAME}"; | ||||||||||
| var certKeyPath = $"{DevCertHostingExtensions.DEV_CERT_BIND_MOUNT_DEST_DIR}/{DevCertHostingExtensions.CERT_KEY_FILE_NAME}"; | ||||||||||
| if (settings.EnableGrpcEndpoint) | ||||||||||
| ConfigureReceiver(4317, OpenTelemetryCollectorResource.GrpcEndpointName); | ||||||||||
|
|
||||||||||
| if (settings.EnableHttpEndpoint) | ||||||||||
| { | ||||||||||
| resourceBuilder.WithArgs( | ||||||||||
| $@"--config=yaml:receivers::otlp::protocols::http::tls::cert_file: ""{certFilePath}""", | ||||||||||
| $@"--config=yaml:receivers::otlp::protocols::http::tls::key_file: ""{certKeyPath}"""); | ||||||||||
| } | ||||||||||
| if (settings.EnableGrpcEndpoint) | ||||||||||
| { | ||||||||||
| resourceBuilder.WithArgs( | ||||||||||
| $@"--config=yaml:receivers::otlp::protocols::grpc::tls::cert_file: ""{certFilePath}""", | ||||||||||
| $@"--config=yaml:receivers::otlp::protocols::grpc::tls::key_file: ""{certKeyPath}"""); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| if (settings.EnableHttpEndpoint) | ||||||||||
| ConfigureReceiver(4318, OpenTelemetryCollectorResource.HttpEndpointName); | ||||||||||
|
|
||||||||||
| if (!settings.DisableHealthcheck) | ||||||||||
| { | ||||||||||
|
|
@@ -83,6 +61,26 @@ public static IResourceBuilder<OpenTelemetryCollectorResource> AddOpenTelemetryC | |||||||||
| ); | ||||||||||
| } | ||||||||||
| return resourceBuilder; | ||||||||||
|
|
||||||||||
| void ConfigureReceiver(int port, string protocol) | ||||||||||
| { | ||||||||||
| var scheme = useHttpsForReceivers ? "https" : "http"; | ||||||||||
| resourceBuilder.WithEndpoint(targetPort: port, name: protocol, scheme: scheme); | ||||||||||
|
|
||||||||||
| if (!useHttpsForReceivers) | ||||||||||
| { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||||||||||
| resourceBuilder.WithHttpsCertificateConfiguration(ctx => | ||||||||||
| { | ||||||||||
| ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::cert_file: ""{ctx.CertificatePath}""")); | ||||||||||
| ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::key_file: ""{ctx.KeyPath}""")); | ||||||||||
|
Comment on lines
+78
to
+79
|
||||||||||
| ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::cert_file: ""{ctx.CertificatePath}""")); | |
| ctx.Arguments.Add(ReferenceExpression.Create($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::key_file: ""{ctx.KeyPath}""")); | |
| ctx.Arguments.Add($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::cert_file: ""{ctx.CertificatePath}"""); | |
| ctx.Arguments.Add($@"--config=yaml:receivers::otlp::protocols::{protocol}::tls::key_file: ""{ctx.KeyPath}"""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReferenceExpression is absolutely required here as certificate and key paths cannot be resolve until after the app host starts.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default 'ToString()': ReferenceExpression inherits 'ToString()' from 'Object', and so is not suitable for printing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReferenceExpressionis absolutely required here as certificate and key paths cannot be resolve until after the app host starts.