diff --git a/README.md b/README.md index 122f495..a482f53 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,7 @@ as a Kubernetes container without config files. | `FUSEY_PREFIX` | _(none)_ | Key prefix for all objects in the bucket (e.g. `pod-abc/`). Use this to share one bucket across multiple Fusey instances | | `FUSEY_COMPACTION_THRESHOLD` | `0.3` | Orphan fraction above which a chunk is targeted by `fusey compact` | | `FUSEY_PERSIST_INTERVAL` | `30s` | How often the index is flushed to disk and the object store | +| `FUSEY_ALLOW_OTHER` | `true` | When `true`, fusey mounts with the FUSE `allow_other` option so any user on the host can access the mountpoint. When `false`, only the UID that called `mount(2)` (the fusey daemon) can access it (the FUSE default). The default is `true` because fusey's typical deployment runs the daemon as root while the consumer (e.g. an agent-server) runs as a non-root user; without `allow_other` the kernel rejects the consumer's VFS operations before fusey's permission code runs. Set `FUSEY_ALLOW_OTHER=false` to restore the FUSE default if you need to restrict access to the mounter's UID. | ### Broker store (alternative to direct S3) diff --git a/cmd/fusey/main.go b/cmd/fusey/main.go index c36d51a..34f4c39 100644 --- a/cmd/fusey/main.go +++ b/cmd/fusey/main.go @@ -208,7 +208,7 @@ func runDaemon(daemonID, mountpoint string) { server, err := gofs.Mount(mountpoint, f.Root(), &gofs.Options{ MountOptions: fuse.MountOptions{ FsName: "fusey", - AllowOther: false, + AllowOther: cfg.AllowOther, DirectMount: true, }, }) diff --git a/internal/config/config.go b/internal/config/config.go index 4d3ae2f..ec851ef 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -15,6 +15,17 @@ const ( DefaultCompactionThreshold float64 = 0.3 DefaultPersistInterval time.Duration = 30 * time.Second DefaultBrokerAuthHeader = "X-SESSION-API-KEY" + // DefaultAllowOther matches the FUSE default (`false`) but is + // overridden to `true` here for fusey's runtime use: when fusey is + // launched inside a sandbox container, the daemon's UID (the user + // that called `mount(2)`) is typically root while the consumer + // process (e.g. an agent-server) runs as a non-root user; without + // `allow_other` the kernel rejects the consumer's VFS operations + // on the mount before fusey's permission code runs. Set + // FUSEY_ALLOW_OTHER=false to opt back into the FUSE default (the + // fusey mount will then only be accessible to the UID that + // mounted it). + DefaultAllowOther = true ) // Config holds all runtime configuration resolved from FUSEY_* environment variables. @@ -73,6 +84,12 @@ type Config struct { CompactionThreshold float64 // PersistInterval is how often the index is flushed to disk and S3 (FUSEY_PERSIST_INTERVAL). PersistInterval time.Duration + + // AllowOther controls the FUSE `allow_other` mount option + // (FUSEY_ALLOW_OTHER, default true). When true, any user on the + // host may access the mount; when false, only the UID that called + // `mount(2)` may access it (the FUSE default). + AllowOther bool } // Load reads FUSEY_* environment variables and returns a populated Config. @@ -94,6 +111,7 @@ func Load() (*Config, error) { BrokerAuthValue: os.Getenv("FUSEY_BROKER_AUTH_VALUE"), CompactionThreshold: DefaultCompactionThreshold, PersistInterval: DefaultPersistInterval, + AllowOther: DefaultAllowOther, } if v := os.Getenv("FUSEY_BROKER_AUTH_HEADER"); v != "" { cfg.BrokerAuthHeader = v @@ -126,6 +144,9 @@ func Load() (*Config, error) { if err := parseDurationEnv("FUSEY_PERSIST_INTERVAL", &cfg.PersistInterval); err != nil { return nil, err } + if err := parseBoolEnv("FUSEY_ALLOW_OTHER", &cfg.AllowOther); err != nil { + return nil, err + } return cfg, nil } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index b227d1d..cebff94 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -25,6 +25,17 @@ func TestLoadDefaults(t *testing.T) { if cfg.CompactionThreshold != DefaultCompactionThreshold { t.Errorf("CompactionThreshold: got %f, want %f", cfg.CompactionThreshold, DefaultCompactionThreshold) } + // AllowOther defaults to true: fusey's typical deployment runs the + // daemon as root (because the container is privileged and the + // mounter needs CAP_SYS_ADMIN) while the consumer (agent-server) + // runs as a non-root user. Without allow_other, the kernel rejects + // the consumer's VFS operations on the mount. + if cfg.AllowOther != DefaultAllowOther { + t.Errorf("AllowOther: got %v, want %v", cfg.AllowOther, DefaultAllowOther) + } + if cfg.AllowOther != true { + t.Errorf("AllowOther: got %v, want true (default must be true)", cfg.AllowOther) + } } func TestLoadEnvOverrides(t *testing.T) { @@ -36,6 +47,7 @@ func TestLoadEnvOverrides(t *testing.T) { t.Setenv("FUSEY_ENDPOINT", "https://s3.example.com") t.Setenv("FUSEY_COMPACTION_THRESHOLD", "0.5") t.Setenv("FUSEY_PERSIST_INTERVAL", "60s") + t.Setenv("FUSEY_ALLOW_OTHER", "false") cfg, err := Load() if err != nil { @@ -65,6 +77,9 @@ func TestLoadEnvOverrides(t *testing.T) { if cfg.PersistInterval != 60*time.Second { t.Errorf("PersistInterval: got %s", cfg.PersistInterval) } + if cfg.AllowOther != false { + t.Errorf("AllowOther: got %v, want false (FUSEY_ALLOW_OTHER=false)", cfg.AllowOther) + } } func TestLoadBadValues(t *testing.T) { @@ -74,6 +89,7 @@ func TestLoadBadValues(t *testing.T) { {"FUSEY_MAX_SIZE", "notanumber"}, {"FUSEY_COMPACTION_THRESHOLD", "notafloat"}, {"FUSEY_PERSIST_INTERVAL", "notaduration"}, + {"FUSEY_ALLOW_OTHER", "yes"}, } for _, c := range cases { t.Run(c.key, func(t *testing.T) { @@ -93,3 +109,33 @@ func TestMaxFSSizeZeroIsInvalid(t *testing.T) { t.Error("expected error for FUSEY_MAX_SIZE=0") } } + +func TestLoadAllowOther(t *testing.T) { + // `1`, `t`, `T`, `TRUE`, `true`, `True` all parse to true per + // strconv.ParseBool. Covers the common opt-in spellings. + for _, v := range []string{"true", "True", "TRUE", "1"} { + t.Run("explicit_true_"+v, func(t *testing.T) { + t.Setenv("FUSEY_ALLOW_OTHER", v) + cfg, err := Load() + if err != nil { + t.Fatalf("Load: %v", err) + } + if !cfg.AllowOther { + t.Errorf("AllowOther: got %v, want true", cfg.AllowOther) + } + }) + } + + for _, v := range []string{"false", "False", "FALSE", "0"} { + t.Run("explicit_false_"+v, func(t *testing.T) { + t.Setenv("FUSEY_ALLOW_OTHER", v) + cfg, err := Load() + if err != nil { + t.Fatalf("Load: %v", err) + } + if cfg.AllowOther { + t.Errorf("AllowOther: got %v, want false", cfg.AllowOther) + } + }) + } +} diff --git a/specs/mount.qnt b/specs/mount.qnt index ca0ea6c..69a8492 100644 --- a/specs/mount.qnt +++ b/specs/mount.qnt @@ -48,6 +48,31 @@ // instead of go-fuse's cryptic "fusermount exited with code 256" you also // get the kernel syscall error (EPERM, EACCES, EBUSY, ...) in mount.log. // +// Configuration (resolved from environment variables at startup): +// FUSEY_ALLOW_OTHER — controls the FUSE `allow_other` mount option +// (default `true`). When `true`, fusey asks the +// kernel for an `allow_other` mount so any user on +// the host may access the mountpoint; when `false`, +// only the UID that called `mount(2)` (the fusey +// daemon) may access it — the FUSE default. fusey +// defaults this to `true` because the typical +// deployment runs the daemon as root (the mounter +// needs `CAP_SYS_ADMIN`) while the consumer process +// (e.g. an agent-server) runs as a non-root user; +// without `allow_other` the kernel rejects the +// consumer's VFS operations before fusey's own +// permission code ever runs. +// +// This spec does NOT model the lifecycle differently based on +// FUSEY_ALLOW_OTHER: the mount option is consumed by gofs.Mount at the +// DaemonStarting → DaemonReady transition and either succeeds (the +// mount is operational with the requested option) or fails +// (`daemonMountFails`) — and that second case covers, among other +// failure modes, the situation where the kernel refuses `allow_other` +// because `/etc/fuse.conf` does not enable `user_allow_other`. The +// `ALLOW_OTHER` constant below is the spec-level projection of the +// env var; invariants in this file hold for both values. +// // CLI dispatch surface: // // cmd/fusey/main.go's main() dispatches on os.Args[1] (with `--version`/ @@ -82,6 +107,19 @@ module mount { + // -------------------------------------------------------------------------- + // Constants + // -------------------------------------------------------------------------- + + // Spec-level projection of the FUSEY_ALLOW_OTHER environment variable: + // when `true`, the daemon requests a FUSE `allow_other` mount so any user + // on the host may access the mountpoint; when `false`, only the UID that + // called `mount(2)` may access it. Modeled as a constant (not a state + // variable) because the value is read once from the environment at + // startup and does not change during the daemon's lifetime. See the + // preamble "Configuration" section for the rationale. + const ALLOW_OTHER: bool + // -------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------