Documentation
¶
Index ¶
- Variables
- func DataAs[T any](r Result) (T, bool)
- func GetData[T any](store ResultStore, id CheckID) (T, bool)
- func NewRequestFromResource(ctx context.Context, r Resource, mutators ...probe.RequestMutator) (*http.Request, error)
- func ResourceDataAs[T any](resource Resource) (T, bool)
- type Attempt
- type Baseline
- type BaselineCheckConfig
- type BaselineComparator
- type BaselineSource
- type Check
- type CheckFunc
- type CheckID
- type CheckScope
- type Condition
- type Engine
- type GlobalBaselineCheckConfig
- type GlobalBaselineSource
- type GlobalCapture
- type Observation
- type Option
- type Reporter
- type Resource
- type ResourceCheckFunc
- type Result
- type ResultStore
- type RunOption
- func WithCAPECID(ids ...string) RunOption
- func WithCVSSScoreRange(min, max float64) RunOption
- func WithCVSSVector(vectors ...string) RunOption
- func WithCWEID(ids ...string) RunOption
- func WithExclude(ids ...CheckID) RunOption
- func WithFilter(keep func(Check) bool) RunOption
- func WithMaxCVSSScore(max float64) RunOption
- func WithMinCVSSScore(min float64) RunOption
- func WithOWASP(ids ...string) RunOption
- func WithOnly(ids ...CheckID) RunOption
- type ScanError
- type ScanSummary
- type Scenario
- type SkipDecision
- type Snapshot
- type StaticResultStore
- type Target
- type VariantCheckFunc
- type VariantMode
- type VariantResourceCheckFunc
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func NewRequestFromResource ¶ added in v0.3.0
func NewRequestFromResource(ctx context.Context, r Resource, mutators ...probe.RequestMutator) (*http.Request, error)
NewRequestFromResource builds a request for resource r via probe.NewRequest, defaulting to GET when r.Method is empty.
func ResourceDataAs ¶ added in v0.1.2
Types ¶
type Baseline ¶ added in v0.3.0
type Baseline = Snapshot
Baseline is a Snapshot held up as the expected/reference response for a resource.
type BaselineCheckConfig ¶ added in v0.3.0
type BaselineCheckConfig struct {
ID CheckID
Name string
Description string
DependsOn []CheckID
// Baseline resolves the expected response for a resource.
Baseline BaselineSource
// Capture performs the live attempt and returns its snapshot.
Capture func(ctx context.Context, target Target, resource Resource, store ResultStore) (Snapshot, error)
// Compare judges the baseline against the captured snapshot.
// Defaults to CompareStatusCode when nil.
Compare BaselineComparator
Timeout time.Duration
Concurrency int
}
BaselineCheckConfig configures a baseline-comparison check built by NewBaselineCheck.
type BaselineComparator ¶ added in v0.3.0
type BaselineComparator func(baseline, current Snapshot) []Observation
BaselineComparator compares a baseline against a freshly captured snapshot and returns any resulting Observations. A nil or empty result means no deviation was found.
type BaselineSource ¶ added in v0.3.0
type BaselineSource func(ctx context.Context, target Target, resource Resource, store ResultStore) (Baseline, bool)
BaselineSource resolves the baseline for a resource. It returns ok=false when no baseline is available, in which case the comparison check skips.
func BaselineFromCheck ¶ added in v0.3.0
func BaselineFromCheck(id CheckID) BaselineSource
BaselineFromCheck returns a BaselineSource that reads the baseline captured for a resource by a prior "baseline probe" check (see CaptureBaselineCheck), via that check's per-resource Result.Data.
func BaselineFromResource ¶ added in v0.3.0
func BaselineFromResource() BaselineSource
BaselineFromResource returns a BaselineSource that reads a baseline manually attached to Resource.Data at discovery time.
func StaticBaseline ¶ added in v0.3.0
func StaticBaseline(b Baseline) BaselineSource
StaticBaseline returns a BaselineSource that always resolves to the same fixed baseline, regardless of target or resource.
type Check ¶
type Check struct {
ID CheckID
Name string
Description string
Link string
Tags []string
DependsOn []CheckID
Conditions []Condition
// Security metadata, mirrored from checkdef.CheckDef. Purely
// descriptive — the engine only reads these for run-time check
// selection (see WithMinCVSSScore, WithCWEID, WithOWASP, ...).
CVSSVector string
CVSSScore float64
CWEID string
CAPECID string
OWASP string
Skip SkipDecision
Scope CheckScope
Run CheckFunc
RunResource ResourceCheckFunc
Variants []string
VariantMode VariantMode
RunVariant VariantCheckFunc
RunResourceVariant VariantResourceCheckFunc
Timeout time.Duration
Concurrency int
}
func CaptureBaselineCheck ¶ added in v0.3.0
func CaptureBaselineCheck(id CheckID, name string, capture func(ctx context.Context, target Target, resource Resource, store ResultStore) (Snapshot, error)) Check
CaptureBaselineCheck builds a ScopePerResource Check that captures a Snapshot per resource via capture and stores it as Result.Data — the "baseline probe". Pair it with BaselineFromCheck(id) and a DependsOn on this check's id in the comparison check.
func CaptureGlobalBaselineCheck ¶ added in v0.3.0
func CaptureGlobalBaselineCheck(id CheckID, name string, capture GlobalCapture) Check
CaptureGlobalBaselineCheck is the ScopeGlobal counterpart of CaptureBaselineCheck, for targets with no per-resource dimension.
func NewBaselineCheck ¶ added in v0.3.0
func NewBaselineCheck(cfg BaselineCheckConfig) Check
NewBaselineCheck builds a ScopePerResource Check that resolves cfg.Baseline, captures the current response via cfg.Capture, and compares them via cfg.Compare (CompareStatusCode by default). A resource with no resolvable baseline is skipped rather than compared.
func NewGlobalBaselineCheck ¶ added in v0.3.0
func NewGlobalBaselineCheck(cfg GlobalBaselineCheckConfig) Check
NewGlobalBaselineCheck is the ScopeGlobal counterpart of NewBaselineCheck, for targets with no per-resource dimension (see BaselineCheckConfig for the ScopePerResource variant).
type Condition ¶
type Condition func(store ResultStore) bool
func IfCheckObserved ¶ added in v0.1.1
func IfCheckPassed ¶
func IfCheckSkipped ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) RunScenario ¶ added in v0.1.2
func (e *Engine) RunScenario(ctx context.Context, target Target, scenario Scenario) (ScanSummary, error)
RunScenario executes the checks in scenario against target using the engine's configured reporters, concurrency limits, and default timeout. It does not consult or modify the engine's registered check list — scenario.Checks is fully self-contained.
Reporter.OnScanComplete is always called before returning, even if scenario.Checks is empty.
type GlobalBaselineCheckConfig ¶ added in v0.3.0
type GlobalBaselineCheckConfig struct {
ID CheckID
Name string
Description string
DependsOn []CheckID
Baseline GlobalBaselineSource
Capture GlobalCapture
Compare BaselineComparator
Timeout time.Duration
}
GlobalBaselineCheckConfig is the ScopeGlobal counterpart of BaselineCheckConfig.
type GlobalBaselineSource ¶ added in v0.3.0
type GlobalBaselineSource func(ctx context.Context, target Target, store ResultStore) (Baseline, bool)
GlobalBaselineSource is the ScopeGlobal counterpart of BaselineSource: it resolves the Baseline to compare against for a target with no per-resource dimension.
func BaselineFromGlobalCheck ¶ added in v0.3.0
func BaselineFromGlobalCheck(id CheckID) GlobalBaselineSource
BaselineFromGlobalCheck is the ScopeGlobal counterpart of BaselineFromCheck: it reads the baseline from the global (non-per-resource) result of a prior check (see CaptureGlobalBaselineCheck).
func StaticGlobalBaseline ¶ added in v0.3.0
func StaticGlobalBaseline(b Baseline) GlobalBaselineSource
StaticGlobalBaseline is the ScopeGlobal counterpart of StaticBaseline.
type GlobalCapture ¶ added in v0.3.0
GlobalCapture is the ScopeGlobal counterpart of the Capture func used by BaselineCheckConfig: it captures the current Snapshot for a target with no per-resource dimension.
type Observation ¶ added in v0.1.1
type Observation struct {
CheckID CheckID
ResourceID string
Variant string
Title string
Description string
Evidence string
Metadata map[string]string
}
func CompareStatusCode ¶ added in v0.3.0
func CompareStatusCode(baseline, current Snapshot) []Observation
CompareStatusCode is the default BaselineComparator: it flags any change in status code between the baseline and the current snapshot.
type Option ¶
type Option func(*engineConfig)
func WithChecks ¶
func WithDefaultTimeout ¶
func WithMaxConcurrency ¶
func WithReporters ¶
type ResourceCheckFunc ¶
type Result ¶
type Result struct {
CheckID CheckID
ResourceID string
Observations []Observation
Resources []Resource
Skipped bool
SkipReason string
Duration time.Duration
Metadata map[string]string
Data any
Err error
Attempts []Attempt
}
func DataResult ¶
DataResult returns a Result carrying data without a CheckID. The engine always sets CheckID after the run, so callers inside a Run func do not need to supply the ID themselves.
func ResultData ¶
type ResultStore ¶
type RunOption ¶ added in v0.4.0
type RunOption func(*runConfig)
RunOption customizes which registered checks execute for a single Engine.Run call.
func WithCAPECID ¶ added in v0.4.0
WithCAPECID keeps only checks whose CAPECID matches one of the given IDs (case-insensitive, e.g. "CAPEC-31").
func WithCVSSScoreRange ¶ added in v0.4.0
WithCVSSScoreRange keeps only checks whose CVSSScore is within [min, max].
func WithCVSSVector ¶ added in v0.4.0
WithCVSSVector keeps only checks whose CVSSVector exactly matches one of the given vectors.
func WithCWEID ¶ added in v0.4.0
WithCWEID keeps only checks whose CWEID matches one of the given IDs (case-insensitive, e.g. "CWE-345").
func WithExclude ¶ added in v0.4.0
WithExclude removes the given check IDs from a run.
func WithFilter ¶ added in v0.4.0
WithFilter restricts a run to checks for which keep returns true. Multiple WithFilter options (and the WithCVSS*/WithCWEID/WithCAPECID/WithOWASP helpers, which are built on it) are AND-combined. A check that a selected check depends on is kept even when it fails the filter, so the dependency graph stays valid — only WithExclude drops a dependency.
func WithMaxCVSSScore ¶ added in v0.4.0
WithMaxCVSSScore keeps only checks whose CVSSScore is <= max.
func WithMinCVSSScore ¶ added in v0.4.0
WithMinCVSSScore keeps only checks whose CVSSScore is >= min.
type ScanSummary ¶
type Scenario ¶ added in v0.1.2
Scenario is a named, ordered subset of checks to execute against a target. Pass it to Engine.RunScenario to execute only those checks using the engine's configured reporters, concurrency limits, and default timeout.
Checks can be shared across scenarios by referencing the same CheckFunc variable from multiple Check values, each with its own Check.DependsOn wiring — so the same business logic can run at different points in different scenario dependency graphs.
type SkipDecision ¶
type SkipDecision struct {
// contains filtered or unexported fields
}
func SkipAlways ¶
func SkipAlways(reason string) SkipDecision
func SkipResourceWhen ¶ added in v0.2.0
func SkipResourceWhen(fn func(ctx context.Context, target Target, resource Resource, store ResultStore) string) SkipDecision
SkipResourceWhen builds a skip decision evaluated once per resource for a ScopePerResource check, instead of once for the whole check. Use this when the decision depends on the resource itself (e.g. its security scheme) rather than on the target or environment.
func SkipWhen ¶
func SkipWhen(fn func(ctx context.Context, target Target, store ResultStore) string) SkipDecision
func (SkipDecision) Eval ¶ added in v0.1.2
func (s SkipDecision) Eval(ctx context.Context, target Target, store ResultStore) string
Eval runs the skip decision and returns a non-empty skip reason if the check should be skipped, or "" if it should run.
func (SkipDecision) EvalResource ¶ added in v0.2.0
func (s SkipDecision) EvalResource(ctx context.Context, target Target, resource Resource, store ResultStore) string
EvalResource runs the per-resource skip decision, falling back to Eval (the check-wide decision) when no resource-specific decision was set.
type Snapshot ¶ added in v0.3.0
type Snapshot struct {
StatusCode int
Header http.Header
Body []byte
Duration time.Duration
Data any
}
Snapshot is a captured response, reduced to whatever a comparator needs to judge it. StatusCode is the convenience field the default comparator uses; Header, Body, and Duration carry the full response for comparators that need more; Data carries anything else custom comparators want to inspect.
func ProbeAndCompareBaseline ¶ added in v0.3.0
func ProbeAndCompareBaseline(ctx context.Context, p *probe.Probe, build probe.RequestBuilder, store ResultStore, baselineID CheckID) (Snapshot, bool, error)
ProbeAndCompareBaseline sends the request returned by build via probe.Do, keeping the full response (headers, body, duration) in the Snapshot for comparators that need more than the status code, and compares the resulting snapshot against the baseline stored under baselineID. It returns the current snapshot and whether the response deviated from the baseline.
type StaticResultStore ¶ added in v0.1.2
type StaticResultStore struct {
// contains filtered or unexported fields
}
StaticResultStore is a ResultStore fixture for tests: seed it with the Results a check's Skip decision or Conditions should see, without running the Engine.
func NewStaticResultStore ¶ added in v0.1.2
func NewStaticResultStore(results ...Result) *StaticResultStore
func (*StaticResultStore) Get ¶ added in v0.1.2
func (s *StaticResultStore) Get(id CheckID) (Result, bool)
func (*StaticResultStore) GetForResource ¶ added in v0.1.2
func (s *StaticResultStore) GetForResource(id CheckID, _ string) (Result, bool)
func (*StaticResultStore) Observations ¶ added in v0.1.2
func (s *StaticResultStore) Observations() []Observation
func (*StaticResultStore) Resources ¶ added in v0.1.2
func (s *StaticResultStore) Resources() []Resource
type VariantCheckFunc ¶ added in v0.3.0
type VariantMode ¶ added in v0.3.0
type VariantMode int
const ( VariantsSequential VariantMode = iota VariantsParallel )
type VariantResourceCheckFunc ¶ added in v0.3.0
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package checkdef parses declarative check metadata (ID, name, description, dependencies, ...) out of an embedded definition file, so a reusable check package can keep that metadata in YAML/TOML/JSON instead of hand-assembling it in Go.
|
Package checkdef parses declarative check metadata (ID, name, description, dependencies, ...) out of an embedded definition file, so a reusable check package can keep that metadata in YAML/TOML/JSON instead of hand-assembling it in Go. |
|
examples
|
|
|
advanced-scan
command
|
|
|
baseline-scan
command
|
|
|
multi-scenario
command
|
|
|
internal
|
|