Skip to content

nfsmount: make it work on OpenBSD (options, AUTH_UNIX, uid/gid) - #9597

Merged
ncw merged 6 commits into
rclone:masterfrom
Socialpranker:fix/8578-bsd-nfsmount
Jul 30, 2026
Merged

ncw merged 6 commits into
rclone:masterfrom
Socialpranker:fix/8578-bsd-nfsmount

Conversation

@Socialpranker

@Socialpranker Socialpranker commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

What does this change do?

nfsmount didn't work on OpenBSD at all. This started as a narrow fix for
one broken flag and grew into what actually makes nfsmount functional
there end to end, across five commits:

  1. nfsmount built its mount options assuming GNU/Linux mount_nfs syntax
    (-o port=N, -o mountport=N, -o tcp). OpenBSD's mount_nfs(8) doesn't
    understand mountport or tcp as -o suboptions, and selects TCP with a
    separate -T flag instead. Fixed by building OpenBSD-specific options.

  2. That fix still didn't run: the options were correct but were being passed
    to the generic mount(8), and -T is a mount_nfs(8)-only flag - mount
    rejected it with unknown option -- T. Fixed by calling mount_nfs
    directly on OpenBSD instead of going through mount.

  3. With the command finally running, the mount still failed with
    mount_nfs: can't access /: Authentication error. OpenBSD's (and the
    other BSDs') kernel NFS client requires the server to offer AUTH_UNIX in
    the MOUNT reply; rclone's NFS server (willscott/go-nfs) only advertised
    AUTH_NULL. go-nfs never inspects the credential body for either flavor -
    the MOUNT handler has a literal // TODO: auth check and reads the
    credential as an opaque blob, and no NFS procedure handler (GetAttr, Read,
    Write, etc.) branches on which flavor was used. So advertising AUTH_UNIX
    in addition to AUTH_NULL costs nothing for existing Linux/macOS clients
    and unblocks the BSD ones.

  4. Along the way, mounted files showed up owned by 4294967295 (^uint32(0))
    on OpenBSD. vfsflags_unix.go, which calls unix.Geteuid()/unix.Getegid()
    to report the real uid/gid, only built for linux/darwin/freebsd; OpenBSD
    fell through to the non-unix zero-value stub. Fixed by adding openbsd to
    the build tag - it needs no OS-specific code, just the same POSIX calls
    golang.org/x/sys/unix already ships for it.

  5. Documented the working procedure (portmap registration, mount_nfs -T,
    AUTH_UNIX background) so an OpenBSD user can follow the docs instead of
    digging through this thread.

All five commits have been tested end to end on a real OpenBSD 7.9 arm64 VM:
registered rclone's server in portmap, mounted with mount_nfs -T, confirmed
the mount succeeds, files read back correctly, AUTH_UNIX is what gets past
the auth stage, and (re-verified separately) mounted files show the real
uid/gid instead of 4294967295.

Linked issue

Fixes #8578

Checklist

  • This change is trivial OR it has been discussed and agreed in the linked issue.
  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • (Backend changes only) test_all passes for this backend and I can provide a test account for the integration tester.
  • This Pull Request is ready for review.

nfsmount built its mount options for GNU/Linux syntax unconditionally:
"-o port=N", "-o mountport=N" and "-o tcp". OpenBSD's mount_nfs(8)
rejects "-o mountport" outright ("option not supported", per the
reporter's log) and has no "tcp" suboption either, since it selects
TCP with the separate "-T" flag instead of an -o suboption.

Add a runtime.GOOS == "openbsd" branch that builds the option list
OpenBSD's mount_nfs actually accepts: "-o port=N" plus "-T" for TCP,
with no mountport option since OpenBSD's mountd is located via
portmap rather than a fixed, settable port. This follows the same
GOOS-branching pattern already used in this file's unmount function
(darwin) and in cmd/cmount/mount.go for openbsd/freebsd differences.

FreeBSD's mount_nfs(8) documents "port=", "mountport=" and "tcp" as
-o suboptions identical to Linux, so the existing option set is left
unchanged for freebsd and all other platforms.

Verified by cross-compiling (go build and go vet) for GOOS=openbsd,
freebsd, linux and darwin, all of which succeed. Actually mounting
via mount_nfs on OpenBSD needs a BSD machine to confirm at runtime,
which wasn't available here.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@Socialpranker
Socialpranker requested a review from ncw as a code owner July 11, 2026 05:33
@ncw

ncw commented Jul 11, 2026

Copy link
Copy Markdown
Member

Nice fix, but I need to have it tested on Openbsd.

I suspect needing the portmapper will make it fail unfortunately.

There may be a workaround by manually inserting the portmapper entry after rclone has started but that needs implementing or documenting at least.

Can you install an Openbsd VM?

The previous OpenBSD path built the right options ("-o port=N -T") but
still handed them to mount(8). On OpenBSD "-T" is a mount_nfs(8) flag,
not a mount(8) one, so mount rejected it with "mount: unknown option --
T" and the mount never ran. Call mount_nfs(8) directly on OpenBSD; the
options are already in its native syntax.

Verified on a real OpenBSD 7.9 arm64 VM: with this change the command
becomes "mount_nfs -o port=N -T localhost:/ <mnt>" and mount_nfs accepts
the flags. The mount then fails later with "Stale NFS file handle"
because the OpenBSD client and rclone's in-process NFS server disagree
on the root filehandle - that is a separate issue in the NFS server,
not in the mount options this PR is about.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@Socialpranker

Copy link
Copy Markdown
Contributor Author

Set up an OpenBSD 7.9 arm64 VM and tested this. You were right that it wasn't going to just work, and it turned up two things.

First, the fix as it stood didn't run at all. The options were correct, but they went to mount, and -T is a mount_nfs(8) flag, not a mount(8) one, so OpenBSD rejected it with mount: unknown option -- T before anything mounted. I pushed a follow-up that calls mount_nfs directly on OpenBSD. With that, the command becomes mount_nfs -o port=N -T localhost:/ <mnt> and mount_nfs accepts the flags, so the option handling this PR is about now works.

Second, the mount then fails one step later with mount_nfs: Stale NFS file handle. Watching the server side, the OpenBSD client never issues a MOUNT RPC and instead sends a 28-byte handle straight to a GetAttr, which rclone's in-process NFS server rejects (FromHandle ... invalid UUID). That looks like a mismatch between the OpenBSD client and the serve-nfs handle format rather than anything about the mount options, and I couldn't get any mount_nfs invocation past it (tried v2/v3, -U, disk vs memory cache). Confirmed the same "not supported" error from the issue for the old -o mountport= path along the way, so the direction here is right.

Do you want to keep this PR scoped to the option fix (mount_nfs plus -T, which is a genuine prerequisite), and track the handle mismatch separately? Or would you rather I dig into the serve-nfs handle side first? Happy to go either way.

@ncw

ncw commented Jul 11, 2026

Copy link
Copy Markdown
Member

Ideally this PR should make the NFS server work at least a little bit on Openbsd.

Happy to have multiple commits but keep each one to a specific purpose.

I suspect that chasing handle formats is a dead end. Handles are opaque. Read the docs on rclone's handle cache. Restart the kernel client (might involve restarting the VM) between tries as it catches handles which can confuse things.

@Socialpranker

Copy link
Copy Markdown
Contributor Author

Chased this down. My laptop nearly caught fire from all the OpenBSD VM reboots, but I got there.

You were right that handle formats are a dead end, though not for the reason I first thought. My earlier "Stale handle" was a red herring: I was mounting straight at the port and skipping portmap, so the client never did a proper MOUNT and sent a bogus handle. Following hjicks' recipe from #8578 instead (stop the system nfsd/portmap/mountd, start portmap, register rclone's server in it with rpcinfo), the MOUNT RPC goes through fine and the client gets a real root filehandle.

Then it fails one step later with exactly what hjicks saw:

mount_nfs: can't access /: Authentication error

So the wall isn't the handle cache and it isn't the kernel caching handles between tries (I confirmed that by fully rebooting the VM between attempts and getting the identical handle, so it's constructed client-side, not cached). The wall is auth. willscott/go-nfs only ever advertises AUTH_NULL in the MOUNT reply, and the BSD NFS clients want AUTH_UNIX. That matches your grep of the library and hjicks' wireshark capture showing Flavor: AUTH_NULL.

So this needs AUTH_UNIX support added to the go-nfs server, which is a much bigger and cross-BSD job than this PR.

Given that, I'd suggest keeping this PR scoped to what it actually fixes: the mount_nfs invocation (so OpenBSD gets past mount: unknown option -- T and actually reaches the auth stage), and tracking the AUTH_UNIX work separately. That way the option handling is correct and ready for whenever the auth side lands. Happy to open a separate issue for the auth part if that's useful.

The mount served fine on Linux and macOS but *BSD kernel NFS clients
refused it with "Authentication error". The MOUNT reply only ever
offered AUTH_NULL, and the OpenBSD/FreeBSD/NetBSD clients won't mount a
server unless AUTH_UNIX is among the offered flavors.

Add AUTH_UNIX to the advertised list. The server still doesn't inspect
the credential (there's no per-user access control here) so the AUTH_UNIX
cred the client then sends is read as an opaque blob and ignored, exactly
as the AUTH_NULL one was. No behaviour change for existing Linux/macOS
clients, and OpenBSD now mounts and reads files over the share.

Verified on a real OpenBSD 7.9 arm64 VM: registered rclone's server in
portmap and ran "mount_nfs -T localhost:/ /mnt"; the mount now succeeds
(MOUNT and GetAttr RPCs go through) and files read back correctly through
the mount, where before it stopped at the auth stage.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@Socialpranker
Socialpranker requested a review from albertony as a code owner July 12, 2026 10:20
@Socialpranker

Copy link
Copy Markdown
Contributor Author

Correction to my last comment: I said the AUTH_UNIX side was a big cross-BSD change in go-nfs. That was wrong, and I should have checked before saying it. The flavor list isn't in the library, it's right here in rclone: Handler.Mount in cmd/serve/nfs/handler.go hands back []nfs.AuthFlavor{nfs.AuthFlavorNull}. go-nfs never actually inspects the credential (it reads it as an opaque blob, and the mount path there is a // TODO: auth check), so all that's needed is to also offer AUTH_UNIX. One line.

With that added, OpenBSD mounts and reads. I ran it as a clean A/B on a fresh 7.9 VM, same recipe both times (register the server in portmap the way hjicks described, then mount_nfs -T localhost:/), the only difference being the one-line change:

  • without AUTH_UNIX: mount_nfs: can't access /: Authentication error, nothing mounts
  • with AUTH_UNIX: mount succeeds, ls shows the files and cat returns a test file byte-for-byte. Reran it to be sure it wasn't a fluke.

So this PR can actually make the NFS server work on OpenBSD, which is what you were hoping for. I've got three commits now, each doing one thing: the original option fix, the mount_nfs/-T follow-up so the mount command even runs, and this AUTH_UNIX line so it gets past auth. Happy to squash if you'd rather have fewer.

One unrelated thing I noticed while testing: the mounted files show up owned by 4294967295 (^uint32(0)). That's because vfsflags_unix.go is built for linux || darwin || freebsd and OpenBSD isn't in the tag, so it falls back to the non-unix uid/gid. It's a pre-existing thing, separate from this PR, but easy to fold in or file separately if you want.

@ncw

ncw commented Jul 12, 2026

Copy link
Copy Markdown
Member

Great stuff :-)

If we advertise AUTH_UNIX and then don't implement anything extra then what will that break? Remember that serve nfs is already in use by many clients so if we advertise improperly implemented features we are bound to break stuff.

One unrelated thing I noticed while testing: the mounted files show up owned by 4294967295 (^uint32(0)). That's because vfsflags_unix.go is built for linux || darwin || freebsd and OpenBSD isn't in the tag, so it falls back to the non-unix uid/gid. It's a pre-existing thing, separate from this PR, but easy to fold in or file separately if you want.

Fix that too.

Let's target this PR as "Make nfsmount work on OpenBSD"

Also update the docs with special procedures needed for OpenBSD. I want an OpenBSD user to be able to read the docs and use rclone nfsmount without referring elsewhere.

Socialpranker and others added 2 commits July 12, 2026 16:40
Mounted files showed up owned by 4294967295 (^uint32(0)) on OpenBSD.
vfsflags_unix.go, which calls unix.Geteuid()/unix.Getegid() to get the
real uid/gid, only builds for linux, darwin and freebsd; OpenBSD fell
through to vfsflags_non_unix.go's zero-value stub instead.

OpenBSD has no linux/darwin/freebsd-specific fields here, just the same
POSIX Geteuid/Getegid/Umask calls golang.org/x/sys/unix already ships
for openbsd on every arch, so this just adds openbsd to both build tags
rather than needing a separate file.

Cross-compiled for GOOS=openbsd (arm64, amd64) and go vet clean; ran the
existing vfs test suite on darwin, no regressions. Not yet verified on a
live OpenBSD mount, only that the right uid/gid syscalls now get called
in this codepath.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Cover the portmap registration OpenBSD's kernel NFS client needs (recipe
from hjicks in #8578), the mount_nfs -T requirement, and why the server
advertises AUTH_UNIX, so an OpenBSD user doesn't need to read through the
issue thread to get a working mount.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@Socialpranker Socialpranker changed the title nfsmount: fix mount_nfs options incompatible with OpenBSD nfsmount: make it work on OpenBSD (options, AUTH_UNIX, uid/gid) Jul 12, 2026
@Socialpranker

Copy link
Copy Markdown
Contributor Author

On the AUTH_UNIX safety question: go-nfs never inspects the credential body for any flavor, it's read as an opaque blob and there's a // TODO: auth check where validation would go. So advertising AUTH_UNIX doesn't add any enforcement that could be wrong, it just widens the set of flavors the MOUNT reply offers. A client that already worked with AUTH_NULL keeps working exactly as before; the only change is that BSD clients requiring AUTH_UNIX in the list can now get past the mount handshake. I don't see a path where this breaks an existing client, since nothing downstream branches on which flavor was used.

Pushed the uid/gid fix (4294967295 -> real uid/gid) as a separate commit: vfsflags_unix.go only builds for linux/darwin/freebsd, so OpenBSD fell through to the non-unix zero-value stub instead of calling unix.Geteuid()/unix.Getegid(). Added openbsd to both build tags; those are plain POSIX syscalls x/sys/unix already has for openbsd, no BSD-specific fields involved. Cross-compiled clean for openbsd/arm64 and openbsd/amd64, existing vfs suite still passes. Haven't re-run this specific one on the VM yet, will do that next.

Docs are next: I'll write up the portmap registration + mount_nfs -T procedure so an OpenBSD user can follow it without digging through this thread.

@Socialpranker

Copy link
Copy Markdown
Contributor Author

Follow-up on the uid/gid fix: re-ran it end to end on the OpenBSD 7.9 arm64 VM (not just cross-compiled this time). Built the branch, ran serve nfs, registered with portmap, mounted with mount_nfs -T -o port=..., and checked ownership through the mount:

$ stat -f '%u %g %N' /tmp/nfstest/mnt/hello.txt
1000 1000 /tmp/nfstest/mnt/hello.txt

That's the real tester uid/gid (1000/1000), not 4294967295. Content reads back correctly too. All five commits are now verified on live OpenBSD, not just the first three.

@ncw

ncw commented Jul 13, 2026

Copy link
Copy Markdown
Member

Do the tests for rclone nfsmount work on Openbsd now?

Do they still work for supported platforms (eg linux)?

@Socialpranker

Copy link
Copy Markdown
Contributor Author

Tested this for real — built the branch, ran the existing test suite on macOS, and stood up a real OpenBSD 7.9 arm64 VM (qemu, HVF-accelerated) to exercise the actual mount path end to end.

Supported platforms (macOS as a stand-in for the shared unix code path):

go test ./cmd/nfsmount/... -run TestMount -v
--- PASS: TestMount (83.06s)  [256 subtests, 1 skip, 0 fail]
--- PASS: TestSubpathMount
go test ./cmd/serve/nfs/... ./vfs/... ./vfs/vfscommon/...
ok  	github.com/rclone/rclone/cmd/serve/nfs
ok  	github.com/rclone/rclone/vfs
ok  	github.com/rclone/rclone/vfs/vfscache
ok  	github.com/rclone/rclone/vfs/vfscache/downloaders
ok  	github.com/rclone/rclone/vfs/vfscache/writeback
ok  	github.com/rclone/rclone/vfs/vfscommon

GOOS=linux GOARCH=amd64 go build . also compiles clean. Nothing here is broken by this PR.

OpenBSD 7.9 arm64 (real VM, not just reading the diff):

Followed the portmap recipe this PR's own docs commit added — registered rclone serve nfs's port with rpcinfo -s nfs 3 <PORT> / rpcinfo -s mountd 3 <PORT> after starting portmap — then ran mount_nfs -o port=<PORT> -T localhost:/ /mnt:

$ mount | grep nfs
localhost:/ on /mnt/nfstest type nfs (v3, tcp, timeo=100, retrans=101)
$ cat /mnt/nfstest/test.txt
hello nfs test
$ ls -ln /mnt/nfstest/test.txt
-rw-r--r--  1 0  0  15 Jul 14 06:54 /mnt/nfstest/test.txt

Mount succeeds, AUTH_UNIX gets past the auth stage (no Authentication error), file reads back correctly, and ownership shows real uid=0 gid=0 — not 4294967295. All three fixes (mount_nfs invocation, AUTH_UNIX, uid/gid) check out.

One thing worth calling out explicitly: running the single rclone nfsmount command without first doing the manual portmap registration hangs on mount_nfs and times out — which matches what your docs commit already says (portmap registration is a manual step, not something nfsmount automates on OpenBSD), but I wanted to confirm it in practice so it doesn't read as "nfsmount just works" from the PR title alone. Might be worth a line in the top-level PR description if it isn't already clear that OpenBSD users still need the portmap dance from the docs section before nfsmount (or a manual mount_nfs) will succeed.

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you - this looks great now - will merge :-)

@ncw
ncw merged commit afa25e9 into rclone:master Jul 30, 2026
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.

“rclone nfsmount” uses mount_nfs incompatible with BSD Unix

2 participants