Documentation
¶
Overview ¶
Package control contains types that expose control server methods, and can be used to configure and interact with a running sandbox process.
Index ¶
- Constants
- Variables
- func ContainerUsage(kr *kernel.Kernel) map[string]uint64
- func ExecAsync(proc *Proc, args *ExecArgs) (*kernel.ThreadGroup, kernel.ThreadID, *host.TTYFileOperations, ...)
- func PrintPIDsJSON(pl []*Process) (string, error)
- func ProcessListToJSON(pl []*Process) (string, error)
- func ProcessListToTable(pl []*Process) string
- func Processes(k *kernel.Kernel, containerID string, out *[]*Process) error
- type BlockProfileOpts
- type CPUProfileOpts
- type CatOpts
- type Events
- type EventsOpts
- type ExecArgs
- type Fs
- type GoroutineProfileOpts
- type HeapProfileOpts
- type Lifecycle
- type Logging
- type LoggingArgs
- type MemoryUsage
- type MemoryUsageFile
- type MemoryUsageFileOpts
- type MemoryUsageOpts
- type MemoryUsageRecord
- type MutexProfileOpts
- type Proc
- type Process
- type Profile
- func (p *Profile) Block(o *BlockProfileOpts, _ *struct{}) error
- func (p *Profile) CPU(o *CPUProfileOpts, _ *struct{}) error
- func (p *Profile) Goroutine(o *GoroutineProfileOpts, _ *struct{}) error
- func (p *Profile) Heap(o *HeapProfileOpts, _ *struct{}) error
- func (p *Profile) Mutex(o *MutexProfileOpts, _ *struct{}) error
- func (p *Profile) Stop()
- func (p *Profile) Trace(o *TraceProfileOpts, _ *struct{}) error
- type PsArgs
- type SaveOpts
- type State
- type TraceProfileOpts
- type Usage
- type UsageReduceOpts
- type UsageReduceOutput
Constants ¶
const ( // DefaultBlockProfileRate is the default profiling rate for block // profiles. // // The default here is 10%, which will record a stacktrace 10% of the // time when blocking occurs. Since these events should not be super // frequent, we expect this to achieve a reasonable balance between // collecting the data we need and imposing a high performance cost // (e.g. skewing even the CPU profile). DefaultBlockProfileRate = 10 // DefaultMutexProfileRate is the default profiling rate for mutex // profiles. Like the block rate above, we use a default rate of 10% // for the same reasons. DefaultMutexProfileRate = 10 )
Variables ¶
var ErrInvalidFiles = errors.New("exactly one file must be provided")
ErrInvalidFiles is returned when the urpc call to Save does not include an appropriate file payload (e.g. there is no output file!).
Functions ¶
func ContainerUsage ¶
ContainerUsage retrieves per-container CPU usage.
func ExecAsync ¶
func ExecAsync(proc *Proc, args *ExecArgs) (*kernel.ThreadGroup, kernel.ThreadID, *host.TTYFileOperations, *hostvfs2.TTYFileDescription, error)
ExecAsync runs a new task, but doesn't wait for it to finish. It is defined as a function rather than a method to avoid exposing execAsync as an RPC.
func PrintPIDsJSON ¶
PrintPIDsJSON prints a JSON object containing only the PIDs in pl. This behavior is the same as runc's.
func ProcessListToJSON ¶
ProcessListToJSON will return the JSON representation of ps.
func ProcessListToTable ¶
ProcessListToTable prints a table with the following format: UID PID PPID C TTY STIME TIME CMD 0 1 0 0 pty/4 14:04 505262ns tail
Types ¶
type BlockProfileOpts ¶
type BlockProfileOpts struct { // FilePayload is the destination for the profiling output. urpc.FilePayload // Duration is the duration of the profile. Duration time.Duration `json:"duration"` // Rate is the block profile rate. Rate int `json:"rate"` }
BlockProfileOpts contains options specifically for block profiles.
type CPUProfileOpts ¶
type CPUProfileOpts struct { // FilePayload is the destination for the profiling output. urpc.FilePayload // Duration is the duration of the profile. Duration time.Duration `json:"duration"` }
CPUProfileOpts contains options specifically for CPU profiles.
type CatOpts ¶
type CatOpts struct { // Files are the filesystem paths for the files to cat. Files []string `json:"files"` // FilePayload contains the destination for output. urpc.FilePayload }
CatOpts contains options for the Cat RPC call.
type Events ¶
type Events struct {
// contains filtered or unexported fields
}
Events is the control server state for eventchannel-related commands.
func (*Events) AttachDebugEmitter ¶
func (e *Events) AttachDebugEmitter(o *EventsOpts, _ *struct{}) error
AttachDebugEmitter receives a connected unix domain socket FD from the client and establishes it as a new emitter for the sentry eventchannel. Any existing emitters are replaced on a subsequent attach.
type EventsOpts ¶
type EventsOpts struct {
urpc.FilePayload
}
EventsOpts are the arguments for eventchannel-related commands.
type ExecArgs ¶
type ExecArgs struct { // Filename is the filename to load. // // If this is provided as "", then the file will be guessed via Argv[0]. Filename string `json:"filename"` // Argv is a list of arguments. Argv []string `json:"argv"` // Envv is a list of environment variables. Envv []string `json:"envv"` // MountNamespace is the mount namespace to execute the new process in. // A reference on MountNamespace must be held for the lifetime of the // ExecArgs. If MountNamespace is nil, it will default to the init // process's MountNamespace. MountNamespace *fs.MountNamespace // MountNamespaceVFS2 is the mount namespace to execute the new process in. // A reference on MountNamespace must be held for the lifetime of the // ExecArgs. If MountNamespace is nil, it will default to the init // process's MountNamespace. MountNamespaceVFS2 *vfs.MountNamespace // WorkingDirectory defines the working directory for the new process. WorkingDirectory string `json:"wd"` // KUID is the UID to run with in the root user namespace. Defaults to // root if not set explicitly. KUID auth.KUID // KGID is the GID to run with in the root user namespace. Defaults to // the root group if not set explicitly. KGID auth.KGID // ExtraKGIDs is the list of additional groups to which the user belongs. ExtraKGIDs []auth.KGID // Capabilities is the list of capabilities to give to the process. Capabilities *auth.TaskCapabilities // StdioIsPty indicates that FDs 0, 1, and 2 are connected to a host pty FD. StdioIsPty bool // FilePayload determines the files to give to the new process. urpc.FilePayload // ContainerID is the container for the process being executed. ContainerID string // PIDNamespace is the pid namespace for the process being executed. PIDNamespace *kernel.PIDNamespace // Limits is the limit set for the process being executed. Limits *limits.LimitSet }
ExecArgs is the set of arguments to exec.
type GoroutineProfileOpts ¶
type GoroutineProfileOpts struct { // FilePayload is the destination for the profiling output. urpc.FilePayload }
GoroutineProfileOpts contains options specifically for goroutine profiles.
type HeapProfileOpts ¶
type HeapProfileOpts struct { // FilePayload is the destination for the profiling output. urpc.FilePayload // Delay is the sleep time, similar to Duration. This may // not affect the data collected however, as the heap will // continue only the memory associated with the last alloc. Delay time.Duration `json:"delay"` }
HeapProfileOpts contains options specifically for heap profiles.
type Lifecycle ¶
Lifecycle provides functions related to starting and stopping tasks.
type Logging ¶
type Logging struct{}
Logging provides functions related to logging.
func (*Logging) Change ¶
func (l *Logging) Change(args *LoggingArgs, code *int) error
Change will change the log level and strace arguments. Although this functions signature requires an error it never actually returns an error. It's required by the URPC interface. Additionally, it may look odd that this is the only method attached to an empty struct but this is also part of how URPC dispatches.
type LoggingArgs ¶
type LoggingArgs struct { // SetLevel is a flag used to indicate that we should update // the logging level. We should be able to change the strace // list without affecting the logging level and vice versa. SetLevel bool // Level is the log level that will be set if SetLevel is true. Level log.Level // SetLogPackets indicates that we should update the log packets flag. SetLogPackets bool // LogPackets is the actual value to set for LogPackets. // SetLogPackets must be enabled to indicate that we're changing // the value. LogPackets bool // SetStrace is a flag used to indicate that strace related // arguments were passed in. SetStrace bool // EnableStrace is a flag from the CLI that specifies whether to // enable strace at all. If this flag is false then a completely // pristine copy of the syscall table will be swapped in. This // approach is used to remain consistent with an empty strace // allowlist meaning trace all system calls. EnableStrace bool // Strace is the allowlist of syscalls to trace to log. If this // and StraceEventAllowlist are empty trace all system calls. StraceAllowlist []string // SetEventStrace is a flag used to indicate that event strace // related arguments were passed in. SetEventStrace bool // StraceEventAllowlist is the allowlist of syscalls to trace // to event log. StraceEventAllowlist []string }
LoggingArgs are the arguments to use for changing the logging level and strace list.
type MemoryUsage ¶
type MemoryUsage struct { Unknown uint64 `json:"Unknown"` System uint64 `json:"System"` Anonymous uint64 `json:"Anonymous"` PageCache uint64 `json:"PageCache"` Mapped uint64 `json:"Mapped"` Tmpfs uint64 `json:"Tmpfs"` Ramdiskfs uint64 `json:"Ramdiskfs"` Total uint64 `json:"Total"` }
MemoryUsage is a memory usage structure.
type MemoryUsageFile ¶
type MemoryUsageFile struct {
urpc.FilePayload
}
MemoryUsageFile contains the file handle to the usage file.
type MemoryUsageFileOpts ¶
type MemoryUsageFileOpts struct { // Version is used to ensure both sides agree on the format of the // shared memory buffer. Version uint64 `json:"Version"` }
MemoryUsageFileOpts contains usage file options.
type MemoryUsageOpts ¶
type MemoryUsageOpts struct { // Full indicates that a full accounting should be done. If Full is not // specified, then a partial accounting will be done, and Unknown will // contain a majority of memory. See Collect for more information. Full bool `json:"Full"` }
MemoryUsageOpts contains usage options.
type MemoryUsageRecord ¶
type MemoryUsageRecord struct {
// contains filtered or unexported fields
}
MemoryUsageRecord contains the mapping and platform memory file.
func NewMemoryUsageRecord ¶
func NewMemoryUsageRecord(usageFile, platformFile os.File) (*MemoryUsageRecord, error)
NewMemoryUsageRecord creates a new MemoryUsageRecord from usageFile and platformFile.
func (*MemoryUsageRecord) Fetch ¶
func (m *MemoryUsageRecord) Fetch() (mapped, unknown, total uint64, err error)
Fetch fetches the usage info from a MemoryUsageRecord.
type MutexProfileOpts ¶
type MutexProfileOpts struct { // FilePayload is the destination for the profiling output. urpc.FilePayload // Duration is the duration of the profile. Duration time.Duration `json:"duration"` // Fraction is the mutex profile fraction. Fraction int `json:"fraction"` }
MutexProfileOpts contains options specifically for mutex profiles.
type Proc ¶
Proc includes task-related functions.
At the moment, this is limited to exec support.
type Process ¶
type Process struct { UID auth.KUID `json:"uid"` PID kernel.ThreadID `json:"pid"` // Parent PID PPID kernel.ThreadID `json:"ppid"` Threads []kernel.ThreadID `json:"threads"` // Processor utilization C int32 `json:"c"` // TTY name of the process. Will be of the form "pts/N" if there is a // TTY, or "?" if there is not. TTY string `json:"tty"` // Start time STime string `json:"stime"` // CPU time Time string `json:"time"` // Executable shortname (e.g. "sh" for /bin/sh) Cmd string `json:"cmd"` }
Process contains information about a single process in a Sandbox.
type Profile ¶
type Profile struct {
// contains filtered or unexported fields
}
Profile includes profile-related RPC stubs. It provides a way to control the built-in runtime profiling facilities.
The profile object must be instantied via NewProfile.
func NewProfile ¶
NewProfile returns a new Profile object.
func (*Profile) Block ¶
func (p *Profile) Block(o *BlockProfileOpts, _ *struct{}) error
Block dumps a blocking profile.
func (*Profile) CPU ¶
func (p *Profile) CPU(o *CPUProfileOpts, _ *struct{}) error
CPU is an RPC stub which collects a CPU profile.
func (*Profile) Goroutine ¶
func (p *Profile) Goroutine(o *GoroutineProfileOpts, _ *struct{}) error
Goroutine dumps out the stack trace for all running goroutines.
func (*Profile) Heap ¶
func (p *Profile) Heap(o *HeapProfileOpts, _ *struct{}) error
Heap generates a heap profile.
func (*Profile) Mutex ¶
func (p *Profile) Mutex(o *MutexProfileOpts, _ *struct{}) error
Mutex dumps a mutex profile.
func (*Profile) Trace ¶
func (p *Profile) Trace(o *TraceProfileOpts, _ *struct{}) error
Trace is an RPC stub which starts collection of an execution trace.
type PsArgs ¶
type PsArgs struct { // JSON will force calls to Ps to return the result as a JSON payload. JSON bool }
PsArgs is the set of arguments to ps.
type SaveOpts ¶
type SaveOpts struct { // Key is used for state integrity check. Key []byte `json:"key"` // Metadata is the set of metadata to prepend to the state file. Metadata map[string]string `json:"metadata"` // FilePayload contains the destination for the state. urpc.FilePayload }
SaveOpts contains options for the Save RPC call.
type TraceProfileOpts ¶
type TraceProfileOpts struct { // FilePayload is the destination for the profiling output. urpc.FilePayload // Duration is the duration of the profile. Duration time.Duration `json:"duration"` }
TraceProfileOpts contains options specifically for traces.
type Usage ¶
Usage includes usage-related RPC stubs.
func (*Usage) Collect ¶
func (u *Usage) Collect(opts *MemoryUsageOpts, out *MemoryUsage) error
Collect returns memory used by the sandboxed application.
func (*Usage) GetFileIoStats ¶
GetFileIoStats writes the read times in nanoseconds to out.
func (*Usage) Reduce ¶
func (u *Usage) Reduce(opts *UsageReduceOpts, out *UsageReduceOutput) error
Reduce requests that the sentry attempt to reduce its memory usage.
func (*Usage) UsageFD ¶
func (u *Usage) UsageFD(opts *MemoryUsageFileOpts, out *MemoryUsageFile) error
UsageFD returns the file that tracks the memory usage of the application.
type UsageReduceOpts ¶
type UsageReduceOpts struct { // If Wait is true, Reduce blocks until all activity initiated by // Usage.Reduce() has completed. Wait bool `json:"wait"` }
UsageReduceOpts contains options to Usage.Reduce().
type UsageReduceOutput ¶
type UsageReduceOutput struct{}
UsageReduceOutput contains output from Usage.Reduce().