mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-27 10:59:04 +00:00
fix(sts): validate root credentials on 1.0.7 startup (#9604)
Backport the startup validation and focused tests from #9295 for rustfs/backlog#3294. Co-authored-by: heihutu <heihutu@gmail.com> Co-authored-by: zhi22915 <qiuzgang@gmail.com> Co-authored-by: qunjiazhu <qunjiazhu@gmail.com>
This commit is contained in:
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Deployment
|
||||
|
||||
- Before upgrading, verify that the configured root access key is at least 3 bytes and the root secret key is at least 8 bytes. RustFS now rejects shorter values during startup and identifies the setting to update. Coordinate root credential changes across all nodes and clients. See [root credential rotation considerations](docs/operations/two-factor-auth.md#root-credentials-cannot-be-changed-at-runtime).
|
||||
|
||||
- Existing volumes created by older root-running container images must be writable by the non-root runtime identity before upgrading. The default container UID/GID is `10001:10001`; stop the affected instances, verify host mount paths, and for ordinary bind mounts run `sudo chown -R 10001:10001 /actual/data /actual/logs` on each RustFS data/log mount. Account for ACLs, NFS, Kubernetes, and rootless UID mappings. Image-build ownership changes do not migrate mounted data. See the Docker Quick Start in [README.md](README.md).
|
||||
- Local disk initialization now checks file creation, writing, and deletion in the data root and fixed internal metadata directories. Unwritable disks are rejected using existing startup/quorum rules, with filesystem errors and Unix runtime/owner IDs logged for permission failures, instead of admitting those disks and discovering the mismatch on a later write. Existing object trees are not scanned and volume ownership is never changed automatically.
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ use rustfs_config::{
|
||||
DEFAULT_CONSOLE_ADDRESS, DEFAULT_CONSOLE_ENABLE, ENV_RUSTFS_ACCESS_KEY, ENV_RUSTFS_SECRET_KEY, RUSTFS_REGION,
|
||||
};
|
||||
use rustfs_credentials::{DEFAULT_ACCESS_KEY, DEFAULT_SECRET_KEY, Masked};
|
||||
use rustfs_policy::auth::{is_access_key_valid, is_secret_key_valid};
|
||||
use std::collections::HashSet;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::sync::{Mutex, OnceLock};
|
||||
|
||||
pub(crate) const LEGACY_ENV_RUSTFS_ROOT_USER: &str = "RUSTFS_ROOT_USER";
|
||||
@@ -186,6 +188,16 @@ impl Config {
|
||||
DEFAULT_ACCESS_KEY.eq(&self.access_key) && DEFAULT_SECRET_KEY.eq(&self.secret_key)
|
||||
}
|
||||
|
||||
pub(crate) fn validate_root_credentials(access_key: &str, secret_key: &str) -> std::io::Result<()> {
|
||||
if !is_access_key_valid(access_key) {
|
||||
return Err(Error::new(ErrorKind::InvalidInput, "RUSTFS_ACCESS_KEY must be at least 3 bytes"));
|
||||
}
|
||||
if !is_secret_key_valid(secret_key) {
|
||||
return Err(Error::new(ErrorKind::InvalidInput, "RUSTFS_SECRET_KEY must be at least 8 bytes"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create Config from Opt
|
||||
pub(super) fn from_opt(opt: Opt) -> std::io::Result<Self> {
|
||||
let Opt {
|
||||
@@ -229,6 +241,7 @@ impl Config {
|
||||
&[LEGACY_ENV_RUSTFS_ROOT_PASSWORD],
|
||||
DEFAULT_SECRET_KEY,
|
||||
)?;
|
||||
Self::validate_root_credentials(&access_key, &secret_key)?;
|
||||
|
||||
// Region is optional, but if not set, we should default to "us-east-1" for signing compatibility with AWS S3 clients
|
||||
let region = region.or_else(|| Some(RUSTFS_REGION.to_string()));
|
||||
|
||||
@@ -365,6 +365,34 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn root_credential_lengths_are_checked_after_resolving_key_files() {
|
||||
let dir = tempfile::tempdir().expect("temporary credential directory");
|
||||
let file = dir.path().join("secret");
|
||||
let config = |access_key| {
|
||||
Config::from_opt(Opt::parse_from([
|
||||
"rustfs",
|
||||
"server",
|
||||
"--access-key",
|
||||
access_key,
|
||||
"--secret-key-file",
|
||||
file.to_str().expect("temporary secret key path"),
|
||||
"/data",
|
||||
]))
|
||||
};
|
||||
|
||||
std::fs::write(&file, "1234567\n").expect("write short secret");
|
||||
let err = config("root").expect_err("seven-byte secret must be rejected after trimming");
|
||||
assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);
|
||||
assert_eq!(err.to_string(), "RUSTFS_SECRET_KEY must be at least 8 bytes");
|
||||
|
||||
std::fs::write(&file, "12345678\n").expect("write eight-byte secret");
|
||||
let err = config("ab").expect_err("two-byte access key must be rejected");
|
||||
assert_eq!(err.to_string(), "RUSTFS_ACCESS_KEY must be at least 3 bytes");
|
||||
assert!(config("abc").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn test_access_key_envs_are_used_for_bootstrap_credentials() {
|
||||
|
||||
@@ -138,6 +138,7 @@ pub(crate) async fn prepare_embedded_startup_config(
|
||||
mut volumes: Vec<String>,
|
||||
region: String,
|
||||
) -> Result<EmbeddedStartupConfig> {
|
||||
Config::validate_root_credentials(&access_key, &secret_key)?;
|
||||
let mut temp_dir_guard = None;
|
||||
if volumes.is_empty() {
|
||||
let dir = tempfile::tempdir().map_err(|err| Error::other(format!("failed to create temp dir: {err}")))?;
|
||||
@@ -569,7 +570,7 @@ mod tests {
|
||||
let prepared = prepare_embedded_startup_config(
|
||||
"127.0.0.1:9000".to_string(),
|
||||
"access".to_string(),
|
||||
"secret".to_string(),
|
||||
"embedded-secret".to_string(),
|
||||
Vec::new(),
|
||||
"us-west-2".to_string(),
|
||||
)
|
||||
@@ -578,10 +579,10 @@ mod tests {
|
||||
|
||||
assert_eq!(prepared.config.address, "127.0.0.1:9000");
|
||||
assert_eq!(prepared.config.access_key, "access");
|
||||
assert_eq!(prepared.config.secret_key, "secret");
|
||||
assert_eq!(prepared.config.secret_key, "embedded-secret");
|
||||
assert_eq!(prepared.config.region.as_deref(), Some("us-west-2"));
|
||||
assert_eq!(prepared.identity.access_key, "access");
|
||||
assert_eq!(prepared.identity.secret_key, "secret");
|
||||
assert_eq!(prepared.identity.secret_key, "embedded-secret");
|
||||
assert_eq!(prepared.identity.region, "us-west-2");
|
||||
assert!(!prepared.config.console_enable);
|
||||
assert_eq!(prepared.config.volumes.len(), 1);
|
||||
@@ -589,6 +590,23 @@ mod tests {
|
||||
assert!(prepared.temp_dir_guard.is_some());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn prepare_embedded_startup_config_rejects_short_keys_before_creating_volumes() {
|
||||
let parent = tempfile::tempdir().expect("temp parent");
|
||||
let volume = parent.path().join("data");
|
||||
let result = prepare_embedded_startup_config(
|
||||
"127.0.0.1:0".to_string(),
|
||||
"root".to_string(),
|
||||
"1234567".to_string(),
|
||||
vec![volume.display().to_string()],
|
||||
"us-east-1".to_string(),
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(err) if err.kind() == std::io::ErrorKind::InvalidInput));
|
||||
assert!(!volume.exists());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn prepare_embedded_startup_config_creates_missing_custom_volume() {
|
||||
let parent = tempfile::tempdir().expect("temp parent");
|
||||
@@ -597,7 +615,7 @@ mod tests {
|
||||
let prepared = prepare_embedded_startup_config(
|
||||
"127.0.0.1:9000".to_string(),
|
||||
"access".to_string(),
|
||||
"secret".to_string(),
|
||||
"embedded-secret".to_string(),
|
||||
vec![volume.display().to_string()],
|
||||
"us-east-1".to_string(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user