mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-24 05:06:28 +00:00
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:
@@ -134,6 +134,10 @@ fn format_external_prefix_mappings(report: &ExternalEnvCompatReport) -> String {
|
|||||||
.join(", ")
|
.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<()> {
|
async fn async_main() -> Result<()> {
|
||||||
// Parse command line arguments
|
// Parse command line arguments
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
@@ -349,6 +353,14 @@ async fn run(config: rustfs::config::Config) -> Result<()> {
|
|||||||
None
|
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();
|
let ctx = CancellationToken::new();
|
||||||
|
|
||||||
// init store
|
// init store
|
||||||
@@ -746,4 +758,22 @@ mod tests {
|
|||||||
"MINIO_ROOT_USER->RUSTFS_ROOT_USER, MINIO_NOTIFY_WEBHOOK_ENABLE_PRIMARY->RUSTFS_NOTIFY_WEBHOOK_ENABLE_PRIMARY"
|
"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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,15 +210,6 @@ pub async fn start_http_server(
|
|||||||
} else {
|
} else {
|
||||||
info!(target: "rustfs::main::startup", "RustFS API: {api_endpoints} {localhost_endpoint}");
|
info!(target: "rustfs::main::startup", "RustFS API: {api_endpoints} {localhost_endpoint}");
|
||||||
info!(target: "rustfs::main::startup", "RustFS Start Time: {now_time}");
|
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","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.");
|
info!(target: "rustfs::main::startup", "To enable the console, restart the server with --console-enable and a valid --console-address.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user