Documentation
¶
Overview ¶
Package agent is boxpool-agent, the process inside every sandbox that runs commands for the host, and a client for it. docs/agent-protocol.md describes the wire protocol.
Index ¶
- Constants
- func DesktopViewer() http.Handler
- func DialTCP(ctx context.Context, c net.Conn, port int) (net.Conn, error)
- func ExtractTar(r io.Reader, dest string, check func(*tar.Header) error) error
- func Listen(addr string) (net.Listener, error)
- func PrepareGuestNetwork() error
- func Serve(ctx context.Context, l net.Listener, version string, shutdown *Shutdown) error
- func WriteTar(w io.Writer, src string) error
- type Client
- func (c *Client) CloseIdleConnections()
- func (c *Client) Download(ctx context.Context, src string) (io.ReadCloser, error)
- func (c *Client) Exec(ctx context.Context, req ExecRequest, stdout, stderr io.Writer) (*Session, error)
- func (c *Client) Ports(ctx context.Context) ([]Port, error)
- func (c *Client) Shutdown(ctx context.Context, grace time.Duration) error
- func (c *Client) StartDesktop(ctx context.Context) (Desktop, error)
- func (c *Client) Upload(ctx context.Context, dest string, tar io.Reader) error
- func (c *Client) Version(ctx context.Context) (Version, error)
- type Desktop
- type ExecRequest
- type Port
- type Session
- type Shutdown
- type ShutdownRequest
- type Version
Constants ¶
const ( Stdin byte = 0 Stdout byte = 1 Stderr byte = 2 )
Stream ids: the first byte of every binary WebSocket message.
const DefaultShutdownGrace = 10 * time.Second
DefaultShutdownGrace is how long guest processes get to exit after SIGTERM when the request does not say.
const FeatureDesktop = "desktop"
FeatureDesktop advertises an image with an on-demand virtual desktop.
const FeatureShutdown = "shutdown"
FeatureShutdown in Version.Features means the agent serves POST /v1/shutdown. Agents older than it, and those in containers, lack it.
const FeatureTCP = "tcp"
FeatureTCP in Version.Features means the agent serves GET /v1/tcp.
const ProtocolVersion = 1
ProtocolVersion is the agent protocol version reported by GET /v1/version. It changes only when a change would break existing clients.
Variables ¶
This section is empty.
Functions ¶
func DesktopViewer ¶
DesktopViewer serves the embedded noVNC client below /v1/desktop/. Both the host binary and guest agent embed it; no CDN is required.
func DialTCP ¶
DialTCP asks the agent at the other end of c, a new connection to it, to connect to port on the guest's loopback, and returns c carrying that connection. It closes c if the agent refuses.
func ExtractTar ¶
ExtractTar extracts a tar into the existing directory dest, as PUT /v1/files does. If check is not nil, it sees each header first and may change it or refuse the entry. Only regular files, directories and symlinks are extracted, with their modes and modification times. No entry is written outside dest: absolute names and .. are refused, parents must be real directories, never symlinks, and an existing entry is unlinked, not written through. Symlinks themselves may point anywhere.
func PrepareGuestNetwork ¶
func PrepareGuestNetwork() error
PrepareGuestNetwork brings up loopback before a VM agent serves requests. A VM without a NIC has no kernel IP autoconfiguration to do this for it. Docker agents must not call this: the Engine configures their network, and they intentionally lack CAP_NET_ADMIN. No external interface is changed.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one agent.
func NewClient ¶
NewClient returns a client that reaches the agent through dial, for example over a unix socket or a vsock connection.
func (*Client) CloseIdleConnections ¶
func (c *Client) CloseIdleConnections()
CloseIdleConnections closes connections kept open for reuse, which otherwise stay open to the agent for as long as the process runs.
func (*Client) Download ¶
Download returns a tar rooted at the base name of src. The caller must read to EOF to detect interrupted transfers, then close the body.
func (*Client) Exec ¶
func (c *Client) Exec(ctx context.Context, req ExecRequest, stdout, stderr io.Writer) (*Session, error)
Exec starts a command and copies its output to stdout and stderr until it exits. With req.TTY all output goes to stdout.
func (*Client) Shutdown ¶
Shutdown asks the agent to stop every guest process, giving them grace after SIGTERM before SIGKILL, remount / read-only and reboot the guest. It returns once / is read-only; the reboot follows, and can cut the reply short.
func (*Client) StartDesktop ¶
StartDesktop starts the image's display without tying it to this request.
type Desktop ¶
type Desktop struct {
Display string `json:"display"`
VNC string `json:"vnc"`
HumanControl bool `json:"human_control"`
}
Desktop describes the display and its private RFB endpoint. HumanControl is cooperative: agents should pause their browser automation while it is true.
type ExecRequest ¶
type ExecRequest struct {
Argv []string `json:"argv"`
Env []string `json:"env,omitempty"`
Cwd string `json:"cwd,omitempty"`
TTY bool `json:"tty,omitempty"`
Rows uint16 `json:"rows,omitempty"`
Cols uint16 `json:"cols,omitempty"`
}
ExecRequest is the first message of an exec session.
type Port ¶
type Port struct {
Proto string `json:"proto"`
Address string `json:"address"`
Port int `json:"port"`
}
Port is a listening TCP socket reported by GET /v1/ports.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a running command. Cancelling the context passed to Exec ends the session, and the agent kills the command.
func Start ¶
func Start(ctx context.Context, conn *websocket.Conn, req ExecRequest, stdout, stderr io.Writer) (*Session, error)
Start runs an exec session on conn, an open exec WebSocket to an agent or to something that relays one, such as the daemon. The session owns conn.
func (*Session) CloseStdin ¶
CloseStdin closes the command's stdin. It does nothing in TTY mode, where the client sends Ctrl-D instead.
type Shutdown ¶
type Shutdown struct {
// Pids lists live processes. It may leave out zombies and kernel
// threads, which do not exit on a signal.
Pids func() ([]int, error)
Kill func(pid int, sig syscall.Signal) error
// Remount syncs and remounts the root filesystem read-only.
Remount func() error
// Reboot ends the VM. It returns only if it fails.
Reboot func() error
}
Shutdown is how the agent serves POST /v1/shutdown. Only the agent in a VM serves it: GuestShutdown returns the real one.
func GuestShutdown ¶
func GuestShutdown() *Shutdown
GuestShutdown is the Shutdown of the agent in a VM. Reboot ends the VM: Firecracker exits on a guest reboot, with reboot=k on x86_64 and through PSCI on arm64.
type ShutdownRequest ¶
type ShutdownRequest struct {
GraceMS int64 `json:"grace_ms,omitempty"`
}
ShutdownRequest is the body of POST /v1/shutdown.