Documentation
¶
Index ¶
- type AgentConfig
- type CommandEnd
- type CommandStart
- type Decoder
- type Direction
- type Encoder
- type ExecMsg
- type Frame
- type FrameType
- type LogEntry
- type Mux
- func (m *Mux) DecodeOne() (*Frame, error)
- func (m *Mux) OnLog(fn func(*LogEntry))
- func (m *Mux) OnSignal(fn func(int))
- func (m *Mux) ReadLoop(ctx context.Context) (exitCode int, err error)
- func (m *Mux) RegisterStream(id uint32, h StreamHandler)
- func (m *Mux) Send(f *Frame) error
- func (m *Mux) SendData(stream uint32, data []byte) error
- func (m *Mux) SendEOF(stream uint32) error
- func (m *Mux) SetRecorder(rec *Recorder, seq uint32)
- type MuxLogHandler
- type PathInfo
- type PathInfoEntry
- type PathQuery
- type Record
- type RecordType
- type RecordedFrame
- type Recorder
- func (r *Recorder) Close() error
- func (r *Recorder) WriteCommandEnd(seq uint32, exitCode int) error
- func (r *Recorder) WriteCommandStart(exec *ExecMsg) (uint32, error)
- func (r *Recorder) WriteFrame(seq uint32, dir Direction, f *Frame) error
- func (r *Recorder) WriteSessionFooter() error
- func (r *Recorder) WriteSessionHeader(h *SessionHeader) error
- type SessionFooter
- type SessionHeader
- type StreamHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentConfig ¶
type AgentConfig struct {
EnvKeep []string `cbor:"env_keep"`
EnvRemove []string `cbor:"env_remove"`
}
AgentConfig carries the agent's runtime configuration, sent via FrameConfig before any FrameExec. Patterns are globs or /regex/ delimited strings.
type CommandEnd ¶
type CommandEnd struct {
SeqNum uint32 `cbor:"seq"`
EndTime int64 `cbor:"end_time"`
ExitCode int `cbor:"exit_code"`
}
CommandEnd marks the end of a command execution.
type CommandStart ¶
type CommandStart struct {
SeqNum uint32 `cbor:"seq"`
StartTime int64 `cbor:"start_time"`
Exec ExecMsg `cbor:"exec"`
}
CommandStart marks the beginning of a command execution.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder reads CBOR-encoded frames.
func NewDecoder ¶
NewDecoder returns a Decoder that reads from r.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder writes CBOR-encoded frames. It is safe for concurrent use.
func NewEncoder ¶
NewEncoder returns an Encoder that writes to w.
type ExecMsg ¶
type ExecMsg struct {
Path string `cbor:"path"`
Argv []string `cbor:"argv"`
Env []string `cbor:"env"`
Cwd string `cbor:"cwd"`
ExtraFDs []uint32 `cbor:"fds,omitempty"`
}
ExecMsg carries the command details in a FrameExec.
type Frame ¶
type Frame struct {
Type FrameType `cbor:"t"`
Stream uint32 `cbor:"s,omitempty"` // 0=stdin, 1=stdout, 2=stderr, 3+=extra fds
Data []byte `cbor:"d,omitempty"`
Signal int `cbor:"sig,omitempty"`
Code int `cbor:"c,omitempty"`
Error string `cbor:"e,omitempty"`
Exec *ExecMsg `cbor:"x,omitempty"`
Log *LogEntry `cbor:"l,omitempty"`
Config *AgentConfig `cbor:"cfg,omitempty"`
Query *PathQuery `cbor:"q,omitempty"`
Info *PathInfo `cbor:"i,omitempty"`
}
Frame is a single message on the CBOR mux. Fields are omitted when zero-valued so only the relevant subset appears on the wire.
type FrameType ¶
type FrameType uint8
FrameType identifies the kind of message on the CBOR mux.
const ( FrameExec FrameType = 1 // local → agent: start command FrameData FrameType = 2 // bidirectional: data for a stream FrameEOF FrameType = 3 // sender closes a stream FrameSignal FrameType = 4 // local → agent: deliver signal to child pgid FrameExit FrameType = 5 // agent → local: child exited (terminal frame) FrameError FrameType = 6 // agent → local: internal error FrameLog FrameType = 7 // agent → local: log message FrameConfig FrameType = 8 // local → agent: serialized config FramePathQuery FrameType = 9 // local → agent: enumerate PATH executables FramePathInfo FrameType = 10 // agent → local: PATH enumeration result )
type LogEntry ¶
type LogEntry struct {
Level int `cbor:"lvl"` // slog.Level value
Msg string `cbor:"msg"`
Attrs []string `cbor:"a,omitempty"` // key=value pairs
}
LogEntry carries a structured log record from the agent.
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
Mux multiplexes CBOR frames over a reader/writer pair. Incoming frames are dispatched to registered handlers; Send serialises outgoing frames.
func NewMux ¶
NewMux creates a mux over the given reader (incoming frames) and writer (outgoing frames). Typically r and w are the two ends of an SSH session's stdio.
func (*Mux) DecodeOne ¶
DecodeOne reads a single frame from the underlying reader without dispatching it. Useful for reading the initial FrameExec before the read loop starts.
func (*Mux) ReadLoop ¶
ReadLoop reads and dispatches frames until the context is cancelled, a FrameExit is received, or the underlying reader returns an error. It returns the exit code from a FrameExit, or -1 if the loop ended without one.
func (*Mux) RegisterStream ¶
func (m *Mux) RegisterStream(id uint32, h StreamHandler)
RegisterStream adds a handler for the given stream ID.
func (*Mux) SetRecorder ¶
SetRecorder enables recording of all frames passing through this mux. seq is the command sequence number assigned by the Recorder.
type MuxLogHandler ¶
type MuxLogHandler struct {
// contains filtered or unexported fields
}
MuxLogHandler is a slog.Handler that sends log records over the CBOR mux as FrameLog frames. This lets agent-side logs appear on the machineproxy process where the operator can see them.
func NewMuxLogHandler ¶
func NewMuxLogHandler(mux *Mux, level slog.Level) *MuxLogHandler
NewMuxLogHandler creates a handler that forwards log records through mux.
type PathInfo ¶ added in v1.1.0
type PathInfo struct {
Entries []PathInfoEntry `cbor:"entries"`
}
PathInfo carries the agent's enumeration result. Entries are deduped by Name (first-found wins per PATH precedence) and listed in the same order as the input Paths.
type PathInfoEntry ¶ added in v1.1.0
type PathInfoEntry struct {
Name string `cbor:"name"`
RemotePath string `cbor:"path"`
Mode uint32 `cbor:"mode"`
Size int64 `cbor:"size"`
MTimeNanos int64 `cbor:"mtime,omitempty"`
}
PathInfoEntry describes one stub entry returned by FramePathInfo.
type PathQuery ¶ added in v1.1.0
type PathQuery struct {
Paths []string `cbor:"paths,omitempty"`
}
PathQuery requests enumeration of executable files reachable through the listed PATH-style directories. An empty Paths slice tells the agent to use its own $PATH at the time of the request.
type Record ¶
type Record struct {
Type RecordType `cbor:"type"`
Header *SessionHeader `cbor:"header,omitempty"`
CmdStart *CommandStart `cbor:"cmd_start,omitempty"`
Frame *RecordedFrame `cbor:"frame,omitempty"`
CmdEnd *CommandEnd `cbor:"cmd_end,omitempty"`
}
Record is the top-level envelope written to a recording file. Exactly one of the optional fields is set per record.
type RecordType ¶
type RecordType uint8
RecordType tags each record in a recording file.
const ( RecordSessionHeader RecordType = 1 RecordCommandStart RecordType = 2 RecordFrame RecordType = 3 RecordCommandEnd RecordType = 4 )
type RecordedFrame ¶
type RecordedFrame struct {
SeqNum uint32 `cbor:"seq"`
Timestamp int64 `cbor:"ts"`
Direction Direction `cbor:"dir"`
Frame Frame `cbor:"frame"`
}
RecordedFrame wraps an agentproto Frame with recording metadata.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder writes session recording data. Safe for concurrent use.
func NewRecorder ¶
NewRecorder creates a Recorder that writes to path. The file is created (or truncated) immediately.
func NewRecorderWriter ¶
NewRecorderWriter creates a Recorder that writes to w. The caller is responsible for closing w.
func (*Recorder) WriteCommandEnd ¶
WriteCommandEnd marks the completion of a command.
func (*Recorder) WriteCommandStart ¶
WriteCommandStart marks the beginning of a new command and returns its sequence number.
func (*Recorder) WriteFrame ¶
WriteFrame records a single agentproto frame with direction metadata.
func (*Recorder) WriteSessionFooter ¶
WriteSessionFooter writes the session-level summary. Call once before closing the recorder.
func (*Recorder) WriteSessionHeader ¶
func (r *Recorder) WriteSessionHeader(h *SessionHeader) error
WriteSessionHeader writes the session-level metadata. Call once at the start of a recording.
type SessionFooter ¶
type SessionFooter struct {
}
SessionFooter is written once at the end of a recording file.
type SessionHeader ¶
type SessionHeader struct {
Version string `cbor:"version"`
StartTime int64 `cbor:"start_time"` // unix nanos
LocalUser string `cbor:"local_user"`
LocalPID int `cbor:"local_pid"`
SSHAddr string `cbor:"ssh_addr"`
SSHUser string `cbor:"ssh_user"`
AgentPath string `cbor:"agent_path"`
}
SessionHeader is written once at the start of a recording file.
type StreamHandler ¶
StreamHandler receives data and EOF events for a single stream ID.
func WriterHandler ¶
func WriterHandler(w io.WriteCloser) StreamHandler
WriterHandler returns a StreamHandler that writes to w and closes it on EOF.