mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
* security: filer token source read from a file FilerTokenFile is the token source of a client that holds a pre-issued filer token rather than a signing key. It reads the file on every call, so an atomic replacement that keeps size and mtime takes effect on the next attempt, and trims surrounding whitespace. A missing, unreadable, empty or malformed file fails the call: there is no fallback to anonymous or admin authority, and errors name the path but not the contents. FilerTokenClaims decodes a token's claims without a key, and FilerTokenGrantCovers compares two grants, so a client can plan reconnects before expiry and know when a replacement narrows what it may see. * mount: -filer.tokenFile authorizes filer calls with a pre-issued token A mount that should not hold a filer signing key can now present a token issued for it. -filer.tokenFile (or -o filer.tokenFile=) names the file; it is read for every filer gRPC attempt, so a replaced file takes effect on the next call or retry without a restart, and a missing or empty file fails the call locally. The source reaches every filer client the mount builds: the startup handshake, each attempt of WithFilerClient, the volume location client, the SSE-S3 reader's configuration call, the peer registrar dial and the lock client. It is attached per call, never to the cached channel, and never to master, volume or peer mount RPCs. The filer refuses MountRegister, MountList and distributed locks to scoped tokens, so the mount refuses to start when -filer.tokenFile is combined with -peer.enable or -dlm instead of failing at run time. Server-side copy_file_range signs its filer HTTP request with the HTTP key, not this token, and is unsupported with it. Without the flag the mount behaves as before. * mount: resubscribe metadata with a replaced filer token A metadata subscription keeps the authority it opened with, so a mount reading -filer.tokenFile would follow with the old token until the filer ended the stream at expiry, and every such end took the gap path that distrusts all cached listings. SubscribeMetaEvents now takes the credentials of each attempt. The mount opens each subscription with the token current at that moment and watches the file; once it holds a different token the attempt ends and the follow resubscribes at once from its checkpoint. This planned resubscribe is not a gap: cached listings stay, unless the new grant may show less than the old one or either token cannot be decoded, in which case they are read again so nothing the old grant showed outlives it. The filer walk treats a resubscribe like a stopped follow, so the same attempt is not replayed on the next filer. Without a token file nothing changes. * mount: hand the mutation stream over to a replaced filer token The mutation stream keeps the token it opened with, and a filer refuses to send on a scoped stream once that token has expired. A mutation applied at that moment loses its reply, the mount reads that as a transport failure, and the unary fallback sends it again. The stream now opens with a snapshot of the token source. Before admitting a request it checks the source: when the file holds another token, or the stream's token would expire before a reply could come back, the stream is retired. New requests wait while the admitted ones are answered, the stream is half-closed so the filer finishes it, and a successor opens with the new token. The waits give up only after filerRPCWait without a response, so a rename that keeps answering is not cut short. A request is never resent by the handover: one still unanswered when the wait gives up fails as on any lost stream, as before. A token too close to expiry to open a stream with is refused before anything is sent, so the request goes out once as a unary call, which the filer checks when it starts. Without a token file nothing changes. * mount: review fixes for the filer token file - A distrust of cached listings now also discards the directory builds in flight, in the meta cache's apply loop: such a build publishes nothing, its entries are wiped and the visit lists the directory again, so a listing read under a grant that has since narrowed is never cached after the distrust. The cached flags are reset again in the loop, after any build that completed before it. - Retiring the mutation stream runs in the background, and a request that waits for the retirement gives up on its own context, unadmitted. - With a token file and no filer signing key, server-side whole-file copy is not tried: its filer HTTP request would go out unsigned and fail as ambiguous. The copy streams through the chunk path instead. - On Windows the token file is opened with delete sharing, so a renewer can replace it by rename while a read holds it open; the missing-file test checks os.ErrNotExist instead of Unix wording. * mount: review fixes for the mutation stream handover A request admitted to the mutation stream with just over one RPC wait left on its token could wait behind a slow send until that margin was gone; its reply could then be refused at expiry and the request was resent over unary. The send loop now checks the margin again right before sending and holds back a request that no longer has it, which is safe to send over unary because the filer never saw it. A sent request whose reply is lost while the token has one RPC wait or less left now fails with EIO instead of a transport error: the filer may have applied it, so it is not resent. Losses with the margin intact fall back to unary as before. A newly opened stream now admits its first request through the same checks as an open one, so a token file replaced, or a token that neared expiry, while the stream opened is caught before anything is sent. A retirement keeps a cancel handle for its stream. Close uses it, so unmount no longer waits for admitted requests to be answered, and a waiter that gives up on a retiring stream stops it as it would stop an open one, so a request still queued there is never sent after that waiter fell back to unary. An ordinary rotation still drains admitted requests. * mount: drop kernel listings when the filer token's grant narrows A replacement token whose grant may not cover the old one already distrusts the mount's own cached listings. The kernel kept its own copy: OpenDir sets FOPEN_CACHE_DIR | FOPEN_KEEP_CACHE, so a directory still reachable under the new grant was listed again from the page cache with names the new grant may hide, until something else invalidated it. On a narrowed or undecodable grant the mount now also notifies the kernel for every directory inode it holds, from the subscription goroutine as the metadata apply path already does, so the next readdir reaches the mount. A readdir already under way on an open handle still finishes from what it read. * mount: drop kernel listings after a subscription gap too distrustCachedListings serves both the narrowed-grant path and the gap path. A gap can lose the very events that would have dropped the kernel's cached listings one directory at a time, and with FOPEN_KEEP_CACHE on OpenDir the kernel then serves those listings on every reopen. Move the kernel drop into distrustCachedListings so both paths get it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
393 lines
12 KiB
Go
393 lines
12 KiB
Go
//go:build darwin || freebsd || linux
|
|
|
|
package command
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"os"
|
|
"os/signal"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
|
|
)
|
|
|
|
type parameter struct {
|
|
name string
|
|
value string
|
|
}
|
|
|
|
func runFuse(cmd *Command, args []string) bool {
|
|
rawArgs := strings.Join(args, " ")
|
|
rawArgsLen := len(rawArgs)
|
|
option := strings.Builder{}
|
|
options := []parameter{}
|
|
masterProcess := true
|
|
fusermountPath := ""
|
|
|
|
// first parameter
|
|
i := 0
|
|
for i = 0; i < rawArgsLen && rawArgs[i] != ' '; i++ {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
options = append(options, parameter{"arg0", option.String()})
|
|
option.Reset()
|
|
|
|
for i++; i < rawArgsLen; i++ {
|
|
|
|
// space separator check for filled option
|
|
if rawArgs[i] == ' ' {
|
|
if option.Len() > 0 {
|
|
options = append(options, parameter{option.String(), "true"})
|
|
option.Reset()
|
|
}
|
|
|
|
// dash separator read option until next space
|
|
} else if rawArgs[i] == '-' {
|
|
for i++; i < rawArgsLen && rawArgs[i] != ' '; i++ {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
// ignore "-o"
|
|
if option.String() != "o" {
|
|
options = append(options, parameter{option.String(), "true"})
|
|
}
|
|
option.Reset()
|
|
|
|
// equal separator start option with pending value
|
|
} else if rawArgs[i] == '=' {
|
|
name := option.String()
|
|
option.Reset()
|
|
|
|
for i++; i < rawArgsLen && rawArgs[i] != ',' && rawArgs[i] != ' '; i++ {
|
|
// double quote separator read option until next double quote
|
|
if rawArgs[i] == '"' {
|
|
for i++; i < rawArgsLen && rawArgs[i] != '"'; i++ {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
|
|
// single quote separator read option until next single quote
|
|
} else if rawArgs[i] == '\'' {
|
|
for i++; i < rawArgsLen && rawArgs[i] != '\''; i++ {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
|
|
// add chars before comma
|
|
} else if rawArgs[i] != ' ' {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
}
|
|
|
|
options = append(options, parameter{name, option.String()})
|
|
option.Reset()
|
|
|
|
// comma separator just read current option
|
|
} else if rawArgs[i] == ',' {
|
|
options = append(options, parameter{option.String(), "true"})
|
|
option.Reset()
|
|
|
|
// what is not a separator fill option buffer
|
|
} else {
|
|
option.WriteByte(rawArgs[i])
|
|
}
|
|
}
|
|
|
|
// get residual option data
|
|
if option.Len() > 0 {
|
|
// add value to pending option
|
|
options = append(options, parameter{option.String(), "true"})
|
|
option.Reset()
|
|
}
|
|
|
|
// scan each parameter
|
|
for i := 0; i < len(options); i++ {
|
|
parameter := options[i]
|
|
|
|
switch parameter.name {
|
|
case "child":
|
|
masterProcess = false
|
|
if parsed, err := strconv.ParseInt(parameter.value, 10, 64); err == nil {
|
|
if parsed > math.MaxInt || parsed <= 0 {
|
|
panic(fmt.Errorf("parent PID %d is invalid", parsed))
|
|
}
|
|
mountOptions.fuseCommandPid = int(parsed)
|
|
} else {
|
|
panic(fmt.Errorf("parent PID %s is invalid: %w", parameter.value, err))
|
|
}
|
|
case "arg0":
|
|
mountOptions.dir = ¶meter.value
|
|
case "filer":
|
|
mountOptions.filer = ¶meter.value
|
|
case "filer.path":
|
|
mountOptions.filerMountRootPath = ¶meter.value
|
|
case "filer.tokenFile":
|
|
mountOptions.filerTokenFile = ¶meter.value
|
|
case "volumeName":
|
|
mountOptions.volumeName = ¶meter.value
|
|
case "dirAutoCreate":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.dirAutoCreate = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("dirAutoCreate: %s", err))
|
|
}
|
|
case "collection":
|
|
mountOptions.collection = ¶meter.value
|
|
case "replication":
|
|
mountOptions.replication = ¶meter.value
|
|
case "disk":
|
|
mountOptions.diskType = ¶meter.value
|
|
case "ttl":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.ttlSec = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("ttl: %s", err))
|
|
}
|
|
case "chunkSizeLimitMB":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.chunkSizeLimitMB = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("chunkSizeLimitMB: %s", err))
|
|
}
|
|
case "cacheMetaTtlSec":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.cacheMetaTtlSec = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("cacheMetaTtlSec: %s", err))
|
|
}
|
|
case "dirIdleEvictSec":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.dirIdleEvictSec = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("dirIdleEvictSec: %s", err))
|
|
}
|
|
case "concurrentWriters":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.concurrentWriters = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("concurrentWriters: %s", err))
|
|
}
|
|
case "concurrentReaders":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err == nil {
|
|
intValue := int(parsed)
|
|
mountOptions.concurrentReaders = &intValue
|
|
} else {
|
|
panic(fmt.Errorf("concurrentReaders: %s", err))
|
|
}
|
|
case "cacheDir":
|
|
mountOptions.cacheDirForRead = ¶meter.value
|
|
case "cacheCapacityMB":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 64); err == nil {
|
|
mountOptions.cacheSizeMBForRead = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("cacheCapacityMB: %s", err))
|
|
}
|
|
case "cacheDirWrite":
|
|
mountOptions.cacheDirForWrite = ¶meter.value
|
|
case "cacheMinFreeSpace":
|
|
mountOptions.cacheMinFreeSpace = ¶meter.value
|
|
case "writeBufferSizeMB":
|
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 64); err == nil {
|
|
mountOptions.writeBufferSizeMB = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("writeBufferSizeMB: %s", err))
|
|
}
|
|
case "dataCenter":
|
|
mountOptions.dataCenter = ¶meter.value
|
|
case "allowOthers":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.allowOthers = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("allowOthers: %s", err))
|
|
}
|
|
case "umask":
|
|
mountOptions.umaskString = ¶meter.value
|
|
case "nonempty":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.nonempty = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("nonempty: %s", err))
|
|
}
|
|
case "defaultPermissions":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.defaultPermissions = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("defaultPermissions: %s", err))
|
|
}
|
|
case "idmap":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.idmap = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("idmap: %s", err))
|
|
}
|
|
case "volumeServerAccess":
|
|
mountOptions.volumeServerAccess = ¶meter.value
|
|
case "sseS3Read":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.sseS3Read = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("sseS3Read: %s", err))
|
|
}
|
|
case "map.uid":
|
|
mountOptions.uidMap = ¶meter.value
|
|
case "map.gid":
|
|
mountOptions.gidMap = ¶meter.value
|
|
case "readOnly":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.readOnly = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("readOnly: %s", err))
|
|
}
|
|
case "disableXAttr":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
|
|
mountOptions.disableXAttr = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("disableXAttr: %s", err))
|
|
}
|
|
case "cpuprofile":
|
|
mountCpuProfile = ¶meter.value
|
|
case "memprofile":
|
|
mountMemProfile = ¶meter.value
|
|
case "readRetryTime":
|
|
if parsed, err := time.ParseDuration(parameter.value); err == nil {
|
|
mountReadRetryTime = &parsed
|
|
} else {
|
|
panic(fmt.Errorf("readRetryTime: %s", err))
|
|
}
|
|
case "fusermount.path":
|
|
fusermountPath = parameter.value
|
|
case "config_dir":
|
|
if err := util.ConfigurationFileDirectory.Set(parameter.value); err != nil {
|
|
panic(fmt.Errorf("config_dir %s: %w", parameter.value, err))
|
|
}
|
|
// FUSE performance options
|
|
case "writebackCache":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.writebackCache = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'writebackCache' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
case "concurrentWriteMerge":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.concurrentWriteMerge = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'concurrentWriteMerge' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
case "asyncDio":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.asyncDio = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'asyncDio' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
case "cacheSymlink":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.cacheSymlink = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'cacheSymlink' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
// macOS-specific FUSE options
|
|
case "sys.novncache":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.novncache = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'sys.novncache' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
case "autofs":
|
|
if parsed, err := strconv.ParseBool(parameter.value); err == nil {
|
|
mountOptions.hasAutofs = &parsed
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "failed to parse 'autofs' value %q: %v\n", parameter.value, err)
|
|
return false
|
|
}
|
|
case "_netdev":
|
|
// _netdev is used for systemd/fstab parser to signify that this is a network mount but systemd
|
|
// mount sometimes can't strip them off. Meanwhile, fuse3 would refuse to run with _netdev, we
|
|
// strip them here if it fails to be stripped by the caller.
|
|
//(See https://github.com/seaweedfs/seaweedfs/wiki/fstab/948a70df5c0d9d2d27561b96de53bde07a29d2db)
|
|
glog.V(0).Infof("ignoring _netdev mount option")
|
|
default:
|
|
t := parameter.name
|
|
if parameter.value != "true" {
|
|
t = fmt.Sprintf("%s=%s", parameter.name, parameter.value)
|
|
}
|
|
mountOptions.extraOptions = append(mountOptions.extraOptions, t)
|
|
}
|
|
}
|
|
|
|
if err := checkIdmap(runtime.GOOS, *mountOptions.idmap, *mountOptions.defaultPermissions); err != nil {
|
|
panic(err)
|
|
}
|
|
// The child checks it as well, but by then the parent only waits for
|
|
// its signal, so a bad value has to fail here.
|
|
if _, err := parseCacheMinFreeSpace(&mountOptions); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
util_http.InitGlobalHttpClient()
|
|
|
|
// the master start the child, release it then finish himself
|
|
if masterProcess {
|
|
arg0, err := os.Executable()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// pass our PID to the child process
|
|
pid := os.Getpid()
|
|
argv := append(os.Args, "-o", "child="+strconv.Itoa(pid))
|
|
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, syscall.SIGTERM)
|
|
|
|
attr := os.ProcAttr{}
|
|
attr.Env = os.Environ()
|
|
|
|
child, err := os.StartProcess(arg0, argv, &attr)
|
|
|
|
if err != nil {
|
|
panic(fmt.Errorf("master process can not start child process: %s", err))
|
|
}
|
|
|
|
err = child.Release()
|
|
|
|
if err != nil {
|
|
panic(fmt.Errorf("master process can not release child process: %s", err))
|
|
}
|
|
|
|
select {
|
|
case <-c:
|
|
return true
|
|
}
|
|
}
|
|
|
|
if fusermountPath != "" {
|
|
if err := os.Setenv("PATH", fusermountPath); err != nil {
|
|
panic(fmt.Errorf("setenv: %s", err))
|
|
}
|
|
} else if os.Getenv("PATH") == "" {
|
|
if err := os.Setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin"); err != nil {
|
|
panic(fmt.Errorf("setenv: %s", err))
|
|
}
|
|
}
|
|
|
|
util.LogTransparentHugePages()
|
|
|
|
// just call "weed mount" command
|
|
return runMount(cmdMount, []string{})
|
|
}
|