Documentation
¶
Overview ¶
Package rootfs provides an afero.Fs implementation backed by Go's os.Root API. This confines all filesystem operations to a root directory with atomic protection against symlink-based escape attacks via openat2/RESOLVE_BENEATH.
Index ¶
- type RootFs
- func (r *RootFs) Chmod(name string, mode os.FileMode) error
- func (r *RootFs) Chown(name string, uid, gid int) error
- func (r *RootFs) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (r *RootFs) Close() error
- func (r *RootFs) Create(name string) (afero.File, error)
- func (r *RootFs) Mkdir(name string, perm os.FileMode) error
- func (r *RootFs) MkdirAll(path string, perm os.FileMode) error
- func (r *RootFs) Name() string
- func (r *RootFs) Open(name string) (afero.File, error)
- func (r *RootFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error)
- func (r *RootFs) Remove(name string) error
- func (r *RootFs) RemoveAll(path string) error
- func (r *RootFs) Rename(oldname, newname string) error
- func (r *RootFs) Stat(name string) (os.FileInfo, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RootFs ¶
type RootFs struct {
// contains filtered or unexported fields
}
RootFs is an afero.Fs implementation backed by os.Root. All operations are confined to the root directory using Go's os.Root API, which provides atomic protection against symlink-based escape attacks via the kernel's openat2/RESOLVE_BENEATH on Linux.
Security model:
- All paths are treated as relative to the root directory
- Leading slashes are stripped (e.g., "/foo" becomes "foo")
- Symlinks within the root that resolve within the root are allowed
- Symlinks that would escape the root are rejected atomically by the kernel
- No TOCTOU vulnerabilities: symlink checks happen at the kernel level during file open, not as separate stat+open operations
func New ¶
New creates a new RootFs rooted at the given directory path. The path must exist and be a directory.
Click to show internal directories.
Click to hide internal directories.