Skip to content
Closed
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
00c903c
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Oct 23, 2024
b10b3fa
Merge branch 'main' into main
sandy2008 Oct 23, 2024
0d0aa98
feat(): feat: Add certificate handling in HttpClientFactory using X50…
sandy2008 Oct 27, 2024
e7c6f5b
feat(): feat: Add certificate handling in HttpClientFactory using X50…
sandy2008 Oct 27, 2024
3b43fd3
feat(): feat: Add certificate handling in HttpClientFactory using X50…
sandy2008 Oct 27, 2024
4b6d3cd
feat(): feat: Add certificate handling in HttpClientFactory using X50…
sandy2008 Oct 27, 2024
5864dbf
feat(): feat: Add certificate handling in HttpClientFactory using X50…
sandy2008 Oct 27, 2024
0e38ba3
Merge branch 'main' into main
sandy2008 Oct 27, 2024
3733dee
Merge branch 'main' into main
sandy2008 Nov 5, 2024
f09a650
Merge branch 'main' into main
sandy2008 Nov 7, 2024
8630876
Merge branch 'main' into main
sandy2008 Nov 11, 2024
2e7e412
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
afc8df6
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
c5101b1
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
84a4d5b
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
716949c
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
2781534
feat(): Add mTLS Support for OTLP Exporter
sandy2008 Nov 11, 2024
31ef9aa
Merge branch 'main' into main
sandy2008 Nov 13, 2024
9df6f06
Merge branch 'main' into main
sandy2008 Nov 15, 2024
6e940d1
Merge branch 'main' into main
sandy2008 Nov 19, 2024
dc39de9
Merge branch 'main' into main
sandy2008 Nov 24, 2024
2006fbf
Merge branch 'main' into main
sandy2008 Nov 28, 2024
87737eb
Merge branch 'main' into main
sandy2008 Dec 11, 2024
4d56a9a
Merge branch 'main' into main
sandy2008 Dec 13, 2024
c4ec895
Merge branch 'main' into main
rajkumar-rangaraj Dec 16, 2024
0ad1e13
Merge branch 'main' into main
sandy2008 Dec 17, 2024
7a378e6
Merge branch 'main' into main
sandy2008 Dec 19, 2024
6bddb6b
Merge branch 'main' into main
sandy2008 Dec 25, 2024
9b44067
Merge branch 'main' into main
sandy2008 Jan 7, 2025
a0bd2f9
Merge branch 'main' into main
sandy2008 Jan 20, 2025
f9fcd24
Merge branch 'main' into main
sandy2008 Feb 4, 2025
6675646
Merge branch 'main' into main
sandy2008 Feb 12, 2025
9b13d2e
Merge branch 'main' into main
sandy2008 Feb 19, 2025
cb5ccdf
Merge branch 'main' into main
sandy2008 Feb 24, 2025
d71b483
fix(): support new grpc client
sandy2008 Feb 24, 2025
8694bb9
fix(): support new grpc client
sandy2008 Feb 24, 2025
9d6e67a
fix(): support new grpc client
sandy2008 Feb 24, 2025
7aa2ea3
fix(): support new grpc client
sandy2008 Feb 24, 2025
a09e608
fix(): otlp exporter
sandy2008 Feb 24, 2025
e77d6e1
fix(): support new grpc client
sandy2008 Feb 24, 2025
797816c
fix(): support new grpc client
sandy2008 Feb 24, 2025
0691873
fix(): support new grpc client
sandy2008 Feb 24, 2025
8471933
fix(): support new grpc client
sandy2008 Feb 25, 2025
a9c0e90
Merge branch 'main' into main
rajkumar-rangaraj Feb 25, 2025
5beccbf
fix(): support new grpc client
sandy2008 Feb 25, 2025
8a9639f
Merge branch 'main' of https://github.com/sandy2008/opentelemetry-dotnet
sandy2008 Feb 25, 2025
97e2ba5
Merge branch 'main' into main
sandy2008 Mar 4, 2025
c0b25b6
Merge branch 'main' into main
sandy2008 Mar 6, 2025
8d0717c
feat(): remove public apis for certs
sandy2008 Mar 6, 2025
e32eb71
Merge branch 'main' into main
sandy2008 Mar 10, 2025
d01ed8f
Merge branch 'main' into main
sandy2008 Mar 13, 2025
9371340
Merge branch 'main' into main
sandy2008 Mar 17, 2025
1700559
Merge branch 'main' into main
sandy2008 Mar 25, 2025
b0c100f
feat(): mtls support >8.0 only
sandy2008 Mar 25, 2025
3f8f077
Merge branch 'main' of https://github.com/sandy2008/opentelemetry-dotnet
sandy2008 Mar 25, 2025
1dcbcd9
fix(): mtls certs should be internal
sandy2008 Mar 25, 2025
b251110
Merge branch 'main' into main
sandy2008 Apr 1, 2025
ef7db36
Merge branch 'main' into main
sandy2008 Apr 6, 2025
090785f
Merge branch 'main' into main
sandy2008 Apr 9, 2025
6ecc522
Update OtlpExporterOptionsExtensions.cs
sandy2008 Apr 9, 2025
0a2c60d
fix(): resolve conflict for OTel Protocol
sandy2008 Apr 9, 2025
29e4dd5
Merge branch 'main' into main
sandy2008 Apr 17, 2025
cfb0c01
feat(): support for mtls
sandy2008 Apr 18, 2025
45c4525
feat(): support for mtls
sandy2008 Apr 18, 2025
5033c4b
feat(): support for mtls
sandy2008 Apr 18, 2025
350e607
feat(): support for mtls
sandy2008 Apr 18, 2025
d76fccb
feat(): support for mtls
sandy2008 Apr 18, 2025
7ec6a5d
feat(): support for mtls
sandy2008 Apr 18, 2025
fac985e
feat(): support for mtls
sandy2008 Apr 18, 2025
d1d392f
feat(): support for mtls
sandy2008 Apr 18, 2025
0b98744
feat(): support for mtls
sandy2008 Apr 18, 2025
3a4f031
feat(): support for mtls
sandy2008 Apr 18, 2025
91ccacd
fix(): clean up doc
sandy2008 Apr 20, 2025
66eafa0
fix(): clean up doc
sandy2008 Apr 20, 2025
7003fe1
Merge branch 'main' into main
sandy2008 Apr 24, 2025
ea6c940
fix(): clean up codes
sandy2008 Apr 29, 2025
31cfe8d
Merge branch 'main' of https://github.com/sandy2008/opentelemetry-dotnet
sandy2008 Apr 29, 2025
5935f0d
fix(): clean up codes
sandy2008 Apr 29, 2025
4ffba98
fix(): clean up codes
sandy2008 Apr 29, 2025
aeacb87
fix(): clean up codes
sandy2008 Apr 29, 2025
71e19fe
fix(): clean up codes
sandy2008 Apr 29, 2025
76fa366
fix(): clean up codes
sandy2008 Apr 29, 2025
0438284
fix(): clean up codes
sandy2008 Apr 29, 2025
dbd5a05
fix(): clean up codes
sandy2008 Apr 29, 2025
f6e0577
fix(): clean up codes
sandy2008 Apr 29, 2025
6821ad1
fix(): clean up codes
sandy2008 Apr 29, 2025
3eab016
fix(): clean up codes
sandy2008 Apr 30, 2025
0b0e0c9
fix(): clean up codes
sandy2008 Apr 30, 2025
d4469f9
fix(): clean up codes
sandy2008 Apr 30, 2025
f56dc6e
Merge branch 'main' into main
sandy2008 Apr 30, 2025
4a50f64
fix(): clean up codes
sandy2008 Apr 30, 2025
b817179
Merge branch 'main' of https://github.com/sandy2008/opentelemetry-dotnet
sandy2008 Apr 30, 2025
fc41e6a
fix(): clean up codes
sandy2008 Apr 30, 2025
a69ed31
fix(): clean up codes
sandy2008 Apr 30, 2025
a27780f
fix(): clean up codes
sandy2008 Apr 30, 2025
7898d99
fix(): clean up codes
sandy2008 Apr 30, 2025
dce4bae
fix(): clean up codes
sandy2008 Apr 30, 2025
ca70e55
fix(): clean up codes
sandy2008 Apr 30, 2025
7c611b7
fix(): clean up codes
sandy2008 Apr 30, 2025
0ee5513
fix(): clean up codes
sandy2008 Apr 30, 2025
88a9f7f
fix(): clean up codes
sandy2008 Apr 30, 2025
1ecabf1
fix(): clean up codes
sandy2008 Apr 30, 2025
5d9751c
fix(): clean up codes
sandy2008 Apr 30, 2025
fc90786
Merge branch 'main' into main
sandy2008 May 14, 2025
b7c34cd
Merge branch 'main' into main
sandy2008 May 21, 2025
72912c2
fix(): fix unit test
sandy2008 May 23, 2025
0571af8
Merge branch 'main' of https://github.com/sandy2008/opentelemetry-dotnet
sandy2008 May 23, 2025
777f530
fix(): fix unit test
sandy2008 May 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OpenTelemetry.Exporter.OtlpExporterOptions.CertificateFile.get -> string!
OpenTelemetry.Exporter.OtlpExporterOptions.CertificateFile.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ClientCertificateFile.get -> string!
OpenTelemetry.Exporter.OtlpExporterOptions.ClientCertificateFile.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ClientKeyFile.get -> string!
OpenTelemetry.Exporter.OtlpExporterOptions.ClientKeyFile.set -> void
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
using OpenTelemetry.Internal;
using OpenTelemetry.Trace;
#if NET6_0_OR_GREATER
using System.Security.Cryptography.X509Certificates;
#endif

namespace OpenTelemetry.Exporter;

Expand All @@ -28,6 +31,10 @@ public class OtlpExporterOptions : IOtlpExporterOptions
internal const string DefaultHttpEndpoint = "http://localhost:4318";
internal const OtlpExportProtocol DefaultOtlpExportProtocol = OtlpExportProtocol.Grpc;

internal const string CertificateFileEnvVarName = "OTEL_EXPORTER_OTLP_CERTIFICATE";
internal const string ClientKeyFileEnvVarName = "OTEL_EXPORTER_OTLP_CLIENT_KEY";
internal const string ClientCertificateFileEnvVarName = "OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE";

internal static readonly KeyValuePair<string, string>[] StandardHeaders = new KeyValuePair<string, string>[]
{
new("User-Agent", GetUserAgentString()),
Expand Down Expand Up @@ -68,13 +75,26 @@ internal OtlpExporterOptions(

this.DefaultHttpClientFactory = () =>
{
#if NET6_0_OR_GREATER
var handler = new HttpClientHandler();
HttpClient client = this.AddCertificatesToHttpClient(handler);
client.Timeout = TimeSpan.FromMilliseconds(this.TimeoutMilliseconds);
return client;
#else
// For earlier .NET versions
return new HttpClient
{
Timeout = TimeSpan.FromMilliseconds(this.TimeoutMilliseconds),
};
#endif
};

this.BatchExportProcessorOptions = defaultBatchOptions!;

// Load certificate-related environment variables
this.CertificateFile = Environment.GetEnvironmentVariable(CertificateFileEnvVarName) ?? string.Empty;
this.ClientKeyFile = Environment.GetEnvironmentVariable(ClientKeyFileEnvVarName) ?? string.Empty;
this.ClientCertificateFile = Environment.GetEnvironmentVariable(ClientCertificateFileEnvVarName) ?? string.Empty;
}

/// <inheritdoc/>
Expand Down Expand Up @@ -142,6 +162,21 @@ public Func<HttpClient> HttpClientFactory
}
}

/// <summary>
/// Gets or sets the trusted certificate to use when verifying a server's TLS credentials.
/// </summary>
public string CertificateFile { get; set; }

/// <summary>
/// Gets or sets the path to the private key to use in mTLS communication in PEM format.
/// </summary>
public string ClientKeyFile { get; set; }

/// <summary>
/// Gets or sets the path to the certificate/chain trust for client's private key to use in mTLS communication in PEM format.
/// </summary>
public string ClientCertificateFile { get; set; }

/// <summary>
/// Gets a value indicating whether or not the signal-specific path should
/// be appended to <see cref="Endpoint"/>.
Expand Down Expand Up @@ -220,6 +255,41 @@ internal OtlpExporterOptions ApplyDefaults(OtlpExporterOptions defaultExporterOp
return this;
}

#if NET6_0_OR_GREATER
internal HttpClient AddCertificatesToHttpClient(HttpClientHandler handler)
Copy link
Member

Choose a reason for hiding this comment

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

How you plan to handle errors within this method?

{
// Configure server certificate validation if CertificateFile is provided
if (!string.IsNullOrEmpty(this.CertificateFile))
{
// Load the certificate from the file
var trustedCertificate = X509Certificate2.CreateFromPemFile(this.CertificateFile);
Copy link
Member

Choose a reason for hiding this comment

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

The implementation does not verify if CertificateFile, ClientCertificateFile, or ClientKeyFile exist before attempting to load them.


// Set custom server certificate validation callback
handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
Copy link
Member

Choose a reason for hiding this comment

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

Using a custom server certificate validation callback can introduce security risks if not handled properly. Can you list what measures have been taken to mitigate potential risks, such as unintended trust, proper error handling, revocation checks, and restricting trust scope?

{
if (cert != null && chain != null)
{
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
chain.ChainPolicy.CustomTrustStore.Add(trustedCertificate);
return chain.Build(cert);
Copy link
Member

Choose a reason for hiding this comment

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

chain.Build(cert) might fail if the certificate chain is incomplete or missing necessary intermediate certificates. Consider checking chain.ChainStatus for errors before returning true. Also, logging failures can help diagnose why validation failed

}

return false;
};
}

// Add client certificate if both files are provided
if (!string.IsNullOrEmpty(this.ClientCertificateFile) && !string.IsNullOrEmpty(this.ClientKeyFile))
{
var clientCertificate = X509Certificate2.CreateFromPemFile(this.ClientCertificateFile, this.ClientKeyFile);
Copy link
Member

Choose a reason for hiding this comment

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

Loading a client certificate from a PEM file with a private key should be done cautiously. How do you ensure or inform customers that the private key file should be stored securely and access-restricted?

handler.ClientCertificates.Add(clientCertificate);
}

// Create and return an HttpClient with the modified handler
return new HttpClient(handler);
}
#endif

private static string GetUserAgentString()
{
var assembly = typeof(OtlpExporterOptions).Assembly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,30 @@ public static Channel CreateChannel(this OtlpExporterOptions options)
ChannelCredentials channelCredentials;
if (options.Endpoint.Scheme == Uri.UriSchemeHttps)
{
channelCredentials = new SslCredentials();
if (!string.IsNullOrEmpty(options.ClientCertificateFile) && !string.IsNullOrEmpty(options.ClientKeyFile))
{
string clientCertPem = File.ReadAllText(options.ClientCertificateFile);
string clientKeyPem = File.ReadAllText(options.ClientKeyFile);
var keyPair = new KeyCertificatePair(clientCertPem, clientKeyPem);

string rootCertPem = string.Empty;
if (!string.IsNullOrEmpty(options.CertificateFile))
{
rootCertPem = File.ReadAllText(options.CertificateFile);
}

channelCredentials = new SslCredentials(rootCertPem, keyPair);
}
else
{
string rootCertPem = string.Empty;
if (!string.IsNullOrEmpty(options.CertificateFile))
{
rootCertPem = File.ReadAllText(options.CertificateFile);
}

channelCredentials = new SslCredentials(rootCertPem);
}
}
else
{
Expand Down
Loading