Skip to content

client, cmds/cpu, cmds/decpu: use localfs and restrict export to -namespace - #337

Open
brho wants to merge 1 commit into
u-root:mainfrom
brho:namespace-filter-localfs
Open

brho wants to merge 1 commit into
u-root:mainfrom
brho:namespace-filter-localfs

Conversation

@brho

@brho brho commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

This PR replaces the client's forked CPU9P implementation with hugelgupf/p9/fsimpl/localfs and restricts the client's 9P and NFS exports to only the paths specified in -namespace by default:

  1. Replace CPU9P with localfs.Attacher:
  2. Restrict 9P and NFS client exports to -namespace by default:
    • Adds ParseBindRemotes to extract the client-side ("remote") paths from -namespace.
    • Adds NewFilter9P (p9.Attacher wrapper) and NewFilterFS (billy.Filesystem + billy.Change wrapper for NFS) that share an allowList:
      • Explicitly exported subtrees allow full read/write access (while blocking removal/renaming of a mount-point root itself when its parent directory is not exported, and preventing symlink escapes outside the allow list).
      • Ancestor directories from / down to each mount point allow read-only traversal (Walk/GetAttr/Stat/Lstat) and filtered Readdir/ReadDir (exposing only allowed child entries) so /tmp/cpu and bind mounts work seamlessly without exposing the rest of / in /tmp/cpu.
      • All other paths under -root return os.ErrNotExist.
  3. Add -unsafe-export flag (default false):
    • Adds -unsafe-export to cmds/cpu and cmds/decpu and client.WithUnsafeExport(bool) to restore the previous behavior of exporting the entire -root directory tree when desired.

@brho
brho requested a review from rminnich November 13, 2026 22:59
@rminnich
rminnich requested review from ericvh and a balanced review from Copilot November 15, 2026 14:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Comment thread client/filter9p.go Resolved
Comment thread client/filter9p.go Outdated
if err != nil {
return nil, nil, err
}
for i := 0; i < len(qids)-1; i++ {

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.

shouldn't f.File.Walk have verified this property? I've never seen a test before against TypeDIr like this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(from gemini) Done — removed qidType and the qids[i].Type != p9.TypeDir check in Walk, leaving that to the underlying p9 server and localfs.

Comment thread client/filter9p.go Resolved
Comment thread client/osnfs.go Outdated
cur := full
var tail []string
for {
resolved, err := filepath.EvalSymlinks(cur)

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.

Do we need to use the safe root path from newer Go here? Remember we should be at 1.27.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(from gemini) Removed along with the other redundant per-operation wrappers on filter9PFile.

Comment thread client/osnfs.go Resolved
Comment thread client/osnfs.go Outdated
if clean == "/" {
return "/", nil
}
root := fs.Filesystem.Root()

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.

ah good. here is Root.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(from gemini) Done — removed resolvePath here and throughout FilterFS.

Comment thread client/osnfs.go Resolved
…espace

- Replace client's forked CPU9P implementation with hugelgupf/p9's
  fsimpl/localfs (which includes {dev, ino} QID collision avoidance
  and full SetAttr/WriteAt/Readdir/Remove/Lock parity).
- Restrict both 9P (NewFilter9P) and NFS (NewFilterFS) client exports
  to only the client-side paths explicitly listed in -namespace by
  default, permitting read-only traversal and filtered directory
  listings on ancestor directories from / down to each mount point.
- Add -unsafe-export flag (default false) to cmds/cpu and cmds/decpu
  and client.WithUnsafeExport(bool) option to restore exporting the
  entire -root tree when needed.
- Add end-to-end 9P and NFSv3 wire tests (client/e2e_export_test.go)
  and full cpud SSH + reverse port-forwarded 9P/NFS daemon tests
  (server/server_linux_test.go).

Signed-off-by: Barret Rhoden <brho@google.com>
@brho
brho force-pushed the namespace-filter-localfs branch from bb47b79 to fc7f231 Compare November 16, 2026 14:18
@brho
brho requested a review from rminnich November 17, 2026 18:08

@rminnich rminnich 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.

can we find some way to NOT embed the private key. This is asking for trouble.
Maybe I'm missing something. But they're very easy to generate dynamically.

Comment thread client/osnfs.go

// Create implements billy.Filesystem.Create.
func (fs *FilterFS) Create(filename string) (billy.File, error) {
if !fs.allow.canRemovePath(filename) {

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.

This naming might confuse people. Why do things that create things call a function called canRemovePath? The user may be able to guess, but perhaps a different function name will help.

Comment thread client/union.go
func (f *fsCPIO) Root() string {
if len(f.mnts) > 0 {
return f.mnts[0].fs.Root()
}

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.

not sure about this but we'll see how it works. What's special about [0]? Is it derived from something else?

Comment thread server/key.go
CAqTAoGAA6rHnhvE9nmrqI4vS3nwSYF5POhP3JjKQMGc5a3H96hf+eJjNihb0NR1
fxHFQ8imFzZ5OxTZOdAJwmbYO1iMS2oJ2GwAG5eI9w+xyyEu+QrCffHGHdFas1+C
uJ2GbxWXZEXGMHS79KrHXMnAFPZLYotgH1v+eTJ631lfZVFCOms=
MIIEpAIBAAKCAQEA65C+hVpY5NbCsPziKjp3JQNJg/fixtxW84kfz790nCpiQx/b

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.

how did we end up embedding a private/public key pair in here? The u-root mount9p command was just changed to use files? I am unsure about this change. A key embedded in source is the same as no key at all, should we just not have a key?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants