-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement(enterprise): hide secrets when enterprise mode is enabled (…
…#14305) * create sensitive string struct Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace api key for datadog logs sink by sensitive string Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace api key for datadog metrics sink by sensitive string Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace api key for datadog traces sink by sensitive string Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace api key for datadog events sink by sensitive string Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace api key for apex sink by sensitive string Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace access key and secret access key for aws auth by sensitive string Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in azure_blob sink Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in es, axiom, logdna, websocket sinks Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in humio and splunk_hec sinks Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in influxdb sink Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in kafka sink Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in new_relic sink Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in sematext sinks Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in splunk_hec metric sink Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in axiom sink Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in azure_monitor_logs sink Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in honeycomb sink Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in logdna sink Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in nats sink Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in pulsar sink Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in aws_kinesis_firehose source Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in splunk_hec source Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in gcp source Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * replace keys by sensitive string in heroku_logs source Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * fix integration tests Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * apply clippy suggestions Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * apply requested fixes Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> * make SensitiveString as configurable Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com> Signed-off-by: Jeremie Drouet <jeremie.drouet@datadoghq.com>
- Loading branch information
Showing
51 changed files
with
308 additions
and
157 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use vector_config::{configurable_component, ConfigurableString}; | ||
|
||
/// Wrapper for sensitive strings containing credentials | ||
#[configurable_component(no_deser, no_ser)] | ||
#[cfg_attr( | ||
feature = "serde", | ||
derive(::serde::Deserialize, ::serde::Serialize), | ||
serde(from = "String", into = "String") | ||
)] | ||
#[configurable(metadata(sensitive))] | ||
#[derive(Clone, Default, PartialEq, Eq)] | ||
pub struct SensitiveString(String); | ||
|
||
impl From<String> for SensitiveString { | ||
fn from(value: String) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl From<SensitiveString> for String { | ||
fn from(value: SensitiveString) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl ConfigurableString for SensitiveString {} | ||
|
||
impl std::fmt::Display for SensitiveString { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "**REDACTED**") | ||
} | ||
} | ||
|
||
impl std::fmt::Debug for SensitiveString { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
// we keep the double quotes here to keep the String behavior | ||
write!(f, "\"**REDACTED**\"") | ||
} | ||
} | ||
|
||
impl SensitiveString { | ||
#[must_use] | ||
pub fn inner(&self) -> &str { | ||
self.0.as_str() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn serialization() { | ||
let json_value = "\"foo\""; | ||
let value: SensitiveString = serde_json::from_str(json_value).unwrap(); | ||
let result: String = serde_json::to_string(&value).unwrap(); | ||
assert_eq!(result, json_value); | ||
} | ||
|
||
#[test] | ||
fn hide_content() { | ||
let value = SensitiveString("hello world".to_string()); | ||
let display = format!("{}", value); | ||
assert_eq!(display, "**REDACTED**"); | ||
let debug = format!("{:?}", value); | ||
assert_eq!(debug, "\"**REDACTED**\""); | ||
} | ||
} |
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
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
Oops, something went wrong.