mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
* volume(rs): refuse short JWT keys and skip Content-MD5 under fips.mode strict Under fips.mode = strict the Rust volume server now does what the Go volume server does under GODEBUG=fips140=only: - At startup it exits when a JWT key in security.toml (any of the eleven jwt.signing* and jwt.filer_signing* settings Go checks) is shorter than the 14 characters FIPS 140 needs for HMAC keys, naming each one. Outside strict mode it warns about each such key but the previous ones. - On SIGHUP, short current keys keep the keys in effect, and a short previous key is dropped, as in Go's Guard.UpdateSigningKeys. - An upload's Content-MD5 is kept as the client sent it, unchecked, since strict mode computes no MD5. The key rule and its messages live in seaweed-common's jwt_keys, so the worker can use the same one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci: run the fips140only cells in fips.mode strict, check strict refusals The fips140only cells of the S3 digest matrix set WEED_FIPS_MODE=strict beside GODEBUG=fips140=only, so the Rust volume server runs in the same mode as the Go processes. A new job, test/s3/digest_matrix/negative_config.sh, checks that master, filer and both volume servers refuse a 10-byte JWT key at startup, that both volume servers keep a mismatched Content-MD5 unchecked, and that S3 answers a request signed with an 8-character secret with an error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: check the strict-mode Content-MD5 rule against both volume servers TestWriteMD5MismatchKeptUncheckedUnderStrictFIPS starts the volume cluster under GODEBUG=fips140=only and WEED_FIPS_MODE=strict and checks that an upload with a mismatched Content-MD5 is stored with the client's value. It sits in test/volume_server/http, so it runs against the Go volume server and, with VOLUME_SERVER_IMPL=rust, against the Rust one. The same check leaves negative_config.sh, which keeps the startup refusals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): say which keys the strict-mode checks cover and what they do The doc comments of the startup check, the reload rule and the jwt_keys helpers now say which keys they check and what happens in each mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): an empty WEED_ variable leaves the security.toml value in place env_string returned an empty variable as a value, so WEED_JWT_SIGNING_KEY= replaced the key from security.toml with an empty one: the volume server then checked no JWTs, and under fips.mode strict a short file key was not refused, while Go's volume server exits with the same files. Go's viper ignores empty variables; env_string now does the same for every WEED_ override. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): read security.toml with the TOML parser The line reader missed quoted key names, multiline strings, dotted keys, inline tables and spaced or quoted table headers, all of which Go's viper reads, so a short JWT key written that way escaped the strict-mode check and was not used at all. Settings are now looked up in the parsed table, case-insensitively as viper does. A file that is not valid TOML is still read line by line, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): prefer the longest literal security.toml key, as viper does Viper looks a dotted setting up longest name first, so a quoted "jwt.filer_signing.key" key, at the top or under [jwt], wins over the nested [jwt.filer_signing] key. The volume server read only the nested one, so a short literal key passed the strict-mode check here while the Go servers refused it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): resolve security.toml key case collisions as viper does Viper lowercases every key of a config file, and when two spellings collide (key and KEY, or [jwt] and [JWT]) the one that is not lowercase wins. The volume server matched names case-insensitively but took the exact spelling first, so a short KEY next to a compliant key passed the strict-mode check here while the Go servers refused it. The parsed table is now lowercased the same way before any lookup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): read an array or table security.toml setting as unset Viper's GetString reads an array or a table as "", so the Go servers skip a jwt key written as key = ["x"]. The volume server read its TOML text instead, used it as the key and refused strict-mode startup over it. fips.mode is still read as text: Go refuses a mode that is not a string, and so does this server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): keep each lenient security.toml line under its full name A security.toml that is not valid TOML is read line by line, and those lines went into nested tables, so a later scalar such as signing = "x" under [jwt] replaced the [jwt.signing] table and erased its key. The line reader ignored such lines before, and a SIGHUP reload of that file would have installed an empty write key. Each line now goes in under its full dotted name, which the longest-name lookup finds first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): take the FIPS mode from the read that gives the JWT keys Startup read security.toml once for the JWT keys and again for fips.mode, so a file replaced between the two reads could pair the keys of one version with the mode of the other and refuse to start over keys that version never ran in strict mode with. The mode now comes from the same parse as the keys; a file that exists but was not read is still an error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): read a float security.toml setting as Go's GetString does GetString formats a float with the shortest digits and no exponent, so key = 1234567890123.0 is a 13-byte key to the Go servers. The volume server kept the TOML spelling with its .0 and measured 15 bytes, which passed the strict-mode check the Go servers refuse. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): skip array-of-tables sections in a lenient security.toml A file that is not valid TOML is read line by line, and lines under a [[jwt.signing]] header went in under the same names as [jwt.signing], so an empty key there replaced the real one, and a SIGHUP reload would install it. The line reader now skips such sections up to the next ordinary header, as the earlier reader did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
83 lines
3.9 KiB
Bash
83 lines
3.9 KiB
Bash
#!/usr/bin/env bash
|
|
# Checks what strict FIPS mode refuses, in the Go components
|
|
# (GODEBUG=fips140=only) and the Rust volume server (WEED_FIPS_MODE=strict).
|
|
# Go's crypto/hmac refuses keys shorter than 112 bits (14 bytes) in that mode,
|
|
# so a component must refuse such a key at startup instead of failing (or
|
|
# panicking) on the first request that needs it.
|
|
#
|
|
# master, filer, volume (Go), volume (Rust): started alone with a 10-byte
|
|
# jwt.signing.key; each must exit non-zero within 20 s naming the mode.
|
|
# s3: a fips140=only cluster with valid JWT keys and an identity whose
|
|
# 8-character secret makes a SigV4 signing key under 14 bytes; a request
|
|
# signed with it must get an S3 error answer, not a dropped connection.
|
|
#
|
|
# Prints one line per component and exits non-zero if any check fails.
|
|
# WEED, WEED_VOLUME, WORK_DIR binaries and scratch dir
|
|
set -uo pipefail
|
|
|
|
WEED=${WEED:-weed}
|
|
WEED_VOLUME=${WEED_VOLUME:-weed-volume}
|
|
WORK_DIR=${WORK_DIR:-/tmp/seaweedfs-negative-config}
|
|
export GODEBUG=fips140=only WEED_FIPS_MODE=strict
|
|
|
|
rm -rf "$WORK_DIR"
|
|
mkdir -p "$WORK_DIR/short" "$WORK_DIR/valid"
|
|
printf '[jwt.signing]\nkey = "0123456789"\n' > "$WORK_DIR/short/security.toml"
|
|
printf '[jwt.signing]\nkey = "%s"\n' "$(head -c 24 /dev/urandom | od -An -tx1 | tr -d ' \n')" \
|
|
> "$WORK_DIR/valid/security.toml"
|
|
failures=0
|
|
|
|
# expect_refusal starts a component with the short key and reports whether it
|
|
# exited non-zero within 20 s naming the mode in its log: fips140=only for Go,
|
|
# fips.mode strict for Rust.
|
|
expect_refusal() {
|
|
local name=$1; shift
|
|
local log="$WORK_DIR/$name.log"
|
|
(cd "$WORK_DIR/short" && exec "$@") > "$log" 2>&1 &
|
|
local pid=$! status=
|
|
for _ in $(seq 1 20); do
|
|
if ! kill -0 "$pid" 2>/dev/null; then wait "$pid"; status=$?; break; fi
|
|
sleep 1
|
|
done
|
|
if [ -z "$status" ]; then
|
|
kill -KILL "$pid" 2>/dev/null; wait "$pid" 2>/dev/null
|
|
echo "FAIL $name: still running after 20 s with a 10-byte jwt.signing.key"
|
|
failures=$((failures + 1))
|
|
elif [ "$status" -ne 0 ] && grep -q -E 'fips140=only|fips\.mode strict' "$log"; then
|
|
echo "ok $name: refused at startup (exit $status)"
|
|
else
|
|
echo "FAIL $name: exited $status without naming the FIPS mode; log tail:"
|
|
tail -5 "$log" | sed 's/^/ /'
|
|
failures=$((failures + 1))
|
|
fi
|
|
}
|
|
|
|
mkdir -p "$WORK_DIR/m" "$WORK_DIR/f" "$WORK_DIR/vg" "$WORK_DIR/vr"
|
|
expect_refusal master "$WEED" master -port=19333 -mdir="$WORK_DIR/m" -peers=none
|
|
expect_refusal filer "$WEED" filer -master=127.0.0.1:19333 -port=18888 -defaultStoreDir="$WORK_DIR/f"
|
|
expect_refusal volume-go "$WEED" volume -master=127.0.0.1:19333 -port=18080 -dir="$WORK_DIR/vg"
|
|
expect_refusal volume-rust "$WEED_VOLUME" --master 127.0.0.1:19333 --port 18081 --port.grpc 28081 \
|
|
--dir "$WORK_DIR/vr" --securityFile "$WORK_DIR/short/security.toml"
|
|
|
|
cat > "$WORK_DIR/valid/s3.json" <<'EOF'
|
|
{"identities":[{"name":"short","credentials":[{"accessKey":"shortsecretkey01","secretKey":"abcd1234"}],"actions":["Admin"]}]}
|
|
EOF
|
|
mkdir -p "$WORK_DIR/s"
|
|
(cd "$WORK_DIR/valid" && exec "$WEED" server -filer -s3 -ip=127.0.0.1 -dir="$WORK_DIR/s" \
|
|
-master.port=29333 -volume.port=28080 -filer.port=28888 -s3.port=28000 -master.peers=none \
|
|
-s3.config="$WORK_DIR/valid/s3.json") > "$WORK_DIR/s3.log" 2>&1 &
|
|
server_pid=$!
|
|
for _ in $(seq 1 60); do curl -s -o /dev/null http://127.0.0.1:28000/ && break; sleep 1; done
|
|
code=$(curl -s -o "$WORK_DIR/s3.body" -w '%{http_code}' --aws-sigv4 "aws:amz:us-east-1:s3" \
|
|
--user shortsecretkey01:abcd1234 http://127.0.0.1:28000/)
|
|
curl_status=$?
|
|
if [ "$curl_status" -eq 0 ] && [ "${code:0:1}" = 4 ]; then
|
|
echo "ok s3: an 8-character secret gets HTTP $code ($(grep -o '<Code>[^<]*' "$WORK_DIR/s3.body" | cut -c7-))"
|
|
else
|
|
echo "FAIL s3: an 8-character secret got curl exit $curl_status, HTTP $code (a dropped connection is a panic in the request)"
|
|
failures=$((failures + 1))
|
|
fi
|
|
kill -TERM "$server_pid" 2>/dev/null; wait "$server_pid" 2>/dev/null
|
|
|
|
exit $((failures > 0))
|