Skip to content

feat(vfs,fuse): extended attributes, stored in S3 user metadata (#167) - #416

Merged
scttfrdmn merged 4 commits into
mainfrom
feat/167-xattrs
Aug 9, 2026
Merged

scttfrdmn merged 4 commits into
mainfrom
feat/167-xattrs

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #167.

getfattr, setfattr, and setfattr -x on files, stored in S3 user metadata and durable across a
remount. XATTR_CREATE/XATTR_REPLACE honored; an attribute set to an empty value round-trips as
empty rather than as a removal; a directory answers ENOTSUP rather than go-fuse's default of "no
such attribute", so a caller can tell "this filesystem cannot" from "that attribute is missing".

The security property, verified by mutation

The objectfs-xattr- prefix looks like what keeps a caller's attribute away from the POSIX keys, but
it isn't — the base32 encoding is. Blanking the prefix showed nothing under a narrow -run
filter. Replacing encodeXattrKey's body with strings.ToLower(name) makes
TestSetxattrCannotRewriteThePOSIXAttributes fail on setxattr objectfs-sha256. The test drives
seven adversarial names including objectfs-mode, user.objectfs-mode, and OBJECTFS-MODE. The
alternative to encoding is a filesystem where an unprivileged setfattr rewrites a file's permission
bits.

Three encoding problems, one rule each

A user-metadata key is an HTTP header name, and the direct mapping is silently lossy three ways:

  1. Case — S3 lower-cases keys in transit, so user.Foo and user.foo would overwrite each other.
  2. Character set — an xattr name admits any byte but NUL; a header field name admits only token
    characters.
  3. Value bytes — an xattr value is binary, and a header value carries neither a NUL nor a newline.

Names are base32 (its alphabet survives case folding), values base64 in the URL alphabet
specifically — avoiding +, which Backend.copySource documents real S3 reading as a space in a
header. Cost: 1.6 stored bytes per name byte, and a stored key no longer legible in the console. Both
taken deliberately over a partial escaping scheme, whose edge cases would be the entire risk.

Budget: 1758 bytes, computed not transcribed

S3's 2048-byte limit less the worst-case cost of four POSIX keys plus two integrity keys, each derived
from its own key constant so that renaming one cannot leave the figure stale, and asserted as an
identity by TestXattrBudgetIsTheS3LimitLessWhatObjectFSAlreadySpends. Confirmed by measurement here,
not read off a comment.

The two overruns are distinguished because they call for different actions: one attribute larger than
the whole budget is E2BIG and never fits; a set that no longer fits alongside the others is
ENOSPC and fits again once something is removed. Both refuse at setxattr, not at the next
flush — a setfattr that succeeds and breaks a later write moves the error to a caller who cannot act
on it.

security.* and system.* refused

A privilege boundary, not a gap. Linux reads security.capability on every exec and grants the
capabilities it names. Object metadata is writable by anyone holding s3:PutObject, with the AWS CLI,
without touching the mount — so honoring that attribute would convert bucket write access into file
capabilities on every host that mounts the bucket, an escalation ObjectFS would be creating rather
than inheriting. system.posix_acl_* is refused for the milder version: an ACL getfacl reports
while no access check consults it is worse than a setfacl that fails. user.*, trusted.*, and
com.apple.* are stored; trusted.* stays root-only by the kernel's own check.

A removal is a tombstone

SetObjectMetadata is a self-copy with MetadataDirective=REPLACE, and the backend merges the
object's existing metadata underneath the caller's so the integrity keys — which only the backend has
seen the bytes to compute — survive a chmod. Verified against a real endpoint rather than reasoned
about: a key omitted from the caller's map is not removed from the object. So a removexattr that
merely stopped rendering the key would report success while the attribute stayed readable forever —
the same defect shape as an rm that returns success while the object survives.

The alternative is a full PutObject per removal: 20 GiB of transfer to delete a few bytes from a
10 GiB file. The tombstone costs one metadata entry until the object's next content write, and it is
visible in head-object rather than hidden. Removing an attribute never set writes nothing.

Why metadata and not object annotations

#167 says "object annotations where available". The premise that fails is where available — not
availability. PutObjectAnnotation and its siblings are present in the pinned service/s3 v1.106.3 (checked: api_op_PutObjectAnnotation.go et al. exist), so #165's note that they were
absent was true of an older version and is now stale. They also offer far more room: 1 MiB per
annotation, 1,000 per object, against 2 KB total here. The tradeoff is real.

They lose on the fork. Support is per-endpoint, and two storage formats for one attribute set have no
migration between them: annotations do not survive a transition to a directory bucket, and
CopyObject's default annotation directive does not carry them through a multipart copy. Both are
operations ObjectFS performs itself to persist an attribute change
— so a fallback would drop
attributes during ObjectFS's own writes. By the project thesis's classification this is a
correctness capability (the failure mode is an attribute that reads as absent), so it fails closed
rather than degrading silently. Lifting the 2 KB ceiling is a deliberate, probed, migrating change.

A false README claim removed

README said directory buckets don't support "object annotations, which ObjectFS needs for attributes".
ObjectFS uses metadata, not annotations, so the reason was wrong even though the conclusion is right.
Replaced with the accurate statement that directory buckets are unsupported.

Coverage floor: deliberately not ratcheted here

internal/fuse measures 72.1% locally against a floor of 67, and the obvious move is to ratchet.
Not in this PR: that figure is from darwin, and CI measures on linux, which compiles
unmount_path_linux.go (52 lines) where I compiled unmount_path_darwin.go (44) — a different
statement count and a different result. .coverage-floors's own header records this exact mistake
three times over, including one floor set from an isolated run that failed the very next full-repo
gate: "A floor is a claim about a measurement, so the measurement has to be the one CI takes." No
Docker here to measure linux. The ratchet lands as a second commit on this PR, from the number CI
reports below.

Verification

Local, all clean: go build ./..., gofmt -l ., go vet ./..., golangci-lint run (0 issues),
go test -race -timeout 20m ./... with no FAIL, panic, or DATA RACE, and coverage-gate: 35 package(s) at or above their floor — internal/vfs 98.6% (floor 98%), internal/fuse 72.1% (floor 67%). fuse.ENOATTR confirmed to be syscall.ENODATA on Linux and syscall.ENOATTR on
Darwin/FreeBSD in go-fuse v2.11.0, which is why there is no build-tagged pair here; cross-compiles
clean for GOOS=linux.

xattr_oracle_test.go runs the operation sequence against the local OS filesystem as an oracle,
allowing for the attributes macOS adds on its own (com.apple.provenance on every file it creates).

getfattr, setfattr, and setfattr -x now work on files. XATTR_CREATE and XATTR_REPLACE are
honored, an attribute set to an empty value round-trips as empty rather than as a removal,
and a directory answers ENOTSUP rather than go-fuse's default of "no such attribute" so a
caller can tell "this filesystem cannot" from "that attribute is missing".

Names are base32-encoded and values base64-encoded, because the naive mapping is silently
lossy in three separate ways. A user-metadata key is an HTTP header name: S3 lower-cases it
in transit, so user.Foo and user.foo would overwrite each other, and it admits only token
characters where an xattr name admits any byte but NUL. Values are binary and a header value
carries neither a NUL nor a newline. The URL base64 alphabet specifically, avoiding + (which
real S3 has been observed to read as a space in a header), / and =. The cost is 1.6 stored
bytes per byte of name and a stored key no longer legible in the console; both taken over a
partial escaping scheme whose edge cases would be the entire risk.

The base32 encoding, not the objectfs-xattr- prefix, is what makes collision with the POSIX
attribute keys unrepresentable — verified by mutation. Replacing encodeXattrKey's body with
strings.ToLower(name) makes TestSetxattrCannotRewriteThePOSIXAttributes fail on
`setxattr objectfs-sha256`. That is a security property, not a tidiness one: the alternative
is a filesystem where an unprivileged setfattr rewrites a file's permission bits.

The budget is 1758 bytes, computed rather than written down: S3's 2048-byte limit less the
worst-case cost of four POSIX keys and two integrity keys, each derived from its own key
constant so renaming one cannot leave the figure stale, and asserted as an identity by
TestXattrBudgetIsTheS3LimitLessWhatObjectFSAlreadySpends. The two overruns are reported
differently because they call for different actions: one attribute larger than the whole
budget is E2BIG and never fits, a set that no longer fits alongside the others is ENOSPC and
fits again once something is removed. Both refuse at setxattr rather than at the next flush —
a setfattr that succeeds and breaks a later write moves the error to a caller who cannot act.

security.* and system.* are refused. Linux reads security.capability on every exec and grants
the capabilities it names; object metadata is writable by anyone holding s3:PutObject, so
honoring it would convert bucket write access into file capabilities on every mounting host —
an escalation ObjectFS would be creating, not inheriting. system.posix_acl_* is refused
because storing an ACL the kernel cannot enforce is worse than having none. user.*, trusted.*
and com.apple.* are stored; trusted.* stays root-only by the kernel's own check.

A removal is a tombstone. SetObjectMetadata is a self-copy with MetadataDirective=REPLACE and
the backend merges existing metadata underneath the caller's so the integrity keys survive a
chmod; verified against a real endpoint, a key omitted from the caller's map is not removed
from the object. So a removexattr that merely stopped rendering the key would report success
while the attribute stayed readable forever. The alternative is a full PutObject per removal:
20 GiB of transfer to delete a few bytes from a 10 GiB file.

Object annotations were considered and rejected. They are not unavailable — PutObjectAnnotation
and its siblings are present in the pinned service/s3 v1.106.3, so #165's note that they were
absent is stale — and they offer 1 MiB per annotation against 2 KB total here. They lose on
the fork: support is per-endpoint, and two storage formats for one attribute set have no
migration between them. Annotations do not survive a transition to a directory bucket, and
CopyObject's default annotation directive does not carry them through a multipart copy. Both
are operations ObjectFS performs itself to persist an attribute change, so the fallback would
drop attributes during ObjectFS's own writes.

README's claim that directory buckets lack the annotations ObjectFS needs for attributes was
false — ObjectFS uses metadata, not annotations — and is replaced by the accurate statement
that directory buckets are unsupported.

.coverage-floors is deliberately not ratcheted in this commit. internal/fuse measures 72.1%
here against a floor of 67, but that number is from darwin and CI measures on linux with a
different unmount_path_*.go compiled in. The file's own header records this mistake three
times over: a floor is a claim about a measurement, so the measurement has to be the one CI
takes. Ratcheting follows in a second commit, from CI's figure.

Closes #167
Comment thread internal/fuse/xattr.go Fixed
Comment thread internal/fuse/xattr.go Fixed
Comment thread internal/fuse/xattr.go Fixed
Two defects CI found and darwin could not, both in the #167 xattr work.

**The both-flags errno was one platform's answer, hardcoded.** Setxattr returned EINVAL for a
request naming XATTR_CREATE and XATTR_REPLACE together. That is what darwin's kernel does —
measured, EINVAL whether or not the attribute exists — and what setxattr(2)'s Linux man page
describes. Linux does not implement it: fs/xattr.c has no combined-flag check, so the flags
are tested independently against existence, making the pair ENODATA on a missing attribute
(the REPLACE arm) and EEXIST on a present one (the CREATE arm). Both kernels are
self-consistent and they disagree, so no single errno is right on both.

Now answered by bothXattrFlagsErrno, a build-tagged pair: EINVAL on darwin, and 0 on linux
meaning "no platform answer, fall through", where the existing flag switch reproduces both of
linux's arms from the flags alone. Verified on darwin by making the darwin hook return 0 and
observing ObjectFS produce exactly the two errnos CI reported — attribute not found for the
missing case, file exists for the present one — while the oracle then correctly failed against
darwin's real kernel, which is the proof the split is required rather than cosmetic.

This is what the differential oracle is for and it could not have been caught locally. The
oracle compares against the *local* OS filesystem, so on darwin ObjectFS and the reference
agreed on EINVAL and the test was green. A unit test asserting EINVAL was green too, because a
hand-written expectation encodes the platform of whoever wrote it. The unit test now reads the
same hook rather than naming an errno, and the oracle covers both arms of the divergence, so a
fix that satisfied one platform by hardcoding a constant fails the other.

**Three G115 conversions became one clamped helper.** len(value) to uint32 in xattrRead, at
three sites. gosec reported them on the PR and not locally, the standalone SARIF run being the
one that counts here — a //nolint would not have worked, so xattrSize saturates instead.

Unreachable through the filesystem: an attribute is bounded by vfs.XattrBudget, under 2 KB. The
clamp exists because unreachability is an argument about today's callers, and the reason it
saturates rather than truncates is what a wrap would do to a reader. Both values returned are a
buffer size the caller allocates and reads into, so a wrapped length smaller than the value
gives a caller that sizes a short buffer, gets no ERANGE — the filesystem compared the same
wrapped number — and reads a truncated attribute believing it whole. MaxUint32 cannot be
mistaken for a real size and fails the allocation instead.

The mutation check was the point: deleting the clamp left every test in the package green, so
it was untested. TestXattrSizeSaturatesRatherThanWrapping now fails on the mutant with
`xattrSize(4294967296) = 0` — a 4 GiB attribute reporting size zero.

Verified: build and vet for GOOS=linux and darwin, golangci-lint 0 issues, standalone gosec 0
issues in the xattr files, go test -race across the repo with no FAIL, panic or DATA RACE, and
coverage-gate 35 packages at or above their floor (internal/fuse 72.2%, internal/vfs 98.6%).
@scttfrdmn

Copy link
Copy Markdown
Owner Author

CI found two defects that darwin could not, and both are worth recording because of how they were
found rather than what they were.

1. The both-flags errno was one platform's answer, hardcoded

Setxattr returned EINVAL when a request named XATTR_CREATE and XATTR_REPLACE together. That is
darwin's answer — measured directly, EINVAL whether or not the attribute exists — and it is what
setxattr(2)'s Linux man page describes. Linux does not implement it. fs/xattr.c has no
combined-flag check; each flag is tested independently against existence, so the pair is ENODATA on a
missing attribute (the REPLACE arm) and EEXIST on a present one (the CREATE arm). Both kernels are
self-consistent and they disagree, so no single errno is right on both.

Now a build-tagged bothXattrFlagsErrno: EINVAL on darwin, 0 on linux meaning "no platform answer,
fall through", where the existing flag switch already reproduces both linux arms from the flags alone.

This is what the differential oracle exists for, and it is why a hand-written expectation was not
enough.
The oracle compares against the local OS filesystem — so on darwin, ObjectFS and the
reference agreed on EINVAL and the test was green. The unit test asserting EINVAL was green too,
because a hand-written expectation encodes the platform of whoever wrote it. Only Linux disagreed.

Verified on darwin without a Linux box, by making the darwin hook return 0 to simulate the Linux
path: ObjectFS then produced exactly the two errnos CI reported (attribute not found for the missing
case, file exists for the present one), and the oracle correctly failed against darwin's real
kernel — which is the proof that the split is required rather than cosmetic. The unit test now reads
the same hook instead of naming an errno, and the oracle covers both arms, so a fix that satisfied
one platform by hardcoding a constant fails the other.

2. Three G115 conversions, now one clamped helper

len(value) → uint32 at three sites in xattrRead. Reported by the standalone gosec SARIF run,
which is the one that counts here — a //nolint:gosec would not have worked, since this repo runs
gosec twice and only the golangci-lint invocation honors it (#415).

Unreachable through the filesystem: an attribute is bounded by vfs.XattrBudget, under 2 KB. The clamp
is there because unreachability is an argument about today's callers, not about the function. It
saturates rather than truncates because of what a wrap does to a reader: both returned values are
a buffer size the caller allocates and reads into, so a wrapped length smaller than the value gives a
caller that sizes a short buffer, gets no ERANGE (the filesystem compared the same wrapped number),
and reads a truncated attribute believing it whole. MaxUint32 cannot be mistaken for a real size and
fails the allocation instead.

The mutation check was the point: deleting the clamp left every test in the package green, so it was
untested. TestXattrSizeSaturatesRatherThanWrapping now fails on the mutant with
xattrSize(4294967296) = 0 — a 4 GiB attribute reporting size zero.

Verification

go build and go vet for both GOOS=linux and darwin, golangci-lint 0 issues, standalone gosec
0 issues in the xattr files
(run locally this time, not discovered on CI), go test -race across the
repo with no FAIL/panic/DATA RACE, and coverage-gate: 35 package(s) at or above their floor —
internal/fuse 72.2%, internal/vfs 98.6%.

The .coverage-floors ratchet still waits for CI's own linux figure, per the reasoning in the PR body.

`n > math.MaxUint32` does not compile where int is 32 bits wide: the untyped constant does not
fit the type it is compared against. linux/386 and linux/arm failed the cross-build matrix
while every test passed on this 64-bit host, because the defect is a compile error and not a
wrong answer. The comparison now widens through uint64, which is correct on both — where int is
32 bits the branch is unreachable, and where it is 64 bits it is the real bound.

The test had the same bug in the same shape, and the fix there is not just a wider comparison:
`int(uint64(math.MaxUint32))` is still a constant expression, so it fails to compile on a
32-bit target even inside a branch that can never be taken there — constant conversions are
checked before any branch is considered. The bound goes through a uint64 *variable*, and the
two over-MaxUint32 rows are appended conditionally rather than filtered afterwards, because on
a 32-bit platform the arithmetic that produces them collapses onto values the other rows
already use and a value-based filter would let a row through with the wrong expectation.

CI's cross-build comment describes this defect in advance, from #198: `safeIntToUint32` guarded
its conversion with `i > 0xFFFFFFFF` and internal/fuse did not compile for any 32-bit target,
which cost linux/armv7 a place in the release matrix. The 32-bit cells were added then, and the
`go vet` step alongside them exists because `go build` does not compile _test.go files — the
comment names `int(math.MaxUint32)` in a test as the same error in the same shape. Both cells
and both steps did their job here.

Verified: go vet across linux/386, linux/arm, linux/amd64, linux/arm64 and darwin — which
compiles the tests, unlike go build — golangci-lint 0 issues, and the clamp's mutation check
re-run after the rewrite, still failing with xattrSize(4294967296) = 0.
…→ 72

The second commit the xattr work said it would need. #167's tests took internal/fuse from 67% to
72.5%, and the floor is now that, so the points are held rather than merely earned.

The figure is read from the `coverage` job's log on this PR, not from a local run. That is the whole
reason this is a separate commit, and it is a stronger reason here than the load-dependence the file's
existing notes describe: CI is ubuntu-latest and compiles unmount_path_linux.go (52 lines) where a
darwin run compiles unmount_path_darwin.go (44). The denominators differ, so the percentages do —
72.5% on linux against 72.2% on darwin for the same tree. Most of the package is tagged
`linux || darwin`, which makes the one single-platform pair easy to overlook.

72 rather than 72.5 for the usual reason: the file is integers, and both platforms clear it. Zero
margin is deliberate per the header — "widen the test, not the margin."

Verified with ./scripts/coverage-gate.sh over a full `go test ./...` profile: 35 packages at or above
their floor, internal/fuse 72.2% (floor 72%).
@scttfrdmn

Copy link
Copy Markdown
Owner Author

Ratchet landed in 4616ce1: internal/fuse 67 → 72, from the coverage job's own figure on this PR (72.5%), not a local run.

The gap between platforms turned out to be real and worth recording in the file: CI is ubuntu-latest and compiles unmount_path_linux.go (52 lines) where a darwin run compiles unmount_path_darwin.go (44), so the same tree measures 72.5% there and 72.2% here. 72 is what both clear. Zero margin is deliberate per the file's header — "widen the test, not the margin."

@scttfrdmn
scttfrdmn merged commit 6e8e0eb into main Aug 9, 2026
38 checks passed
@scttfrdmn
scttfrdmn deleted the feat/167-xattrs branch August 9, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C4-5: Implement extended attribute operations

2 participants