diff --git a/rustfs/src/main.rs b/rustfs/src/main.rs index 70095ad42..9a5b2dee7 100644 --- a/rustfs/src/main.rs +++ b/rustfs/src/main.rs @@ -134,6 +134,10 @@ fn format_external_prefix_mappings(report: &ExternalEnvCompatReport) -> String { .join(", ") } +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) +} + async fn async_main() -> Result<()> { // Parse command line arguments let args: Vec = std::env::args().collect(); @@ -349,6 +353,14 @@ async fn run(config: rustfs::config::Config) -> Result<()> { None }; + 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 + ); + } + let ctx = CancellationToken::new(); // init store @@ -746,4 +758,22 @@ mod tests { "MINIO_ROOT_USER->RUSTFS_ROOT_USER, MINIO_NOTIFY_WEBHOOK_ENABLE_PRIMARY->RUSTFS_NOTIFY_WEBHOOK_ENABLE_PRIMARY" ); } + + #[test] + fn is_using_default_credentials_returns_true_for_default_keys() { + let mut config = rustfs::config::Config::new("127.0.0.1:9000", Vec::new()); + config.console_enable = true; + config.console_address = "127.0.0.1:9001".to_string(); + + assert!(is_using_default_credentials(&config)); + } + + #[test] + fn is_using_default_credentials_returns_false_for_custom_keys() { + let mut config = rustfs::config::Config::new("127.0.0.1:9000", Vec::new()); + config.access_key = "custom-access-key".to_string(); + config.secret_key = "custom-secret-key".to_string(); + + assert!(!is_using_default_credentials(&config)); + } } diff --git a/rustfs/src/server/http.rs b/rustfs/src/server/http.rs index 55ff6abdb..d1ad34d99 100644 --- a/rustfs/src/server/http.rs +++ b/rustfs/src/server/http.rs @@ -210,15 +210,6 @@ pub async fn start_http_server( } else { info!(target: "rustfs::main::startup", "RustFS API: {api_endpoints} {localhost_endpoint}"); info!(target: "rustfs::main::startup", "RustFS Start Time: {now_time}"); - if rustfs_credentials::DEFAULT_ACCESS_KEY.eq(&config.access_key) - && rustfs_credentials::DEFAULT_SECRET_KEY.eq(&config.secret_key) - { - 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 - ); - } info!(target: "rustfs::main::startup","For more information, visit https://rustfs.com/docs/"); info!(target: "rustfs::main::startup", "To enable the console, restart the server with --console-enable and a valid --console-address."); }