mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* docker: one FIPS mode for the Go processes and the Rust binaries In the image, Go processes ran with fips140=on by default (#7590) while the Rust binaries, which take their mode from fips.mode alone, ran with unrestricted TLS; and WEED_FIPS_MODE=off or strict made every Go process refuse to start, since the entrypoint's fips140=on did not match. The entrypoint now states the image's mode once, as WEED_FIPS_MODE_DEFAULT=on, and gives Go processes the fips140 GODEBUG that matches WEED_FIPS_MODE, else that default. The Rust binaries use the default when neither WEED_FIPS_MODE nor fips.mode sets a mode; Go processes check their GODEBUG against it and refuse to start on a mismatch, naming WEED_FIPS_MODE as the way to pick another mode. Setting WEED_FIPS_MODE_DEFAULT empty leaves every process in its own default, as outside the image. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docker: take the image's FIPS mode from a fips140 the caller sets GODEBUG=fips140=off, the entrypoint's advice since #7590, made every Go process exit once the Rust binaries joined the image's mode. The entrypoint now maps the caller's fips140 to WEED_FIPS_MODE_DEFAULT, so Go and Rust run in that mode and the old advice keeps working. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docker: say fips.mode alone cannot change the image's FIPS mode Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docker: read an empty fips140 as off and debug as on, as Go does Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docker: warn when GODEBUG fips140 picks the image's FIPS mode The entrypoint keeps translating a caller's fips140 into the mode for the Rust binaries, so existing docker run setups keep starting, but logs that WEED_FIPS_MODE is the setting that also covers launches without the entrypoint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docker: set the FIPS mode after dropping privileges Running as root, the entrypoint re-runs itself through su-exec, and the second pass took the fips140 the first pass had exported for the caller's own, warning on default starts and prepending fips140 twice. 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>
131 lines
4.4 KiB
Go
131 lines
4.4 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.
|
|
// FipsModeDefaultEnv holds the mode that applies when neither sets one; the
|
|
// Docker image's entrypoint sets it to the mode it runs every process in.
|
|
const (
|
|
FipsModeSetting = "fips.mode"
|
|
FipsModeEnv = "WEED_FIPS_MODE"
|
|
FipsModeDefaultEnv = "WEED_FIPS_MODE_DEFAULT"
|
|
)
|
|
|
|
// 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)
|
|
}
|
|
}
|
|
|
|
// resolveFipsMode returns the mode a deployment states for this process and
|
|
// where it came from: WEED_FIPS_MODE or fips.mode in v, read from file, else
|
|
// WEED_FIPS_MODE_DEFAULT. An empty mode means none of them sets one.
|
|
func resolveFipsMode(file string, v interface{ Get(string) interface{} }) (source, mode string, err error) {
|
|
source = fipsModeSource(file)
|
|
mode, err = FipsModeValue(source, v)
|
|
if err != nil || mode != "" {
|
|
return source, mode, err
|
|
}
|
|
return FipsModeDefaultEnv, os.Getenv(FipsModeDefaultEnv), nil
|
|
}
|
|
|
|
// checkResolvedFipsMode is CheckFipsMode for a mode resolveFipsMode returned.
|
|
// A mismatch with the image default says how to pick another mode, since the
|
|
// GODEBUG the caller set cannot change what the Rust binaries run in.
|
|
func checkResolvedFipsMode(source, mode string) error {
|
|
err := CheckFipsMode(source, mode)
|
|
if err != nil && source == FipsModeDefaultEnv {
|
|
return fmt.Errorf("%w; to run in another mode, set %s (or %s) instead of the fips140 GODEBUG", err, FipsModeEnv, FipsModeSetting)
|
|
}
|
|
return err
|
|
}
|
|
|
|
// RequireFipsMode exits when the FIPS mode the deployment states, from the
|
|
// environment, the security.toml merged into the shared configuration, or the
|
|
// image default, 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, mode, err := resolveFipsMode(securityConfigFile(), GetViper())
|
|
if err == nil {
|
|
err = checkResolvedFipsMode(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())
|
|
}
|
|
}
|