fix(server): warn on default credentials with console enabled (#2448)

Co-authored-by: 安正超 <anzhengchao@gmail.com>
Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
Henry Guo
2026-04-11 00:03:06 +08:00
committed by GitHub
parent 4472324125
commit 70fdf79297
2 changed files with 30 additions and 9 deletions
+30
View File
@@ -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<String> = 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));
}
}
-9
View File
@@ -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.");
}