fix(server): avoid logging default credential values (#2800)
Co-authored-by: houseme <[email protected]> Co-authored-by: Claude Sonnet 4.6 <[email protected]> Co-authored-by: loverustfs <[email protected]> Co-authored-by: 安正超 <[email protected]>
This commit is contained in:
co-authored by
houseme
Claude Sonnet 4.6
loverustfs
安正超
parent
995e26f5ee
commit
0153710791
+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)
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user