mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
* Add per-call filer authentication sources and pooled client wrappers * Authenticate gateway filer calls with per-call admin tokens * Authenticate shell admin and synchronization filer calls * Authenticate workers MQ and remaining filer client paths * Cache filer client signing keys and sign subscriptions with the shared key Re-reading security.toml on every filer RPC cost about 125us against 8us for signing. Keep the keys for up to a second, re-reading at once when a WEED_ override or the configuration directory changes. When the file exists but cannot be read, keep the last keys read, else the startup keys, as FilerAdminKeys does, so a process without a key stays tokenless. Metadata subscriptions prefer the shared key, as filer peers do, because older filers verify subscription admin tokens only with it. * Authenticate admin-script, maintenance and filer.conf shell paths Plugin worker admin scripts and master maintenance scripts build their own shell options and carried no filer token source; fs.configure and s3.bucket.quota.check read filer.conf without it. * filer.cat: report a failed read; isolate key overrides in the admin-script test filer.cat ignored the error from its filer call and exited successfully, leaving a truncated -output file. Report the error and exit with failure. The admin-script token test now clears the WEED_ signing-key overrides, which take precedence over security.toml. * security: refuse gRPC keys too short to sign; query engine uses client TLS Under GODEBUG=fips140=only, hmac.New panics on keys under 14 bytes. The startup check now covers jwt.filer_signing.grpc_key and grpc_previous_key, and filer client token sources check the keys they read, so a reloaded or per-endpoint security file with a short key is refused instead of panicking when the next RPC signs. The query engine's broker client dialed every master, filer and broker in plaintext, so the admin token it now sends could cross the network in the clear. It dials with the grpc.client TLS settings instead, and weed-sql loads security.toml as weed-db does. * security: per-endpoint admin tokens ignore WEED_ key overrides FilerAdminTokenFromFile honored WEED_JWT_FILER_SIGNING_GRPC_KEY and WEED_JWT_FILER_SIGNING_KEY. Those are process-wide, so filer.sync with -a.security and -b.security signed both clusters' admin tokens with the one key, handing each cluster a token valid on the other. A per-endpoint file now supplies its own keys only. * weed-sql, weed-db: refuse to start on an unreadable security.toml Both only warned when security.toml was present but could not be read or parsed. They then dialed without the grpc.client TLS settings while the filer token source could still sign admin tokens from WEED_ environment keys, so the tokens could travel in plaintext. They now exit with an error that does not quote the file; a missing file is still fine. * pb: take the filer token source in WithGrpcFilerClient and WithOneOfGrpcFilerClients Fold WithGrpcFilerClientAuth and WithOneOfGrpcFilerClientsAuth into the existing helpers instead of keeping two names for each. Callers without a token source pass nil. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: return the read error from ReadConfiguration Fold ReadConfigurationWithError into ReadConfiguration. The error is returned and not logged, since parser errors can quote values; the existing reload callers already warn when no file was read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * security: keep the test-only filerAdminToken helper in the test It had no production caller. The test helper now resolves keys through filerClientKeysFrom, as the token sources do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: read security.toml once in LoadSecurityConfigurationOrError It validated the file, then merged it with a second read whose failure was ignored and whose parser error was logged. It now merges with one read and logs nothing from the parser. Viper's search also treats a directory the process cannot search as holding no file; a candidate that cannot be checked for lack of permission is now refused too. * security: verify admin subscription tokens with the gRPC clock leeway CheckGrpcMetadataSubscription checked admin tokens strictly, while unary filer calls allow jwt.filer_signing.clock_leeway_seconds. With ten-second client admin tokens, a subscriber whose clock trailed the filer's by more than ten seconds was refused with a matching key. It now takes the leeway, and the filer passes its configured one. The leeway check moves from the server package to security.IsFilerAdminTokenWithLeeway so both use it. * util: start without security.toml only when every candidate is confirmed absent A candidate whose check fails for any reason other than not existing, such as a symlink loop, is refused like one the process cannot search. --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
163 lines
6.3 KiB
Go
163 lines
6.3 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util/version"
|
|
|
|
"time"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/iamapi"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/security"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
"github.com/seaweedfs/seaweedfs/weed/util/grace"
|
|
|
|
// Import credential stores to register them
|
|
_ "github.com/seaweedfs/seaweedfs/weed/credential/filer_etc"
|
|
_ "github.com/seaweedfs/seaweedfs/weed/credential/memory"
|
|
_ "github.com/seaweedfs/seaweedfs/weed/credential/postgres"
|
|
)
|
|
|
|
var (
|
|
iamStandaloneOptions IamOptions
|
|
)
|
|
|
|
type IamOptions struct {
|
|
filer *string
|
|
masters *string
|
|
ip *string
|
|
ipBind *string
|
|
listenOnLocalhost *bool
|
|
port *int
|
|
idleTimeout *int
|
|
selfServiceRequiresGrant *bool
|
|
}
|
|
|
|
func init() {
|
|
cmdIam.Run = runIam // break init cycle
|
|
iamStandaloneOptions.filer = cmdIam.Flag.String("filer", "localhost:8888", "comma-separated filer server addresses for high availability")
|
|
iamStandaloneOptions.masters = cmdIam.Flag.String("master", "localhost:9333", "comma-separated master servers")
|
|
iamStandaloneOptions.ip = cmdIam.Flag.String("ip", util.DetectedHostAddress(), "iam server http listen ip address")
|
|
iamStandaloneOptions.ipBind = cmdIam.Flag.String("ip.bind", "", "ip address to bind to. If empty, default to same as -ip option.")
|
|
iamStandaloneOptions.port = cmdIam.Flag.Int("port", 8111, "iam server http listen port")
|
|
iamStandaloneOptions.idleTimeout = cmdIam.Flag.Int("idleTimeout", 10, "connection idle seconds")
|
|
iamStandaloneOptions.selfServiceRequiresGrant = cmdIam.Flag.Bool("selfServiceRequiresGrant", false, iamSelfServiceRequiresGrantUsage)
|
|
}
|
|
|
|
var cmdIam = &Command{
|
|
UsageLine: "iam [-port=8111] [-filer=<ip:port>[,<ip:port>]...] [-master=<ip:port>,<ip:port>]",
|
|
Short: "[DEPRECATED] start a standalone iam API compatible server",
|
|
Long: `[DEPRECATED] start a standalone iam API compatible server.
|
|
|
|
DEPRECATION NOTICE:
|
|
The standalone 'weed iam' command is deprecated and will be removed in a future release.
|
|
|
|
The IAM API is now embedded in the S3 server by default. Simply use 'weed s3' instead,
|
|
which provides both S3 and IAM APIs on the same port (enabled by default with -iam=true).
|
|
|
|
This simplifies deployment by running a single server instead of two separate servers,
|
|
following the pattern used by MinIO and Ceph RGW.
|
|
|
|
To use the embedded IAM API:
|
|
weed s3 -port=8333 # IAM API is available on the same port
|
|
|
|
To disable the embedded IAM API (if you prefer the old behavior):
|
|
weed s3 -iam=false # Run S3 without IAM
|
|
weed iam -port=8111 # Run IAM separately (deprecated)
|
|
|
|
Multiple filer addresses can be specified for high availability, separated by commas.`,
|
|
}
|
|
|
|
func runIam(cmd *Command, args []string) bool {
|
|
glog.Warningf("================================================================================")
|
|
glog.Warningf("DEPRECATION WARNING: 'weed iam' is deprecated and will be removed in a future release.")
|
|
glog.Warningf("The IAM API is now embedded in 'weed s3' by default (use -iam=true, which is the default).")
|
|
glog.Warningf("Please migrate to using 'weed s3' which provides both S3 and IAM APIs on the same port.")
|
|
glog.Warningf("================================================================================")
|
|
return iamStandaloneOptions.startIamServer()
|
|
}
|
|
|
|
func (iamopt *IamOptions) startIamServer() bool {
|
|
filerAddresses := pb.ServerAddresses(*iamopt.filer).ToAddresses()
|
|
|
|
util.LoadSecurityConfiguration()
|
|
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
|
|
var digest string
|
|
for {
|
|
err := pb.WithOneOfGrpcFilerClients(false, filerAddresses, grpcDialOption, security.FilerAdminToken, func(client filer_pb.SeaweedFilerClient) error {
|
|
resp, err := client.GetFilerConfiguration(context.Background(), &filer_pb.GetFilerConfigurationRequest{})
|
|
if err != nil {
|
|
return fmt.Errorf("get filer configuration: %v", err)
|
|
}
|
|
glog.V(0).Infof("IAM read filer configuration: %s", resp)
|
|
digest = resp.Digest
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
glog.V(0).Infof("wait to connect to filers %v", filerAddresses)
|
|
time.Sleep(time.Second)
|
|
} else {
|
|
glog.V(0).Infof("connected to filers %v", filerAddresses)
|
|
break
|
|
}
|
|
}
|
|
adoptFilerDigest(*iamopt.filer, digest)
|
|
|
|
masters := pb.ServerAddresses(*iamopt.masters).ToAddressMap()
|
|
router := mux.NewRouter().SkipClean(true)
|
|
iamApiServer, iamApiServer_err := iamapi.NewIamApiServer(router, &iamapi.IamServerOption{
|
|
Masters: masters,
|
|
Filers: filerAddresses,
|
|
Port: *iamopt.port,
|
|
GrpcDialOption: grpcDialOption,
|
|
IamSelfServiceRequiresGrant: *iamopt.selfServiceRequiresGrant,
|
|
})
|
|
glog.V(0).Info("NewIamApiServer created")
|
|
if iamApiServer_err != nil {
|
|
glog.Fatalf("IAM API Server startup error: %v", iamApiServer_err)
|
|
}
|
|
|
|
// Register shutdown handler to prevent goroutine leak
|
|
grace.OnInterrupt(func() {
|
|
iamApiServer.Shutdown()
|
|
})
|
|
|
|
// The loopback companion listener is only kept while -ip.bind is unset and
|
|
// the bind address falls back to -ip. An explicit -ip.bind pins the port to
|
|
// exactly that address.
|
|
bindIp := *iamopt.ip
|
|
listenOnLocalhost := iamopt.ipBind == nil || *iamopt.ipBind == ""
|
|
if iamopt.ipBind != nil && *iamopt.ipBind != "" {
|
|
bindIp = *iamopt.ipBind
|
|
}
|
|
if iamopt.listenOnLocalhost != nil {
|
|
listenOnLocalhost = *iamopt.listenOnLocalhost
|
|
}
|
|
idleTimeout := idleTimeoutSeconds(iamopt.idleTimeout)
|
|
|
|
listenAddress := fmt.Sprintf(":%d", *iamopt.port)
|
|
iamApiListener, iamApiLocalListener, err := util.NewIpAndLocalListeners(bindIp, *iamopt.port, idleTimeout, listenOnLocalhost)
|
|
if err != nil {
|
|
glog.Fatalf("IAM API Server listener on %s error: %v", listenAddress, err)
|
|
}
|
|
|
|
glog.V(0).Infof("Start Seaweed IAM API Server %s at http port %d", version.Version(), *iamopt.port)
|
|
if iamApiLocalListener != nil {
|
|
go func() {
|
|
if err = newHttpServer(router, nil).Serve(iamApiLocalListener); err != nil {
|
|
glog.Errorf("IAM API Server Fail to serve: %v", err)
|
|
}
|
|
}()
|
|
}
|
|
if err = newHttpServer(router, nil).Serve(iamApiListener); err != nil {
|
|
glog.Fatalf("IAM API Server Fail to serve: %v", err)
|
|
}
|
|
|
|
return true
|
|
}
|