Hacker News new | ask | show | jobs
by nextaccountic 1052 days ago
What is directfs? The linked webpage doesn't say
3 comments

The gVisor sandbox doesn't provide direct access to the local file system of the host machine. It routes file requests over RPC to the outside Gofer server running on the host machine. The Gofer server reads the files on the host machine and ships the data back to the sandbox over RPC. This setup is understandably slow.

Linux allows one process to send an opened file descriptor to another process over a domain socket with the SCM_RIGHTS message [1]. The DirectFS setup is basically letting the Gofer process to open a file on the host machine and ships the file descriptor to the sandbox process. The sandbox can then read and write directly on the local file system using the file descriptor.

How the heck can this be securely isolated? Well, via the magic of the pivot_root and umount Linux commands. First, Gofer only sends file descriptors of the files permitted to be accessed by the sandbox, like the files under /sandbox/foobar/. Second, the Gofer process does a pivot_root to change its own file system root "/" to "/sandbox/foobar/." It then does an umount on its old "/" to make it completely unaccessible to any opened file descriptors. This prevents someone using the opened file descriptor to change directory to ../.., ../../etc/passwd or to somewhere in the old root's directories.

I believe this is how it works, based on the reading of the blog post.

[1] https://man7.org/linux/man-pages/man7/unix.7.html

I found this [1]

"We recently landed support for directfs feature in runsc. This is a filesystem optimization feature. It enables the sandbox to access the container filesystem directly (without having to go through the gofer). This should improve performance for filesystem heavy workloads.

You can enable this feature by adding `--directfs` flag to the runtime configuration. The runtime configuration is in `/etc/docker/daemon.json` if you are using Docker. This feature is also supported properly on k8s.

We are looking for early adopters of this feature. You can file bugs or send feedback using this link. We look forward to hearing from you!

NOTE: This is completely orthogonal to the "Root Filesystem Overlay Feature" introduced earlier. You can stack these optimizations together for max performance."

[1] https://groups.google.com/g/gvisor-users/c/v-ODHzCrIjE/m/pqI...

I think it's a gVisor-specific concept. The page says:

> Directfs is a new filesystem access mode that uses these primitives to expose the container filesystem to the sandbox in a secure manner.

So, it's likely this is not a filesystem, but just an implementation detail.

Yes, it's a gVisor feature. They basically utilize SCM_RIGHTS[0] Linux api to open files from the gofer process outside of sandbox and then pass opened fds into the sandbox.

[0] - https://blog.cloudflare.com/know-your-scm_rights/