Documentation
¶
Overview ¶
Package sandbox confines the files a request file may read or write to a file root. Every path that comes from a request file (bodies, multipart files, `output`, certificates, keys, netrc and cookie files, unix sockets) goes through a Root; paths given on the command line do not.
Index ¶
- Variables
- func WriteFileAtomicIn(root *os.Root, rel string, data []byte, perm fs.FileMode) (err error)
- type Root
- func (r *Root) Chmod(name string, perm fs.FileMode) error
- func (r *Root) Close() error
- func (r *Root) Dir() string
- func (r *Root) Lstat(name string) (fs.FileInfo, error)
- func (r *Root) MkdirAll(name string, perm fs.FileMode) error
- func (r *Root) Path(name string) (string, error)
- func (r *Root) ReadDir(name string) ([]fs.DirEntry, error)
- func (r *Root) ReadFile(name string) ([]byte, error)
- func (r *Root) Remove(name string) error
- func (r *Root) Rename(oldname, newname string) error
- func (r *Root) Stat(name string) (fs.FileInfo, error)
- func (r *Root) WriteFile(name string, data []byte) error
- func (r *Root) WriteFileAtomic(name string, data []byte, perm fs.FileMode) error
Constants ¶
This section is empty.
Variables ¶
var ErrDenied = errors.New("access denied outside file root")
ErrDenied reports a path outside the file root (after resolving `..` and symbolic links).
Functions ¶
func WriteFileAtomicIn ¶ added in v1.4.0
WriteFileAtomicIn writes data to rel (slash-separated) inside root via a temporary file in the same directory, synced, then renamed into place and the directory synced, so a reader never sees a partial file and a write cut short leaves the previous content. Parent directories are created as needed (0o755); the file gets permission perm (before the umask).
Types ¶
type Root ¶
type Root struct {
// contains filtered or unexported fields
}
Root is a directory that confines file access.
func (*Root) Lstat ¶ added in v1.4.0
Lstat describes a file without following a final symbolic link.
func (*Root) MkdirAll ¶ added in v1.4.0
MkdirAll creates a directory and its missing parents with permission perm (before the umask).
func (*Root) Path ¶
Path returns the absolute path of name after checking that it stays in the root, for the APIs that need a path (unix sockets).
func (*Root) ReadFile ¶
ReadFile reads a file. name is relative to the root, or absolute and inside it; any other name returns an error wrapping ErrDenied.
func (*Root) Rename ¶ added in v1.4.0
Rename renames (moves) oldname to newname, replacing a file at newname.
func (*Root) Stat ¶ added in v1.4.0
Stat describes a file, following symbolic links inside the root.
func (*Root) WriteFileAtomic ¶ added in v1.4.0
WriteFileAtomic writes a file with permission perm (before the umask) so that a reader, or a process killed while writing, never sees a partial file: see WriteFileAtomicIn. Missing parent directories are created.