Documentation
¶
Overview ¶
Package fileroots confines the file API to configured directories ([file] ManagementRoots). The core runs as root: without a boundary, a signed-in session reads, writes and deletes anything on the machine.
Ported from EdmundFu-233/ReCasaOS pkg/filesecurity (managed roots, Apache-2.0): strict path spelling; on every check the root is opened (no symlink in its path) and the client path resolved with openat2(RESOLVE_BENEATH| RESOLVE_NO_MAGICLINKS) below it, so neither `..` nor a symlink leads out. It is a check before the operation: the operation itself still works on the path (see Check).
Index ¶
- Variables
- func Parse(value string) ([]string, error)
- type Roots
- func (r *Roots) Check(path string) (string, error)
- func (r *Roots) CheckAll(paths []string) ([]string, error)
- func (r *Roots) CheckEach(paths ...*string) error
- func (r *Roots) CheckEntries(paths ...*string) error
- func (r *Roots) CheckEntry(path string) (string, error)
- func (r *Roots) Confined() bool
- func (r *Roots) IsAncestor(path string) bool
- func (r *Roots) Leads(dir, name string) bool
- func (r *Roots) Paths() []string
- func (r *Roots) Unavailable() map[string]error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOutside: the path is not below a root, or resolves out of it. ErrOutside = errors.New("the path is outside the managed file roots") // ErrInvalidRoot: a root in the configuration is not usable. ErrInvalidRoot = errors.New("invalid managed file root") // ErrUnsupported: confinement needs Linux openat2. ErrUnsupported = errors.New("managed file roots need Linux openat2") // replaced by a symlink). ErrRootUnavailable = errors.New("the managed file root is not available") // ErrRootNotReal: the root is a symlink, or spelled through one; roots are // spelled as their real path ErrRootNotReal = errors.New("the managed file root is spelled through a symlink: use its real path") // ErrRoot: a root itself, or a folder above one, is not deleted or renamed. ErrRoot = errors.New("a managed file root is not deleted or renamed") )
Functions ¶
Types ¶
type Roots ¶
type Roots struct {
// contains filtered or unexported fields
}
Roots is the configuration. The zero value and nil are unconfined.
var Default *Roots
Default: the roots of this process ([file] ManagementRoots), set at start. nil: unconfined.
func Open ¶
Open takes the roots (Parse) and makes sure the kernel has openat2. The roots are not opened here but on every check: one mounted later (a disk, a USB stick) is the one checked, and one missing now is refused until it is there (Unavailable). No roots: unconfined.
func Refusing ¶
Refusing: Roots that refuse every path with err (a configuration that cannot be used).
func (*Roots) Check ¶
Check returns the canonical spelling of a client path that resolves below its root, symlinks followed and kept beneath. The root is opened for the check: not there (not mounted yet), or a symlink now → ErrRootUnavailable. A path that does not exist yet (an upload, a new folder, a rename's target) is checked through its nearest existing ancestor; a dangling link on the way is refused (writing through it could land anywhere). Relative links that stay below the root are followed; absolute links are refused, even to inside (RESOLVE_BENEATH). Unconfined: the path as given.
It is a check before the operation: a component swapped for a symlink between the check and the operation is not caught here.
func (*Roots) CheckEach ¶
CheckEach replaces each *path with its canonical spelling, or returns the first error.
func (*Roots) CheckEntries ¶
CheckEntries: CheckEntry for each *path, replaced with its canonical spelling; the first error.
func (*Roots) CheckEntry ¶
CheckEntry is Check for what deletes or renames the entry itself, not what it leads to: its folder must be below a root, the entry need not resolve there (a link that leads out is removed or renamed as a link). A root, or a folder above one, is refused (ErrRoot). Unconfined: the path as given.
func (*Roots) IsAncestor ¶
IsAncestor: path is a directory above a root ("/" above "/DATA") and not itself below one (with /DATA and /DATA/sub, /DATA is managed). Listing it shows only the way down to the roots (Leads).
func (*Roots) Unavailable ¶
Unavailable: the roots that cannot be opened now, with why (for a warning at start): ErrRootUnavailable, and ErrRootNotReal too for one spelled through a symlink.