From 01537107917be93cad295b257dd8278daa43d1dc Mon Sep 17 00:00:00 2001 From: Henry Guo Date: Tue, 5 May 2026 11:44:07 +0800 Subject: [PATCH] fix(server): avoid logging default credential values (#2800) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: houseme Co-authored-by: Claude Sonnet 4.6 Co-authored-by: loverustfs Co-authored-by: 安正超 --- rustfs/src/main.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/rustfs/src/main.rs b/rustfs/src/main.rs index f8634abc2..b4d1f387c 100644 --- a/rustfs/src/main.rs +++ b/rustfs/src/main.rs @@ -138,6 +138,9 @@ fn is_using_default_credentials(config: &rustfs::config::Config) -> bool { rustfs_credentials::DEFAULT_ACCESS_KEY.eq(&config.access_key) && rustfs_credentials::DEFAULT_SECRET_KEY.eq(&config.secret_key) } +const DEFAULT_CREDENTIALS_WARNING_MESSAGE: &str = + "Detected default root credentials; change them with the RUSTFS_ACCESS_KEY and RUSTFS_SECRET_KEY environment variables"; + async fn async_main() -> Result<()> { // Parse command line arguments let args: Vec = std::env::args().collect(); @@ -355,11 +358,7 @@ async fn run(config: rustfs::config::Config) -> Result<()> { }; if is_using_default_credentials(&config) { - warn!( - "Detected default credentials '{}:{}', we recommend that you change these values with 'RUSTFS_ACCESS_KEY' and 'RUSTFS_SECRET_KEY' environment variables", - rustfs_credentials::DEFAULT_ACCESS_KEY, - rustfs_credentials::DEFAULT_SECRET_KEY - ); + warn!("{}", DEFAULT_CREDENTIALS_WARNING_MESSAGE); } let ctx = CancellationToken::new(); @@ -780,4 +779,14 @@ mod tests { assert!(!is_using_default_credentials(&config)); } + + #[test] + fn default_credentials_warning_message_does_not_expose_values() { + let message = DEFAULT_CREDENTIALS_WARNING_MESSAGE; + + assert!(message.contains(rustfs_config::ENV_RUSTFS_ACCESS_KEY)); + assert!(message.contains(rustfs_config::ENV_RUSTFS_SECRET_KEY)); + assert!(!message.contains(rustfs_credentials::DEFAULT_ACCESS_KEY)); + assert!(!message.contains(rustfs_credentials::DEFAULT_SECRET_KEY)); + } }