-
Notifications
You must be signed in to change notification settings - Fork 474
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
feat: configure TLS with environment variables. #2465
Open
jvanz
wants to merge
4
commits into
open-telemetry:main
Choose a base branch
from
jvanz:tls-envvars
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,19 @@ | |
/// Compression algorithm to use, defaults to none. | ||
pub const OTEL_EXPORTER_OTLP_COMPRESSION: &str = "OTEL_EXPORTER_OTLP_COMPRESSION"; | ||
|
||
/// Certificate file to validate the OTLP server connection | ||
#[cfg(feature = "tls")] | ||
pub const OTEL_EXPORTER_OTLP_CERTIFICATE: &str = "OTEL_EXPORTER_OTLP_CERTIFICATE"; | ||
/// Path to the certificate file to use for client authentication (mTLS). | ||
#[cfg(feature = "tls")] | ||
pub const OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: &str = "OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE"; | ||
/// Path to the key file to use for client authentication (mTLS). | ||
#[cfg(feature = "tls")] | ||
pub const OTEL_EXPORTER_OTLP_CLIENT_KEY: &str = "OTEL_EXPORTER_OTLP_CLIENT_KEY"; | ||
/// Use insecure connection. Disable TLS | ||
#[cfg(feature = "tls")] | ||
pub const OTEL_EXPORTER_OTLP_INSECURE: &str = "OTEL_EXPORTER_OTLP_INSECURE"; | ||
|
||
#[cfg(feature = "http-json")] | ||
/// Default protocol, using http-json. | ||
pub const OTEL_EXPORTER_OTLP_PROTOCOL_DEFAULT: &str = OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_JSON; | ||
|
@@ -76,6 +89,22 @@ | |
|
||
/// The timeout to the collector. | ||
pub timeout: Duration, | ||
|
||
/// Disable TLS | ||
#[cfg(feature = "tls")] | ||
pub insecure: Option<bool>, | ||
|
||
/// The certificate file to validate the OTLP server connection | ||
#[cfg(feature = "tls")] | ||
pub certificate: Option<String>, | ||
|
||
/// The path to the certificate file to use for client authentication (mTLS). | ||
#[cfg(feature = "tls")] | ||
pub client_certificate: Option<String>, | ||
|
||
/// The path to the key file to use for client authentication (mTLS). | ||
#[cfg(feature = "tls")] | ||
pub client_key: Option<String>, | ||
} | ||
|
||
impl Default for ExportConfig { | ||
|
@@ -88,6 +117,14 @@ | |
// won't know if user provided a value | ||
protocol, | ||
timeout: Duration::from_secs(OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT), | ||
#[cfg(feature = "tls")] | ||
insecure: None, | ||
#[cfg(feature = "tls")] | ||
certificate: None, | ||
#[cfg(feature = "tls")] | ||
client_certificate: None, | ||
#[cfg(feature = "tls")] | ||
client_key: None, | ||
} | ||
} | ||
} | ||
|
@@ -195,6 +232,21 @@ | |
fn with_timeout(self, timeout: Duration) -> Self; | ||
/// Set export config. This will override all previous configuration. | ||
fn with_export_config(self, export_config: ExportConfig) -> Self; | ||
/// Set insecure connection. Disable TLS | ||
#[cfg(feature = "tls")] | ||
fn with_insecure(self) -> Self; | ||
/// Set the certificate file to validate the OTLP server connection | ||
/// This is only available when the `tls` feature is enabled. | ||
#[cfg(feature = "tls")] | ||
fn with_certificate<T: Into<String>>(self, certificate: T) -> Self; | ||
jvanz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Set the path to the certificate file to use for client authentication (mTLS). | ||
/// This is only available when the `tls` feature is enabled. | ||
#[cfg(feature = "tls")] | ||
fn with_client_certificate<T: Into<String>>(self, client_certificate: T) -> Self; | ||
/// Set the path to the key file to use for client authentication (mTLS). | ||
/// This is only available when the `tls` feature is enabled. | ||
#[cfg(feature = "tls")] | ||
fn with_client_key<T: Into<String>>(self, client_key: T) -> Self; | ||
} | ||
|
||
impl<B: HasExportConfig> WithExportConfig for B { | ||
|
@@ -217,6 +269,34 @@ | |
self.export_config().endpoint = exporter_config.endpoint; | ||
self.export_config().protocol = exporter_config.protocol; | ||
self.export_config().timeout = exporter_config.timeout; | ||
#[cfg(feature = "tls")] | ||
{ | ||
self.export_config().insecure = Some(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per the specs, the connection should be secure by default.
|
||
} | ||
self | ||
} | ||
|
||
#[cfg(feature = "tls")] | ||
fn with_insecure(mut self) -> Self { | ||
self.export_config().insecure = Some(true); | ||
self | ||
} | ||
|
||
#[cfg(feature = "tls")] | ||
fn with_certificate<T: Into<String>>(mut self, certificate: T) -> Self { | ||
self.export_config().certificate = Some(certificate.into()); | ||
self | ||
} | ||
|
||
#[cfg(feature = "tls")] | ||
fn with_client_certificate<T: Into<String>>(mut self, client_certificate: T) -> Self { | ||
self.export_config().client_certificate = Some(client_certificate.into()); | ||
self | ||
} | ||
|
||
#[cfg(feature = "tls")] | ||
fn with_client_key<T: Into<String>>(mut self, client_key: T) -> Self { | ||
self.export_config().client_key = Some(client_key.into()); | ||
self | ||
} | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
tls
feature flag is specific togrpc-tonic
. Just to be clear -this PR is only adding TLS support forgrpc
, and nothttp
?