mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-07-06 14:00:40 +00:00
fix: redact Kafka SASL password in debug output (#8337)
## Summary - Mask `KafkaClientSaslConfig` password fields in debug output while keeping usernames visible. - Cover metasrv WAL debug output with a regression test. ## Files - `src/common/wal/src/config/kafka/common.rs` - `src/common/wal/src/config.rs` Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
This commit is contained in:
@@ -268,4 +268,26 @@ mod tests {
|
||||
};
|
||||
assert_eq!(datanode_wal_config, DatanodeWalConfig::Kafka(expected));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_kafka_wal_config_debug_redacts_password() {
|
||||
let config = MetasrvWalConfig::Kafka(MetasrvKafkaConfig {
|
||||
connection: KafkaConnectionConfig {
|
||||
sasl: Some(KafkaClientSasl {
|
||||
config: KafkaClientSaslConfig::Plain {
|
||||
username: "greptime".to_string(),
|
||||
password: "kafka-secret".to_string(),
|
||||
},
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let debug = format!("{config:#?}");
|
||||
|
||||
assert!(debug.contains("greptime"));
|
||||
assert!(debug.contains("<REDACTED>"));
|
||||
assert!(!debug.contains("kafka-secret"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::fmt;
|
||||
use std::io::Cursor;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
@@ -63,7 +64,7 @@ pub struct KafkaClientSasl {
|
||||
pub config: KafkaClientSaslConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(tag = "type", rename_all = "SCREAMING-KEBAB-CASE")]
|
||||
pub enum KafkaClientSaslConfig {
|
||||
Plain {
|
||||
@@ -82,6 +83,28 @@ pub enum KafkaClientSaslConfig {
|
||||
},
|
||||
}
|
||||
|
||||
impl fmt::Debug for KafkaClientSaslConfig {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
KafkaClientSaslConfig::Plain { username, .. } => f
|
||||
.debug_struct("Plain")
|
||||
.field("username", username)
|
||||
.field("password", &"<REDACTED>")
|
||||
.finish(),
|
||||
KafkaClientSaslConfig::ScramSha256 { username, .. } => f
|
||||
.debug_struct("ScramSha256")
|
||||
.field("username", username)
|
||||
.field("password", &"<REDACTED>")
|
||||
.finish(),
|
||||
KafkaClientSaslConfig::ScramSha512 { username, .. } => f
|
||||
.debug_struct("ScramSha512")
|
||||
.field("username", username)
|
||||
.field("password", &"<REDACTED>")
|
||||
.finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KafkaClientSaslConfig {
|
||||
/// Converts to [`SaslConfig`].
|
||||
pub fn into_sasl_config(self) -> SaslConfig {
|
||||
|
||||
Reference in New Issue
Block a user