fix(server): avoid logging default credential values (#2800)

Co-authored-by: houseme <housemecn@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: loverustfs <hello@rustfs.com>
Co-authored-by: 安正超 <anzhengchao@gmail.com>
This commit is contained in:
Henry Guo
2026-05-05 11:44:07 +08:00
committed by GitHub
parent 995e26f5ee
commit 0153710791
+14 -5
View File
@@ -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<String> = 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));
}
}