mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* util: refuse to start when fips.mode in security.toml disagrees with GODEBUG security.toml gains [fips] mode = "off" | "on" | "strict", also settable as WEED_FIPS_MODE: one setting that states the FIPS 140-3 mode of every process in a deployment, so the Rust binaries, which do not run on the Go runtime, can follow it. Go processes keep taking their behaviour from GODEBUG=fips140 and now check it against the setting: LoadSecurityConfiguration and `weed worker` exit when "off" runs without fips140=off, "on" without fips140=on, or "strict" without fips140=only, naming the setting and the GODEBUG value it needs. An unknown value is refused; unset or empty changes nothing. Refs #12839 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * rust: fips.mode with FIPS-mode TLS in weed-volume, weed-worker and weed-vector seaweed-common gains a fips module: FipsMode resolved from fips.mode in the security.toml a binary uses, with WEED_FIPS_MODE over it. Each binary resolves it once at startup, logs it and installs the matching rustls provider as the process default, refusing to start on an unknown value or when another provider was installed first. Under "on" and "strict" the provider is aws-lc-rs filtered to the lists Go's crypto/tls applies in FIPS mode: TLS 1.3 AES-GCM suites and TLS 1.2 ECDHE AES-GCM suites (no ChaCha20-Poly1305), X25519MLKEM768, SecP256r1MLKEM768, P-256 and P-384 (no plain X25519), Go's ten signature schemes (no ML-DSA). Configurations SeaweedFS builds require the Extended Master Secret in that mode, and the volume server refuses a non-FIPS suite in tls.cipher_suites instead of falling back. sw-client installs the same provider instead of ring. Unset or "off" keeps aws-lc-rs's default provider unchanged. This is behavioural parity only: the provider still runs on the non-validated aws-lc-rs build. Refs #12839 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: refuse a fips.mode that is not a string viper's GetString turns an array or a table into "", so mode = ["strict"] under [fips] skipped the GODEBUG check while the Rust binaries refused the same file. RequireFipsMode now reads the raw value (ViperProxy.Get, under its lock) and exits when it is not a string, naming its source; an absent or empty value still means unset, and WEED_FIPS_MODE still wins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * rust: read fips.mode with the parser that reads the JWT keys seaweed_common::fips::resolve parsed security.toml with the toml crate, while the volume server reads the rest of the file with its own lenient loader. A file with [fips] mode = "on" beside an unquoted value the loader accepts resolved to off and logged "fips.mode unset", although the JWT keys from the same file were applied. Each binary now reads fips.mode with the loader it uses for everything else and hands the value to resolve: the volume server through its line parser, the worker and vector engine through their parsed Security table, which already refuses a file that is not TOML. A security.toml the volume server finds but cannot read stops startup. A missing setting is still off, and WEED_FIPS_MODE still wins. seaweed-common no longer depends on toml. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * sw-client: offer only FIPS signature schemes with insecure_skip_verify With https.client.insecure_skip_verify, reqwest installs its own verifier, which advertises a fixed scheme list including SHA-1 and Ed448 whatever the process provider allows. In FIPS mode the volume transport now builds its rustls configuration itself on the process provider: the server certificate and host name are not checked, as the setting asks, but handshake signatures are verified with the provider's algorithms, only its schemes are offered, and TLS 1.2 requires the Extended Master Secret. Outside FIPS mode the reqwest path is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * seaweed-common: sign only with Go 1.27's FIPS schemes, allow ML-DSA The FIPS provider kept aws-lc-rs's key provider, so a FIPS-mode listener signed handshakes with whatever scheme its key and the peer agreed on, outside the list the provider verifies with. Keys now load through a provider that limits each key to the FIPS signature schemes and refuses a key that can sign none of them, such as Ed448; the volume server and the worker's gRPC TLS name the certificate and key files in that error. The lists follow Go 1.27.4, which go.mod now requires: its defaults_fips140.go allows ML-DSA-44, -65 and -87 as signature schemes and ML-DSA certificate keys (for Go's native module only), so they are allowed here as well. Go also allows MLKEM1024 but does not enable it by default, so it stays out of the key exchange list as in Go's defaults. "off" keeps the default key provider. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: skip the truncate manifest test on freebsd like its fake filer 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>
105 lines
3.2 KiB
Go
105 lines
3.2 KiB
Go
package util
|
|
|
|
import (
|
|
"crypto/fips140"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
)
|
|
|
|
// FipsModeSetting is the security.toml setting that states the FIPS 140-3
|
|
// mode every SeaweedFS process of a deployment runs in. Go processes take the
|
|
// mode from GODEBUG and check it against this setting; the Rust binaries take
|
|
// it from this setting alone. FipsModeEnv sets it from the environment.
|
|
const (
|
|
FipsModeSetting = "fips.mode"
|
|
FipsModeEnv = "WEED_FIPS_MODE"
|
|
)
|
|
|
|
// The values of fips.mode. An empty value leaves every process as it is.
|
|
const (
|
|
FipsModeOff = "off"
|
|
FipsModeOn = "on"
|
|
FipsModeStrict = "strict"
|
|
)
|
|
|
|
var fips140Enabled = fips140.Enabled
|
|
|
|
// fips140Godebug names the fips140 GODEBUG value this process runs with.
|
|
func fips140Godebug() string {
|
|
switch {
|
|
case fips140Enforced():
|
|
return "only"
|
|
case fips140Enabled():
|
|
return "on"
|
|
}
|
|
return "off"
|
|
}
|
|
|
|
// CheckFipsMode returns an error when mode, the value of fips.mode read from
|
|
// source, is not one SeaweedFS knows or does not match the fips140 GODEBUG
|
|
// this process runs with: off needs fips140=off, on needs fips140=on and
|
|
// strict needs fips140=only. An empty mode is not checked.
|
|
func CheckFipsMode(source, mode string) error {
|
|
var want string
|
|
switch mode {
|
|
case "":
|
|
return nil
|
|
case FipsModeOff:
|
|
want = "off"
|
|
case FipsModeOn:
|
|
want = "on"
|
|
case FipsModeStrict:
|
|
want = "only"
|
|
default:
|
|
return fmt.Errorf("%s is %q; want %s, %s or %s", source, mode, FipsModeOff, FipsModeOn, FipsModeStrict)
|
|
}
|
|
if got := fips140Godebug(); got != want {
|
|
return fmt.Errorf("%s is %q, which needs GODEBUG=fips140=%s; this process runs with fips140=%s", source, mode, want, got)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// fipsModeSource names where fips.mode came from for messages: the
|
|
// environment variable when it is set, else the setting in file.
|
|
func fipsModeSource(file string) string {
|
|
if os.Getenv(FipsModeEnv) != "" {
|
|
return FipsModeEnv
|
|
}
|
|
return file + ": " + FipsModeSetting
|
|
}
|
|
|
|
// FipsModeValue returns fips.mode from v, the environment's value when
|
|
// WEED_FIPS_MODE is set, "" when neither sets it. A value that is not a
|
|
// string, such as an array or a table, is an error naming source: viper's
|
|
// GetString would read it as "" and so skip the check.
|
|
func FipsModeValue(source string, v interface{ Get(string) interface{} }) (string, error) {
|
|
switch value := v.Get(FipsModeSetting).(type) {
|
|
case nil:
|
|
return "", nil
|
|
case string:
|
|
return value, nil
|
|
default:
|
|
return "", fmt.Errorf("%s is %v, a %T, not a string; want %s, %s or %s", source, value, value, FipsModeOff, FipsModeOn, FipsModeStrict)
|
|
}
|
|
}
|
|
|
|
// RequireFipsMode exits when fips.mode, from the environment or the
|
|
// security.toml merged into the shared configuration, is not a string or
|
|
// fails CheckFipsMode, so a process never runs in a FIPS mode other than the
|
|
// one the deployment states. Call it after loading security.toml.
|
|
func RequireFipsMode() {
|
|
source := fipsModeSource(securityConfigFile())
|
|
mode, err := FipsModeValue(source, GetViper())
|
|
if err == nil {
|
|
err = CheckFipsMode(source, mode)
|
|
}
|
|
if err != nil {
|
|
glog.Fatalf("%v", err)
|
|
}
|
|
if mode != "" {
|
|
glog.V(0).Infof("%s is %q, matching GODEBUG fips140=%s", source, mode, fips140Godebug())
|
|
}
|
|
}
|