mirror of
https://github.com/rustfs/rustfs.git
synced 2026-09-04 11:15:39 +00:00
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:
+14
-5
@@ -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)
|
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<()> {
|
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();
|
||||||
@@ -355,11 +358,7 @@ async fn run(config: rustfs::config::Config) -> Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if is_using_default_credentials(&config) {
|
if is_using_default_credentials(&config) {
|
||||||
warn!(
|
warn!("{}", DEFAULT_CREDENTIALS_WARNING_MESSAGE);
|
||||||
"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();
|
||||||
@@ -780,4 +779,14 @@ mod tests {
|
|||||||
|
|
||||||
assert!(!is_using_default_credentials(&config));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user