Documentation
¶
Overview ¶
Package mitigation is the "What to do" part of a finding: confirmed packs loaded from a signed update, the "Applied" log, the compromise indicators and the AI explanation. Findings themselves belong to modules/findings; this module only reads them through findings.Service.
Index ¶
- Constants
- Variables
- func CheckPack(data []byte) (cve string, err error)
- func FindingFolded(ctx context.Context, tx *sql.Tx, f lifecycle.FindingFold) error
- func Statement(version string, docs []Doc) ([]byte, error)
- type AI
- type AIOutput
- type AIRequest
- type ActionHandlers
- func (h *ActionHandlers) FindingsPostFindingsIDAi(ctx context.Context, req *oas.FindingsPostFindingsIDAiReq, ...) (*oas.FindingsPostFindingsIDAiOK, error)
- func (h *ActionHandlers) FindingsPostFindingsIDApplied(ctx context.Context, req *oas.FindingsPostFindingsIDAppliedReq, ...) (*oas.FindingsPostFindingsIDAppliedOK, error)
- type Details
- type Doc
- type InstallResult
- type Loader
- type Provider
- type Rejection
- type Skill
- type Update
- type Vendors
- type Verifier
Constants ¶
const ( PackVersionFile = "VERSION" PackSignatureFile = "packs.minisig" PackStatementFile = "packs.list" // a copy of the statement, for people who check it with minisign; never read by the box )
Files of a pack directory besides the packs.
const StatementHeader = "vedette mitigation packs v1"
StatementHeader is the first line of the signed statement. It separates the statement from every other document the release key signs (index.json and release-manifest.json are JSON, so they cannot be read as one, nor one as them).
Variables ¶
ErrAIUnavailable is what AI.Run returns when no profile is assigned to the job or the ai module is off; the handler answers 409 ai_unavailable.
var ErrBadPackSet = errors.New("pack set is not well formed")
ErrBadPackSet means the update cannot be put into a statement: a document name is not a plain file name, appears twice, or the version is not one line. The Verifier refuses such an update before any signature check.
var ErrNoPackDir = errors.New("no pack directory")
ErrNoPackDir means the directory does not exist or holds no pack, no VERSION and no signature: this build ships no packs.
var ErrNoValidPack = errors.New("update has no valid pack")
ErrNoValidPack means the update holds no valid pack (no documents, or every one was rejected). It is refused rather than wiping the packs that are loaded.
var ErrNoVerifier = errors.New("no update signature verifier configured")
ErrNoVerifier means no signature verifier is configured, so every update is refused (fail closed, FORBID-3).
var ErrReplay = errors.New("update version is not newer than the installed one")
ErrReplay means the update is not newer than the installed one, or its version cannot be ordered.
var ErrUnsigned = errors.New("update signature is not valid")
ErrUnsigned means the update's signature is not valid.
var Migrations = mustSub(migrationFiles, "migrations/sqlite")
Migrations holds the SQLite migrations of the mitigation module. Apply them after the migrations of core and findings: the tables point at fnd_finding.
Functions ¶
func CheckPack ¶
CheckPack reports whether the box would load this pack document, and its CVE (the release tool runs it before signing).
func FindingFolded ¶
FindingFolded is mitigation's part of a device merge that folds two findings of one CVE into one (core/lifecycle, inside the inventory's write, before the folded finding f.From is deleted): its "Applied" marks and AI results become f.Into's. An item both findings had marked applied keeps the earlier mark; of two AI results of the same skill the newer stays.
func Statement ¶
Statement is the text the release key signs for one update: the header, the version, then one line per document with the SHA-256 of its bytes and its name, sorted by name. It binds Update.Version, every byte of every Docs[].Data and the set of documents (adding, removing, renaming or swapping one changes it).
Types ¶
type AI ¶
type AI interface {
// Available reports whether a profile is assigned and allowed for the skill and the ai module is on.
Available(ctx context.Context, s Skill) bool
// Run asks the AI. ErrAIUnavailable (wrapped) when it cannot be used; an *apierr.Error of the ai module (ai_unavailable,
// budget_reached, ai_cut_off, ai_bad_format, blocked_by_hook, provider_error, unreachable, ai_timeout) is answered as it is.
Run(ctx context.Context, req AIRequest) (AIOutput, error)
}
AI is the small door to the ai module (its RunJob, not wired yet). The AI never gets a write tool here (SYS-8): it returns text and this module stores it as an AI result.
type AIOutput ¶
type AIOutput struct {
Model string
Profile string // name of the profile that answered
InputTok int
OutputTok int
Paragraphs []string
Steps []string
// Answers are the four answers in order (findings.AIResult.Answers).
Answers []findings.AIAnswer
// Configs are the ready config blocks of the mitigation-config skill (Code is the lines to paste, Note what the change is based
// on, SideEffect what it can break); none for explain.
Configs []findings.CodeStep
// NoConfigReason says why no config (or no firewall rule) helps for this finding, when the AI gave none (#897 r1 H1).
NoConfigReason string
// Shortened: a part of the answer was longer than the AI module keeps (cut at a sentence end, or a config block left out whole).
Shortened bool
Citations []findings.Citation
ActivityID string // id of the ai_activity row, "" when none
}
AIOutput is the answer of the AI module, already metered and logged by it.
type AIRequest ¶
type AIRequest struct {
Skill Skill
FindingID string
HasPack bool
User string // email of the person who asked
}
AIRequest is what the AI is asked about: one finding, by id. The AI door reads the finding's view and the brief of its CVE itself, the same sources the page reads, and whether a confirmed pack exists (the config skill is for when it does not).
type ActionHandlers ¶
type ActionHandlers struct {
// contains filtered or unexported fields
}
ActionHandlers implements POST /findings/{id}/applied and POST /findings/{id}/ai (operator). Embed it in the composite handler; it implements no other operation.
func NewActionHandlers ¶
func NewActionHandlers(db *store.DB, a *audit.Log, f *findings.Service, d Details, ai AI, clock func() time.Time) (*ActionHandlers, error)
NewActionHandlers returns the handlers; every argument except clock is required.
func (*ActionHandlers) FindingsPostFindingsIDAi ¶
func (h *ActionHandlers) FindingsPostFindingsIDAi(ctx context.Context, req *oas.FindingsPostFindingsIDAiReq, params oas.FindingsPostFindingsIDAiParams) (*oas.FindingsPostFindingsIDAiOK, error)
FindingsPostFindingsIDAi implements findings_post_findings_id_ai (INV-3): the customer's AI explains the finding or drafts a recommendation; the result is stored as an AI result and answered with its AI label data (model, profile, tokens, citations). 409 ai_unavailable when it cannot be used.
func (*ActionHandlers) FindingsPostFindingsIDApplied ¶
func (h *ActionHandlers) FindingsPostFindingsIDApplied(ctx context.Context, req *oas.FindingsPostFindingsIDAppliedReq, params oas.FindingsPostFindingsIDAppliedParams) (*oas.FindingsPostFindingsIDAppliedOK, error)
FindingsPostFindingsIDApplied implements findings_post_findings_id_applied (INV-1): it logs one item as applied, once, and never changes the finding's status.
type Details ¶
type Details interface {
Detail(ctx context.Context, rec findings.Record) (findings.Detail, error)
}
Details is how the handlers answer: the finding page, as findings composes it (satisfied by *findings.FindingHandlers, which also asks this module's Provider for the "What to do" part).
type InstallResult ¶
InstallResult is what Install did.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader loads confirmed packs from signed updates into mit_pack (INV-2).
func NewLoader ¶
func NewLoader(db *store.DB, a *audit.Log, v Verifier, log *slog.Logger, clock func() time.Time) *Loader
NewLoader returns the loader. A nil verifier is allowed and refuses everything.
func (*Loader) Install ¶
Install replaces the loaded packs with the valid ones of the update, in one transaction. An update with no valid pack (ErrNoValidPack) and one whose version is not newer than the installed one (ErrReplay) are refused and change nothing; a refused update does not use up its version.
The signature is checked first: without a verifier, or when it fails, nothing is read and nothing changes. Then each document is held to INV-2: status confirmed, confirmed_by, confirmed_at, drafted_with and sources present. A document that fails is rejected on its own (listed in the result) and does not stop the others. A pack missing from the new update is withdrawn.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider is the "What to do" provider findings asks for (PRE-1, POST-1). Register it with findings.FindingHandlers.SetGuidance.
func NewProvider ¶
NewProvider returns the provider.
func (*Provider) SetAgents ¶
func (p *Provider) SetAgents(f findings.AgentReports)
SetAgents registers whether an agent of this box reads a device now: the same check as the finding page's "No agent reports" line (cmd/vedette agentReports), so the steps never promise an agent that no longer reports (INV-7).
type Skill ¶
type Skill string
Skill is what the customer's AI is asked to do for a finding (POST /findings/{id}/ai).
type Update ¶
type Update struct {
Version string // the update's version, kept as pack_version
Docs []Doc
Signature []byte
}
Update is the mitigation content of one signed update: pack documents (JSON) and the signature material core/updates holds. The Verifier decides what the signature covers.
func ReadPackDir ¶
ReadPackDir reads a pack directory into an Update (fail closed): only regular files are read, never a link or anything below a sub-directory; VERSION and packs.minisig are required; every other *.json file is a document; packs.list and README files are skipped, hidden files too, and any other file refuses the directory. Sizes are capped per file, in number and in total.
type Vendors ¶
type Vendors interface {
// HasFirewallVendor reports whether the inventory has a firewall or router whose vendor is the
// given lower-case inventory vendor name ("fortinet", "mikrotik").
HasFirewallVendor(ctx context.Context, vendor string) (bool, error)
}
Vendors is what mitigation reads from the inventory to mark the firewall guides of a confirmed pack (INV-5).
type Verifier ¶
type Verifier interface {
// Verify returns nil only when the signature of the whole update is valid. The signature must bind
// Update.Version and the bytes of every Docs[].Data (and their set), or the replay protection and
// the confirmed-pack rule can be bypassed by swapping what the signature does not cover.
Verify(ctx context.Context, u Update) error
}
Verifier checks the signature of an update (core/updates; not built yet).