mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
* worker(rs): refuse short JWT keys under fips.mode strict weed-worker, weed-vector and weed-vector-cli now check the JWT keys of the security.toml they read, as every Go process does: under fips.mode strict each exits at startup naming every key shorter than the 14 characters FIPS 140 needs for HMAC keys, with the rule and messages of seaweed_common::jwt_keys (#13206); outside strict mode each such key but a previous_key gets a warning. A filer signing key given on the command line (--filer-signing-key, WEED_FILER_SIGNING_KEY) is checked the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker(rs): warn about a short signing key flag outside strict mode A filer signing key given by --filer-signing-key or WEED_FILER_SIGNING_KEY was checked only under fips.mode strict; outside it, a key strict mode would refuse now gets the warning a short key in security.toml gets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: start the worker binaries with short keys under fips.mode strict Integration tests start the built weed-worker, weed-vector and weed-vector-cli under WEED_FIPS_MODE=strict with a 10-byte key in security.toml, or a short --filer-signing-key, and check that each exits naming the key. They run in the existing cargo test jobs and need no cluster: the check comes before the binaries dial anything. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
2.3 KiB
Rust
66 lines
2.3 KiB
Rust
//! weed-vector under `fips.mode = strict` exits at startup when a JWT key is
|
|
//! too short for FIPS 140, before it dials the masters.
|
|
|
|
use std::io::Read;
|
|
use std::process::{Command, ExitStatus, Stdio};
|
|
use std::time::{Duration, Instant};
|
|
|
|
/// Runs weed-vector with `args` under `WEED_FIPS_MODE=strict` and a
|
|
/// security.toml holding `security`, without the caller's other WEED_
|
|
/// variables, and returns its exit status and stderr. Fails when it is still
|
|
/// running after 30 s, which means it accepted the keys.
|
|
fn run_strict(security: &str, args: &[&str]) -> (ExitStatus, String) {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let file = dir.path().join("security.toml");
|
|
std::fs::write(&file, security).unwrap();
|
|
let mut command = Command::new(env!("CARGO_BIN_EXE_weed-vector"));
|
|
for (name, _) in std::env::vars_os() {
|
|
if name.to_string_lossy().starts_with("WEED_") {
|
|
command.env_remove(name);
|
|
}
|
|
}
|
|
let mut child = command
|
|
.arg("--security-toml")
|
|
.arg(&file)
|
|
.args(args)
|
|
.env("WEED_FIPS_MODE", "strict")
|
|
.current_dir(dir.path())
|
|
.stdout(Stdio::null())
|
|
.stderr(Stdio::piped())
|
|
.spawn()
|
|
.unwrap();
|
|
let deadline = Instant::now() + Duration::from_secs(30);
|
|
loop {
|
|
if let Some(status) = child.try_wait().unwrap() {
|
|
let mut stderr = String::new();
|
|
child
|
|
.stderr
|
|
.take()
|
|
.unwrap()
|
|
.read_to_string(&mut stderr)
|
|
.unwrap();
|
|
return (status, stderr);
|
|
}
|
|
if Instant::now() > deadline {
|
|
let _ = child.kill();
|
|
panic!("weed-vector still running after 30 s: it accepted the short key");
|
|
}
|
|
std::thread::sleep(Duration::from_millis(100));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_short_key_in_security_toml_stops_the_engine() {
|
|
let (status, stderr) = run_strict(
|
|
"[jwt.signing.read]\nkey = \"0123456789\"\n",
|
|
&["--masters", "127.0.0.1:9333.19333"],
|
|
);
|
|
assert!(!status.success(), "{stderr}");
|
|
assert!(
|
|
stderr.contains("fips.mode strict")
|
|
&& stderr
|
|
.contains("jwt.signing.read.key (10 characters) is shorter than the 14 characters"),
|
|
"{stderr}"
|
|
);
|
|
}
|