Repository navigation
nfsmount: make it work on OpenBSD (options, AUTH_UNIX, uid/gid) - #9597
Conversation
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]>
|
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]>
|
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 Second, the mount then fails one step later with 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. |
|
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. |
|
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: 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. So this needs Given that, I'd suggest keeping this PR scoped to what it actually fixes: the |
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]>
|
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: 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
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 One unrelated thing I noticed while testing: the mounted files show up owned by |
|
Great stuff :-) If we advertise AUTH_UNIX and then don't implement anything extra then what will that break? Remember that
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 |
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]>
|
On the AUTH_UNIX safety question: Pushed the uid/gid fix (4294967295 -> real uid/gid) as a separate commit: Docs are next: I'll write up the portmap registration + |
|
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 That's the real |
|
Do the tests for Do they still work for supported platforms (eg linux)? |
|
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):
OpenBSD 7.9 arm64 (real VM, not just reading the diff): Followed the portmap recipe this PR's own docs commit added — registered Mount succeeds, AUTH_UNIX gets past the auth stage (no One thing worth calling out explicitly: running the single |
ncw
left a comment
There was a problem hiding this comment.
Thank you - this looks great now - will merge :-)
What does this change do?
nfsmountdidn't work on OpenBSD at all. This started as a narrow fix forone broken flag and grew into what actually makes
nfsmountfunctionalthere end to end, across five commits:
nfsmountbuilt its mount options assuming GNU/Linuxmount_nfssyntax(
-o port=N,-o mountport=N,-o tcp). OpenBSD'smount_nfs(8)doesn'tunderstand
mountportortcpas-osuboptions, and selects TCP with aseparate
-Tflag instead. Fixed by building OpenBSD-specific options.That fix still didn't run: the options were correct but were being passed
to the generic
mount(8), and-Tis amount_nfs(8)-only flag -mountrejected it with
unknown option -- T. Fixed by callingmount_nfsdirectly on OpenBSD instead of going through
mount.With the command finally running, the mount still failed with
mount_nfs: can't access /: Authentication error. OpenBSD's (and theother BSDs') kernel NFS client requires the server to offer AUTH_UNIX in
the MOUNT reply; rclone's NFS server (
willscott/go-nfs) only advertisedAUTH_NULL. go-nfs never inspects the credential body for either flavor -
the MOUNT handler has a literal
// TODO: auth checkand reads thecredential 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.
Along the way, mounted files showed up owned by 4294967295 (^uint32(0))
on OpenBSD.
vfsflags_unix.go, which callsunix.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/unixalready ships for it.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, confirmedthe 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