Documentation
¶
Index ¶
- Constants
- func ExecuteSSHCommand(ctx context.Context, client *ssh.Client, command string) (string, error)
- type CommandResult
- type DockerRunner
- func (r *DockerRunner) Cleanup(ctx context.Context) error
- func (r *DockerRunner) CopyFromRemote(ctx context.Context, remotePath, localPath string) error
- func (r *DockerRunner) Execute(ctx context.Context, command string) (*CommandResult, error)
- func (r *DockerRunner) GetContainerID() string
- func (r *DockerRunner) IsRemote() bool
- func (r *DockerRunner) SetPIDCallbacks(onStart, onEnd PIDCallback)
- func (r *DockerRunner) Setup(ctx context.Context) error
- func (r *DockerRunner) Type() core.RunnerType
- type HostRunner
- func (r *HostRunner) Cleanup(ctx context.Context) error
- func (r *HostRunner) CopyFromRemote(ctx context.Context, remotePath, localPath string) error
- func (r *HostRunner) Execute(ctx context.Context, command string) (*CommandResult, error)
- func (r *HostRunner) IsRemote() bool
- func (r *HostRunner) SetPIDCallbacks(onStart, onEnd PIDCallback)
- func (r *HostRunner) Setup(ctx context.Context) error
- func (r *HostRunner) Type() core.RunnerType
- type LimitedBuffer
- type PIDCallback
- type Runner
- type SSHPool
- type SSHPoolKey
- type SSHRunner
- func (r *SSHRunner) Cleanup(ctx context.Context) error
- func (r *SSHRunner) CopyFromRemote(ctx context.Context, remotePath, localPath string) error
- func (r *SSHRunner) CopyFromRemoteSFTP(remotePath, localPath string) error
- func (r *SSHRunner) Execute(ctx context.Context, command string) (*CommandResult, error)
- func (r *SSHRunner) GetRemoteDir() string
- func (r *SSHRunner) IsRemote() bool
- func (r *SSHRunner) SetPIDCallbacks(onStart, onEnd PIDCallback)
- func (r *SSHRunner) Setup(ctx context.Context) error
- func (r *SSHRunner) Type() core.RunnerType
Constants ¶
const MaxOutputSize = 10 * 1024 * 1024
MaxOutputSize limits the combined output size to prevent memory issues with very large command outputs (10MB default)
const MaxStderrSize = 1 * 1024 * 1024
MaxStderrSize limits stderr capture (1MB) since stderr is typically small
Variables ¶
This section is empty.
Functions ¶
func ExecuteSSHCommand ¶ added in v5.0.3
ExecuteSSHCommand runs `command` on an existing *ssh.Client and returns combined output. When ctx is cancelled mid-flight, a watcher goroutine opens a second SSH session and kills the remote process group (TERM then KILL). This is the shared cancel-aware code path used by SSHRunner and by ad-hoc helpers (e.g. the ssh_exec workflow function).
Why this matters: closing the local SSH session does NOT kill remote processes — sshd just detaches them. The pidfile + process-group kill is the only reliable way to terminate scanning still running on the remote.
Types ¶
type CommandResult ¶
type CommandResult struct {
Output string // Combined stdout and stderr
ExitCode int // Exit code of the command
Error error // Error if execution failed
}
CommandResult holds the output of a command execution
type DockerRunner ¶
type DockerRunner struct {
// contains filtered or unexported fields
}
DockerRunner executes commands inside a Docker container
func NewDockerRunner ¶
func NewDockerRunner(config *core.RunnerConfig, binaryPath string) (*DockerRunner, error)
NewDockerRunner creates a new Docker runner
func (*DockerRunner) Cleanup ¶
func (r *DockerRunner) Cleanup(ctx context.Context) error
Cleanup stops and removes the container
func (*DockerRunner) CopyFromRemote ¶
func (r *DockerRunner) CopyFromRemote(ctx context.Context, remotePath, localPath string) error
CopyFromRemote copies a file from the container to the local host using docker cp
func (*DockerRunner) Execute ¶
func (r *DockerRunner) Execute(ctx context.Context, command string) (*CommandResult, error)
Execute runs a command in the Docker container
func (*DockerRunner) GetContainerID ¶
func (r *DockerRunner) GetContainerID() string
GetContainerID returns the current container ID (for persistent mode)
func (*DockerRunner) IsRemote ¶
func (r *DockerRunner) IsRemote() bool
IsRemote returns true since Docker container is considered remote
func (*DockerRunner) SetPIDCallbacks ¶ added in v5.0.1
func (r *DockerRunner) SetPIDCallbacks(onStart, onEnd PIDCallback)
SetPIDCallbacks sets callbacks for process lifecycle events
func (*DockerRunner) Setup ¶
func (r *DockerRunner) Setup(ctx context.Context) error
Setup prepares the Docker container
func (*DockerRunner) Type ¶
func (r *DockerRunner) Type() core.RunnerType
Type returns the runner type
type HostRunner ¶
type HostRunner struct {
// contains filtered or unexported fields
}
HostRunner executes commands on the local machine
func NewHostRunner ¶
func NewHostRunner(binariesPath string) *HostRunner
NewHostRunner creates a new host runner
func (*HostRunner) Cleanup ¶
func (r *HostRunner) Cleanup(ctx context.Context) error
Cleanup is a no-op for host runner
func (*HostRunner) CopyFromRemote ¶
func (r *HostRunner) CopyFromRemote(ctx context.Context, remotePath, localPath string) error
CopyFromRemote is not supported for host runner (local execution doesn't need file copy)
func (*HostRunner) Execute ¶
func (r *HostRunner) Execute(ctx context.Context, command string) (*CommandResult, error)
Execute runs a command on the local machine
func (*HostRunner) IsRemote ¶
func (r *HostRunner) IsRemote() bool
IsRemote returns false since host runner runs locally
func (*HostRunner) SetPIDCallbacks ¶ added in v5.0.1
func (r *HostRunner) SetPIDCallbacks(onStart, onEnd PIDCallback)
SetPIDCallbacks sets callbacks for process lifecycle events
type LimitedBuffer ¶ added in v5.0.1
type LimitedBuffer struct {
// contains filtered or unexported fields
}
LimitedBuffer wraps bytes.Buffer and silently discards writes after maxSize. This prevents unbounded memory growth when a tool produces GBs of output.
func NewLimitedBuffer ¶ added in v5.0.1
func NewLimitedBuffer(maxSize int) *LimitedBuffer
NewLimitedBuffer creates a LimitedBuffer with the given max size.
func (*LimitedBuffer) Bytes ¶ added in v5.0.1
func (lb *LimitedBuffer) Bytes() []byte
Bytes returns the buffered bytes.
func (*LimitedBuffer) Len ¶ added in v5.0.1
func (lb *LimitedBuffer) Len() int
Len returns the number of buffered bytes.
func (*LimitedBuffer) Overflow ¶ added in v5.0.1
func (lb *LimitedBuffer) Overflow() bool
Overflow returns true if any writes were discarded.
type PIDCallback ¶ added in v5.0.1
type PIDCallback func(pid int)
PIDCallback is called when a process starts or ends
type Runner ¶
type Runner interface {
// Execute runs a command and returns the result
Execute(ctx context.Context, command string) (*CommandResult, error)
// Setup prepares the runner (e.g., copy binary, start container, establish SSH)
Setup(ctx context.Context) error
// Cleanup tears down resources (e.g., stop container, close SSH connection)
Cleanup(ctx context.Context) error
// Type returns the runner type
Type() core.RunnerType
// IsRemote returns true if commands run on a remote machine
IsRemote() bool
// CopyFromRemote copies a file from the remote environment to the local host
// For Docker: uses docker cp, for SSH: uses rsync
CopyFromRemote(ctx context.Context, remotePath, localPath string) error
// SetPIDCallbacks sets callbacks for process lifecycle events.
// onStart is called when a process starts (with the PID)
// onEnd is called when the process ends (with the PID)
// This enables tracking of running processes for cancellation support.
SetPIDCallbacks(onStart, onEnd PIDCallback)
}
Runner interface for executing commands in different environments
func NewRunnerFromType ¶
func NewRunnerFromType(runnerType core.RunnerType, config *core.RunnerConfig, binaryPath string) (Runner, error)
NewRunnerFromType creates a runner from type and config directly
type SSHPool ¶
type SSHPool struct {
// contains filtered or unexported fields
}
SSHPool manages a pool of SSH connections for reuse
func (*SSHPool) Get ¶
func (p *SSHPool) Get(ctx context.Context, config *core.RunnerConfig) (*ssh.Client, SSHPoolKey, error)
Get retrieves or creates an SSH connection for the given config
func (*SSHPool) Release ¶
func (p *SSHPool) Release(key SSHPoolKey)
Release decrements the reference count for a connection
type SSHPoolKey ¶
SSHPoolKey uniquely identifies an SSH connection target
func (SSHPoolKey) String ¶
func (k SSHPoolKey) String() string
String returns a string representation of the pool key
type SSHRunner ¶
type SSHRunner struct {
// contains filtered or unexported fields
}
SSHRunner executes commands on a remote machine via SSH
func NewSSHRunner ¶
func NewSSHRunner(config *core.RunnerConfig, binaryPath string) (*SSHRunner, error)
NewSSHRunner creates a new SSH runner
func (*SSHRunner) CopyFromRemote ¶
CopyFromRemote copies a file from the SSH host to local using rsync
func (*SSHRunner) CopyFromRemoteSFTP ¶ added in v5.0.2
CopyFromRemoteSFTP copies a file from the SSH host to local using SFTP (no rsync dependency).
func (*SSHRunner) GetRemoteDir ¶
GetRemoteDir returns the remote directory where binary is stored
func (*SSHRunner) SetPIDCallbacks ¶ added in v5.0.1
func (r *SSHRunner) SetPIDCallbacks(onStart, onEnd PIDCallback)
SetPIDCallbacks records process lifecycle callbacks. Remote PIDs are NOT forwarded to the local run control plane (the control plane's PID kill is a local syscall, so a remote PID could collide with an unrelated local process). Remote cancellation is instead driven by ctx.Done() inside runCommand, which kills the remote process group out-of-band via SSH.