Skip to content

Commit b67f2ef

Browse files
committed
feat(): add mtls support
1 parent 04d30c9 commit b67f2ef

File tree

9 files changed

+226
-265
lines changed

9 files changed

+226
-265
lines changed
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
OpenTelemetry.Exporter.OtlpExporterOptions.MtlsOptions.get -> OpenTelemetry.Exporter.OtlpMtlsOptions?
2-
OpenTelemetry.Exporter.OtlpExporterOptions.MtlsOptions.set -> void
3-
OpenTelemetry.Exporter.OtlpMtlsOptions
4-
OpenTelemetry.Exporter.OtlpMtlsOptions.CaCertificatePath.get -> string?
5-
OpenTelemetry.Exporter.OtlpMtlsOptions.CaCertificatePath.set -> void
6-
OpenTelemetry.Exporter.OtlpMtlsOptions.ClientCertificatePath.get -> string?
7-
OpenTelemetry.Exporter.OtlpMtlsOptions.ClientCertificatePath.set -> void
8-
OpenTelemetry.Exporter.OtlpMtlsOptions.ClientKeyPath.get -> string?
9-
OpenTelemetry.Exporter.OtlpMtlsOptions.ClientKeyPath.set -> void
10-
OpenTelemetry.Exporter.OtlpMtlsOptions.EnableCertificateChainValidation.get -> bool
11-
OpenTelemetry.Exporter.OtlpMtlsOptions.EnableCertificateChainValidation.set -> void
12-
OpenTelemetry.Exporter.OtlpMtlsOptions.EnableFilePermissionChecks.get -> bool
13-
OpenTelemetry.Exporter.OtlpMtlsOptions.EnableFilePermissionChecks.set -> void
14-
OpenTelemetry.Exporter.OtlpMtlsOptions.IsEnabled.get -> bool
15-
OpenTelemetry.Exporter.OtlpMtlsOptions.OtlpMtlsOptions() -> void
16-
OpenTelemetry.Exporter.OtlpMtlsOptions.ServerCertificateValidationCallback.get -> System.Func<System.Security.Cryptography.X509Certificates.X509Certificate2!, System.Security.Cryptography.X509Certificates.X509Chain!, System.Net.Security.SslPolicyErrors, bool>?
17-
OpenTelemetry.Exporter.OtlpMtlsOptions.ServerCertificateValidationCallback.set -> void
1+

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpMtlsHttpClientFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public static HttpClient CreateMtlsHttpClient(
7272
}
7373

7474
// Create HttpClientHandler with mTLS configuration
75+
#pragma warning disable CA2000 // Dispose objects before losing scope - HttpClientHandler is disposed by HttpClient
7576
handler = new HttpClientHandler { CheckCertificateRevocationList = true };
77+
#pragma warning restore CA2000
7678

7779
// Add client certificate if available
7880
if (clientCertificate != null)
@@ -138,6 +140,10 @@ public static HttpClient CreateMtlsHttpClient(
138140
// Dispose the base client as we're not using it
139141
baseClient.Dispose();
140142

143+
// Dispose certificates as they are no longer needed after being added to the handler
144+
caCertificate?.Dispose();
145+
clientCertificate?.Dispose();
146+
141147
return mtlsClient;
142148
}
143149
catch (Exception ex)

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,6 @@ public OtlpExportProtocol Protocol
154154
/// <remarks>Note: This only applies when exporting traces.</remarks>
155155
public BatchExportProcessorOptions<Activity> BatchExportProcessorOptions { get; set; }
156156

157-
#if NET8_0_OR_GREATER
158-
/// <summary>
159-
/// Gets or sets the mTLS (mutual TLS) configuration options.
160-
/// This property is only available on .NET 8.0 and later versions.
161-
/// </summary>
162-
public OtlpMtlsOptions? MtlsOptions { get; set; }
163-
#endif
164-
165157
/// <inheritdoc/>
166158
public Func<HttpClient> HttpClientFactory
167159
{
@@ -184,6 +176,14 @@ public Func<HttpClient> HttpClientFactory
184176
/// </remarks>
185177
internal bool AppendSignalPathToEndpoint { get; private set; } = true;
186178

179+
#if NET8_0_OR_GREATER
180+
/// <summary>
181+
/// Gets or sets the mTLS (mutual TLS) configuration options.
182+
/// This property is only available on .NET 8.0 and later versions.
183+
/// </summary>
184+
internal OtlpMtlsOptions? MtlsOptions { get; set; }
185+
#endif
186+
187187
internal bool HasData
188188
=> this.protocol.HasValue
189189
|| this.endpoint != null

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMtlsOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace OpenTelemetry.Exporter;
1414
/// <remarks>
1515
/// This class is only available on .NET 8.0 and later versions.
1616
/// </remarks>
17-
public class OtlpMtlsOptions
17+
internal class OtlpMtlsOptions
1818
{
1919
/// <summary>
2020
/// Gets or sets the path to the CA certificate file in PEM format.

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Implementation/OtlpMtlsHttpClientFactoryTests.cs

Lines changed: 0 additions & 162 deletions
This file was deleted.

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Integration/OtlpMtlsIntegrationTests.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)