Documentation
¶
Overview ¶
Package osquery integrates the osquery binary for system queries through an injected exec.Runner.
Build a Querier with a Runner and call its methods; every query is escalated through the Runner. Every query path — the convenience table path AND raw SQL — refuses a curated deny-list of credential-bearing tables before running anything: a query that references a deny-listed table (in any clause) is rejected, so there is no path to read shadow/sudoers/… via osquery. Inputs are size-bounded in-package: table names and raw SQL beyond the caps are refused before execution.
r, _ := exec.NewRunner(exec.Sudo)
q, err := osquery.New(r) // ErrNotInstalled if osqueryi is absent
if err != nil { ... }
rows, err := q.QueryTable(ctx, "os_version")
Results are SDK-native: a Row is one result row as column→value, exactly osquery's own --json output shape. Refusals are errors.Is-able sentinels (ErrTableNotPermitted, ErrInvalidTableName, ErrQueryTooLong); consumers that need a wire envelope build their own at their boundary.
New is a single-implementation capability (design §3.8): it exposes the Querier interface for shape-uniformity with the backend-pattern packages even though osquery is the only implementation. There is no Backend argument — only the required Runner.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotInstalled is returned when osquery is not installed on the system. ErrNotInstalled = errors.New("osquery is not installed") // ErrQueryFailed is returned when an osquery query fails. ErrQueryFailed = errors.New("osquery query failed") // ErrTableNotPermitted is the credential-table deny-list refusal: the // query referenced a table on the curated sensitiveTables list. The // wrapped error names the offending table. ErrTableNotPermitted = errors.New("table is not permitted") // ErrInvalidTableName is the shape refusal: the table name is not a safe // osquery identifier (or exceeds the name cap). Distinct from // ErrTableNotPermitted — shape vs policy. ErrInvalidTableName = errors.New("invalid table name") // ErrQueryTooLong is the size refusal: raw SQL exceeded maxRawSQLLen. ErrQueryTooLong = errors.New("osquery input exceeds size limit") )
Functions ¶
This section is empty.
Types ¶
type Querier ¶
type Querier interface {
// IsInstalled reports, live, whether an osqueryi binary is currently
// reachable. New already fails closed with ErrNotInstalled when the binary
// is absent at construction; IsInstalled re-probes so a caller can detect
// the binary being removed during the agent's lifetime. The ctx is accepted
// for shape-uniformity; the probe itself is a filesystem lookup.
IsInstalled(ctx context.Context) bool
// ListTables returns the names of the available osquery tables.
ListTables(ctx context.Context) ([]string, error)
// QueryTable runs SELECT * FROM <table> after shape validation
// (ErrInvalidTableName) and the credential-table deny-list
// (ErrTableNotPermitted); both refuse before anything executes.
QueryTable(ctx context.Context, tableName string) ([]Row, error)
// QuerySQL runs raw SQL and parses the JSON result rows. It is gated by
// the same credential-table deny-list as the table path — raw SQL
// referencing a deny-listed table is refused (ErrTableNotPermitted)
// before anything executes — and size-bounded (ErrQueryTooLong).
QuerySQL(ctx context.Context, sql string) ([]Row, error)
}
Querier is the osquery surface: a small, ctx-first interface over the osquery binary. It is single-implementation by nature (§3.8) — there is no second way to run osquery — but it is an interface so a consumer learns the same construct-a-handle shape as every other capability.
func New ¶
New creates an osquery Querier driven by runner. Returns ErrNotInstalled when the osqueryi binary is not found (eager fail-closed probe, so a caller learns at construction that osquery is unavailable), and an error when runner is nil.
Example ¶
package main
import (
"context"
"errors"
"fmt"
"log"
"github.com/manchtools/cadestro/sdk/sys/exec"
"github.com/manchtools/cadestro/sdk/sys/osquery"
)
func main() {
r, err := exec.NewRunner(exec.Sudo)
if err != nil {
log.Fatal(err)
}
q, err := osquery.New(r)
if errors.Is(err, osquery.ErrNotInstalled) {
return
}
if err != nil {
log.Fatal(err)
}
rows, err := q.QueryTable(context.Background(), "os_version")
if err != nil {
log.Fatal(err)
}
for _, row := range rows {
fmt.Println(row["name"])
}
}
Output: