console

package
v0.5.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandLocal    = "local"
	CommandRemote   = "remote"
	CommandCarve    = "carve"
	CommandMode     = "mode"
	CommandExitMode = "exit-mode"

	StatusQueued    = "queued"
	StatusDelivered = "delivered"
	StatusCompleted = "completed"
	StatusError     = "error"
	StatusExpired   = "expired"
)
View Source
const PrimingMetadataSQL = "select version, build_platform, build_distro, start_time, config_valid, optimizations from osquery_info"

PrimingMetadataSQL is the read-only osquery statement dispatched when a console session is opened. Its purpose is twofold:

  1. Be present in the node's pending distributed queue so that the next QueryRead can return an accelerated interval when acceleration is enabled — the node switches to fast polling before the user types their first command.
  2. Surface live metadata (osquery version, build platform, start time, uptime) into the session UI so the operator sees fresh values rather than the last-seen DB snapshot.

It is a single statement (no semicolons) so validateSelect stays happy and osquery treats it atomically.

Variables

This section is empty.

Functions

func DefaultCWD

func DefaultCWD(platform string) string

Types

type Command

type Command struct {
	ID                   uint           `gorm:"primarykey" json:"id"`
	CreatedAt            time.Time      `json:"created_at"`
	UpdatedAt            time.Time      `json:"updated_at"`
	DeletedAt            gorm.DeletedAt `gorm:"index" json:"-"`
	SessionID            uint           `gorm:"not null;index" json:"session_id"`
	Input                string         `gorm:"not null" json:"input"`
	TranslatedSQL        string         `json:"translated_sql"`
	DistributedQueryName string         `gorm:"index" json:"distributed_query_name,omitempty"`
	Status               string         `gorm:"not null;index" json:"status"`
	Error                string         `json:"error,omitempty"`
	Priming              bool           `gorm:"not null;default:false;index" json:"priming"`
	DeliveredAt          *time.Time     `json:"delivered_at,omitempty"`
	CompletedAt          *time.Time     `json:"completed_at,omitempty"`
	ExpiredAt            *time.Time     `json:"expired_at,omitempty"`
}

func (Command) TableName

func (Command) TableName() string

type HistoryEntry

type HistoryEntry struct {
	Command Command          `json:"command"`
	Results []map[string]any `json:"results"`
}

type Manager

type Manager struct {
	DB        *gorm.DB
	Queries   *queries.Queries
	LogReader logging.LogReader
}

func NewManager

func NewManager(db *gorm.DB, queryManager *queries.Queries) *Manager

func (*Manager) CloseSession

func (m *Manager) CloseSession(sessionID uint) error

func (*Manager) CommandResults

func (m *Manager) CommandResults(commandID uint) ([]map[string]any, error)

func (*Manager) CreateSession

func (m *Manager) CreateSession(env environments.TLSEnvironment, node nodes.OsqueryNode, creator string) (Session, error)

func (*Manager) GetCommand

func (m *Manager) GetCommand(sessionID, commandID uint) (Command, error)

func (*Manager) GetSession

func (m *Manager) GetSession(sessionID uint) (Session, error)

func (*Manager) History

func (m *Manager) History(envID, nodeID uint, creator string, limit int) ([]HistoryEntry, error)

func (*Manager) PrimingCommand added in v0.5.6

func (m *Manager) PrimingCommand(sessionID uint) (Command, error)

PrimingCommand returns the most recent priming command for a session, or gorm.ErrRecordNotFound if none exists.

func (*Manager) RefreshCommandStatus

func (m *Manager) RefreshCommandStatus(commandID uint) (Command, error)

func (*Manager) SetLogReader added in v0.5.6

func (m *Manager) SetLogReader(r logging.LogReader)

SetLogReader wires a LogReader (DB- or S3-backed). When unset, the manager falls back to NewDBLogReader(m.DB) so existing callers keep the legacy DB-backed behavior.

func (*Manager) SubmitCommand

func (m *Manager) SubmitCommand(sessionID uint, input string, osqueryModeOpt ...bool) (Command, ParsedCommand, error)

func (*Manager) SubmitCommandWithTimeout

func (m *Manager) SubmitCommandWithTimeout(sessionID uint, input string, timeout time.Duration, osqueryModeOpt ...bool) (Command, ParsedCommand, error)

func (*Manager) SubmitPrimingCommand added in v0.5.6

func (m *Manager) SubmitPrimingCommand(sessionID uint, timeout time.Duration) (Command, error)

SubmitPrimingCommand dispatches the console priming metadata query for the session. The priming query is a hidden ConsoleQueryType distributed query whose presence in the node's pending queue lets the TLS QueryRead handler return an accelerated interval when acceleration is enabled — so the node switches to fast polling before the operator types their first command.

Unlike SubmitCommand, priming commands are not mutually exclusive with each other or with user commands: a fresh session may legitimately have a priming query in flight when the user submits their first real command, and SubmitCommandWithTimeout's pending-count ignores priming rows for exactly that reason.

The returned Command is marked Priming=true so the API layer can surface it separately from operator history.

func (*Manager) TouchSession

func (m *Manager) TouchSession(sessionID uint) (Session, error)

type ParsedCommand

type ParsedCommand struct {
	Kind    string `json:"kind"`
	Command string `json:"command"`
	Mode    string `json:"mode,omitempty"`
	Path    string `json:"path,omitempty"`
	SQL     string `json:"sql,omitempty"`
	Output  string `json:"output,omitempty"`
	Message string `json:"message,omitempty"`
}

func Parse

func Parse(input, cwd, platform string) (ParsedCommand, error)

func ParseInput

func ParseInput(input, cwd, platform string, osqueryMode bool) (ParsedCommand, error)

type Session

type Session struct {
	ID            uint           `gorm:"primarykey" json:"id"`
	CreatedAt     time.Time      `json:"created_at"`
	UpdatedAt     time.Time      `json:"updated_at"`
	DeletedAt     gorm.DeletedAt `gorm:"index" json:"-"`
	EnvironmentID uint           `gorm:"not null;index" json:"environment_id"`
	// Environment is the env UUID used as the S3 key prefix when the
	// log reader is S3-backed. Populated at session creation from the
	// env record; the DB reader ignores it.
	Environment string     `gorm:"index" json:"environment"`
	NodeID      uint       `gorm:"not null;index" json:"node_id"`
	NodeUUID    string     `gorm:"not null;index" json:"node_uuid"`
	Creator     string     `gorm:"not null;index" json:"creator"`
	CWD         string     `gorm:"not null" json:"cwd"`
	Platform    string     `json:"platform"`
	Active      bool       `gorm:"not null;default:true" json:"active"`
	ClosedAt    *time.Time `json:"closed_at,omitempty"`
}

func (Session) TableName

func (Session) TableName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL