Skip to content

feat(mount): a read-only mount that can actually be turned on (#532) - #536

Merged
scttfrdmn merged 3 commits into
mainfrom
feat/532-read-only-mount
Sep 20, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
feat/532-read-only-mount

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #532.

What was actually missing

The read-only enforcement has been complete since v0.11.0 and unreachable the whole time:

Layer State before this PR
internal/fuse EROFS gates Complete — thirteen of them, across filesystem.go, rename.go, attributes.go, xattr.go
FUSE ro option Present — mount.go:523 appends it when Options.ReadOnly
MountOptions.ReadOnly → go-fuse Wired — platform.go:93
Anything setting MountOptions.ReadOnly Nothing. buildMountOptions set six fields and not that one
internal/config No read_only key at all, so a config file asking for one was rejected as unknown
vfs.ErrReadOnly Defined, mapped to EROFS at errno.go:58, never returned

internal/fuse/mount.go's own yaml:"read_only" tag is a red herring — nothing in the tree
unmarshals YAML into that package, so it has never decoded a byte. This is the same defect
internal/fuse/platform.go:43 records in the past tense about its own predecessor, and the same class
as #180's nine MountOptions fields that named real capabilities and reached nothing. A tested
implementation with no way to turn it on.

What this adds

  • mount.read_only in internal/config, --read-only on objectfs mount, and -o ro in an
    /etc/fstab entry, which /sbin/mount.objectfs now translates instead of refusing.
  • One line each in buildMountOptions and buildWriterOptions — the two mappings whose absence was
    the whole bug.
  • A backstop in internal/vfs, through a new mutatingNode rather than through node itself.
    node is not a write chokepoint: ReadAt and FileSize call it to overlay pending writes and
    to report sizes that include them, so gating it — the obvious implementation — returns EROFS for
    every read, which is the opposite of the feature.

Three enforcing layers, and the redundancy is the design: internal/vfs so that "nothing is dirty" is
a property of the layer that owns dirty state rather than a convention every caller observes;
internal/fuse so the errno is EROFS at the syscall the application made, which is what tells cp
and tar to stop where EACCES sends an operator digging through bucket policies; and the kernel's own
ro so the mount reports itself correctly to mount(8) and statfs.

Two decisions worth reviewing

mount.read_only, not fuse.read_only — a deviation from the approved plan. The fuse block is
scoped to how the kernel is asked to cache and dispatch, settings whose whole effect is the kernel's
behavior. This one's effect is mostly ObjectFS's own and holds whether or not the kernel was told
anything, so filing it under fuse would describe a guarantee as a dispatch flag. Reasoned out at the
field, in buildMountOptions and in buildWriterOptions.

--read-only is one-way, and ro beats rw in either order. A bool flag cannot distinguish
"absent" from "given as false", so an unconditional assignment would make every plain objectfs mount
silently override a config file that said read_only: true. For the same reason the mount helper lets
ro win whichever order -o ro,rw puts them in, where mount(8) would let the last one win: the two
outcomes are not equally bad. Read-only where they meant read-write is a write that gets refused and
noticed; the other direction is bytes overwritten in a bucket they asked to protect. Both pinned by
tests rather than left to fall out of a table.

Proven at the endpoint, and each layer proven without the other

The internal/fuse tests run against a real in-process S3 endpoint over real HTTP and assert its
request log holds no PUT, POST or DELETE across any key — not just the key the test named, because
the failure includes a directory marker for the refused Mkdir or the copy half of a refused Rename. An
errno is a claim ObjectFS makes about itself; the request log is not, and all thirteen errno gates were
already correct on a build whose mounts accepted writes.

Three tests that exist because of what the others cannot see:

  • TestWritableMountRefusesNoneOfThem — every wrong reason for a refusal is still a refusal. Rmdir of
    a directory that does not exist fails; so does Removexattr of an attribute never set. So this asserts
    that no operation returns EROFS on a writable mount, which is what makes EROFS mean the flag.
  • TestEveryFUSEGateFiresOnItsOwn — with both layers armed, deleting FileHandle.Write's gate leaves
    the refusal test green, because the backstop answers with the same errno. Two layers that cover each
    other's absence are what was wanted at runtime and what makes a mutation invisible. This runs with the
    gate armed and the write path writable, so any EROFS came from the gate.
  • TestTheWriterBackstopHoldsWithoutTheFUSEGate — the mirror: the FUSE gate off, the write path
    read-only. It stands for the fourteenth entry point, added later by someone who did not know about the
    thirteen.

Mutation-verified, eight mutations, each compiling

Mutation Caught by
drop ReadOnly from buildMountOptions TestMountReadOnlyReachesBothEnforcingLayers
drop ReadOnly from buildWriterOptions same test, other half
remove the mutatingNode check 6 vfs subtests + TestTheWriterBackstopHoldsWithoutTheFUSEGate
delete FileHandle.Write's gate TestEveryFUSEGateFiresOnItsOwn only — the both-layers test stayed green, exactly as its comment predicts
delete Unlink's gate both fuse tests, and the endpoint log showed the real DELETE
remove the --read-only override arm TestApplyCommandLineOverrides — nothing caught this before, which is why the subtest was added
make the override unconditional --read-only is one-way
turn helper ro back into kindIgnore four TestTranslate cases

Verification

  • make test — green, full suite with -race
  • golangci-lint run ./internal/... ./cmd/... — no finding in any file this PR touches. The 13
    modernize findings are pre-existing and come from the local v2.13.2 rather than CI's pinned
    v2.12.2. GOOS=linux locally cannot typecheck sdks/c at all, since cgo does not cross-compile
    from darwin; that is a local artifact, and CI lints linux natively.

The enforcement has been complete since v0.11.0 and unreachable the whole
time. internal/fuse returned EROFS from thirteen entry points, mount.go
appended the kernel's own `ro`, platform.go copied MountOptions.ReadOnly
into the go-fuse config — and nothing in the tree ever set
MountOptions.ReadOnly. internal/config had no read_only key, so a config
file asking for one was rejected as unknown, and internal/fuse's own
yaml:"read_only" tag has never decoded a byte because nothing unmarshals
into that package. A tested implementation with no way to reach it, which
is the defect platform.go already records in the past tense about its
predecessor.

Adds `mount.read_only` to internal/config, one line each in
buildMountOptions and buildWriterOptions, `--read-only` on the mount
subcommand, and a backstop in internal/vfs. The mount helper's `ro` is a
translation now instead of a refusal.

The vfs backstop goes through a new mutatingNode rather than node itself:
node is not a write chokepoint — ReadAt and FileSize call it to overlay
pending writes and to report sizes that include them — so gating it would
EROFS every read, which is the opposite of the feature.

--read-only is one-way. A bool flag cannot tell "absent" from "given as
false", so an unconditional assignment would make every plain
`objectfs mount` override a config file that said read_only: true. For the
same reason mount.objectfs lets `ro` beat `rw` in either order, where
mount(8) would let the last win.

Proven at the endpoint. The new internal/fuse tests run against a real
in-process S3 endpoint over real HTTP and assert its request log holds no
PUT, POST or DELETE across any key, because an errno is a claim ObjectFS
makes about itself and all thirteen of those errno gates were already
correct on a mount that accepted writes. A companion test asserts no
operation returns EROFS on a writable mount — several fail for other
reasons, and a refusal for the wrong reason is still a refusal. A third
builds the configuration the program cannot produce, write path read-only
with the FUSE gate off, to show the backstop holds when an entry point
forgets.
…532)

Two layers that each cover the other's absence is what was wanted at
runtime and what makes a mutation undetectable: delete the gate at
filesystem.go:1330 and the refusal test stays green, because the vfs
backstop answers with the same errno.

So this runs the same thirteen entry points with the FUSE gate armed and
the write path writable — a configuration internal/adapter cannot produce
— so any EROFS came from the gate itself. With
TestTheWriterBackstopHoldsWithoutTheFUSEGate covering the other
direction, neither layer can stand in for the other in a test.
…532)

The flag was parsed and connected to nothing that any test could see:
deleting the override arm from applyCommandLineOverrides left every
package green, which is #532's own defect one layer up. Two subtests now
cover it — the flag reaching Mount.ReadOnly, and an invocation without it
leaving a config file's read_only: true alone, which is the failure an
unconditional assignment would cause and which nobody notices until
something has been overwritten.

Also corrects a gate count that was written from the plan rather than the
source: thirteen ReadOnly gates in internal/fuse, not ten. Mkdir, Create,
Unlink, Rmdir, Rename, Open, Write, Setattr on a file and on a directory,
and Setxattr and Removexattr on each.
@scttfrdmn scttfrdmn added type: enhancement New feature or improvement to existing functionality priority: medium Important but not urgent area: fuse FUSE layer and filesystem interface area: cli Command-line interface effort: medium Medium effort - 1-2 days labels Sep 19, 2026
@scttfrdmn
scttfrdmn merged commit 9f1b8cf into main Sep 20, 2026
52 checks passed
@scttfrdmn
scttfrdmn deleted the feat/532-read-only-mount branch September 20, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli Command-line interface area: fuse FUSE layer and filesystem interface effort: medium Medium effort - 1-2 days priority: medium Important but not urgent type: enhancement New feature or improvement to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A read-only mount: --read-only for objectfs mount, and ro for the fstab helper

1 participant