Documentation
¶
Overview ¶
Package sandbox implements unprivileged Linux container with hardening options useful for creating application sandboxes.
Index ¶
- Constants
- Variables
- func IgnoringEINTR(fn func() error) error
- func Init(prepare func(prefix string), setVerbose func(verbose bool))
- func LastCap() uintptr
- func MustExecutable() string
- func OverflowGid() int
- func OverflowUid() int
- func Receive(key string, e any, v **os.File) (func() error, error)
- func SetDumpable(dumpable uintptr) error
- func SetOutput(v Msg)
- func Setup(extraFiles *[]*os.File) (int, *gob.Encoder, error)
- func TryArgv0(v Msg, prepare func(prefix string), setVerbose func(verbose bool))
- type AutoEtc
- type BindMount
- type Container
- type DefaultMsg
- func (msg *DefaultMsg) BeforeExit()
- func (msg *DefaultMsg) IsVerbose() bool
- func (msg *DefaultMsg) PrintBaseErr(err error, fallback string)
- func (msg *DefaultMsg) Resume() bool
- func (msg *DefaultMsg) Suspend()
- func (msg *DefaultMsg) Verbose(v ...any)
- func (msg *DefaultMsg) Verbosef(format string, v ...any)
- func (msg *DefaultMsg) WrapErr(err error, a ...any) error
- type HardeningFlags
- type Mkdir
- type MountDev
- type MountMqueue
- type MountProc
- type MountTmpfs
- type Msg
- type Op
- type Ops
- func (f *Ops) Bind(source, target string, flags int) *Ops
- func (f *Ops) Dev(dest string) *Ops
- func (f *Ops) Etc(host, prefix string) *Ops
- func (f *Ops) Grow(n int)
- func (f *Ops) Link(target, linkName string) *Ops
- func (f *Ops) Mkdir(dest string, perm os.FileMode) *Ops
- func (f *Ops) Mqueue(dest string) *Ops
- func (f *Ops) Place(name string, data []byte) *Ops
- func (f *Ops) PlaceP(name string, dataP **[]byte) *Ops
- func (f *Ops) Proc(dest string) *Ops
- func (f *Ops) Tmpfs(dest string, size int, perm os.FileMode) *Ops
- type Params
- type Symlink
- type Tmpfile
Constants ¶
const ( BindOptional = 1 << iota BindWritable BindDevice )
const ( O_PATH = 0x200000 PR_SET_NO_NEW_PRIVS = 0x26 CAP_SYS_ADMIN = 0x15 CAP_SETPCAP = 0x8 )
const ( SUID_DUMP_DISABLE = iota SUID_DUMP_USER )
const ( PR_CAP_AMBIENT = 0x2f PR_CAP_AMBIENT_RAISE = 0x2 PR_CAP_AMBIENT_CLEAR_ALL = 0x4 )
Variables ¶
var ( ErrNotSet = errors.New("environment variable not set") ErrInvalid = errors.New("bad file descriptor") )
Functions ¶
func IgnoringEINTR ¶
IgnoringEINTR makes a function call and repeats it if it returns an EINTR error. This appears to be required even though we install all signal handlers with SA_RESTART: see #22838, #38033, #38836, #40846. Also #20400 and #36644 are issues in which a signal handler is installed without setting SA_RESTART. None of these are the common case, but there are enough of them that it seems that we can't avoid an EINTR loop.
func MustExecutable ¶
func MustExecutable() string
func OverflowGid ¶
func OverflowGid() int
func OverflowUid ¶
func OverflowUid() int
func SetDumpable ¶
Types ¶
type AutoEtc ¶ added in v0.4.0
type AutoEtc struct{ Prefix string }
AutoEtc expands host /etc into a toplevel symlink mirror with /etc semantics. This is not a generic setup op. It is implemented here to reduce ipc overhead.
type Container ¶
type Container struct { // Cgroup fd, nil to disable. Cgroup *int // ExtraFiles passed through to initial process in the container, // with behaviour identical to its [exec.Cmd] counterpart. ExtraFiles []*os.File // Custom [exec.Cmd] initialisation function. CommandContext func(ctx context.Context) (cmd *exec.Cmd) Stdin io.Reader Stdout io.Writer Stderr io.Writer Cancel func(cmd *exec.Cmd) error WaitDelay time.Duration Params // contains filtered or unexported fields }
Container represents a container environment being prepared or run. None of Container methods are safe for concurrent use.
type DefaultMsg ¶
type DefaultMsg struct {
// contains filtered or unexported fields
}
func (*DefaultMsg) BeforeExit ¶
func (msg *DefaultMsg) BeforeExit()
func (*DefaultMsg) IsVerbose ¶
func (msg *DefaultMsg) IsVerbose() bool
func (*DefaultMsg) PrintBaseErr ¶
func (msg *DefaultMsg) PrintBaseErr(err error, fallback string)
func (*DefaultMsg) Resume ¶
func (msg *DefaultMsg) Resume() bool
func (*DefaultMsg) Suspend ¶
func (msg *DefaultMsg) Suspend()
func (*DefaultMsg) Verbose ¶
func (msg *DefaultMsg) Verbose(v ...any)
func (*DefaultMsg) Verbosef ¶
func (msg *DefaultMsg) Verbosef(format string, v ...any)
type HardeningFlags ¶
type HardeningFlags uintptr
const ( FSyscallCompat HardeningFlags = 1 << iota FAllowDevel FAllowUserns FAllowTTY FAllowNet )
type MountMqueue ¶
type MountMqueue string
MountMqueue mounts a private mqueue instance on container Path.
func (MountMqueue) Is ¶
func (m MountMqueue) Is(op Op) bool
func (MountMqueue) String ¶
func (m MountMqueue) String() string
type MountTmpfs ¶
MountTmpfs mounts tmpfs on container Path.
func (*MountTmpfs) Is ¶
func (t *MountTmpfs) Is(op Op) bool
func (*MountTmpfs) String ¶
func (t *MountTmpfs) String() string
type Msg ¶
type Params ¶
type Params struct { // Working directory in the container. Dir string // Initial process environment. Env []string // Absolute path of initial process in the container. Overrides name. Path string // Initial process argv. Args []string // Mapped Uid in user namespace. Uid int // Mapped Gid in user namespace. Gid int // Hostname value in UTS namespace. Hostname string // Sequential container setup ops. *Ops // Extra seccomp options. Seccomp seccomp.FilterOpts // Permission bits of newly created parent directories. // The zero value is interpreted as 0755. ParentPerm os.FileMode // Retain CAP_SYS_ADMIN. Privileged bool Flags HardeningFlags }
Params holds container configuration and is safe to serialise.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package seccomp provides filter presets and high level wrappers around libseccomp.
|
Package seccomp provides filter presets and high level wrappers around libseccomp. |
Package vfs provides bindings and iterators over proc_pid_mountinfo(5).
|
Package vfs provides bindings and iterators over proc_pid_mountinfo(5). |
Package wl implements Wayland security_context_v1 protocol.
|
Package wl implements Wayland security_context_v1 protocol. |