Documentation
¶
Index ¶
- func CollectNamespacedObjects(ctx context.Context, client *kube.Client, namespace string) ([]map[string]any, error)
- func DecodeK8SYAML(manifest string) ([]map[string]any, error)
- func DecodeK8SYAMLWithHelmSources(manifest string) ([]map[string]any, error)
- func DecodeK8SYAMLWithSources(manifest string) ([]map[string]any, error)
- func EvaluatePolicy(ctx context.Context, opts PolicyOptions, objects []map[string]any) (*policy.Report, error)
- func ManifestDigestSHA256(manifest string) string
- func RenderFixPlanText(changes []FixChange) string
- func RulesetDigest(dir string) (string, error)
- func RulesetDigestMulti(dirs []string) (string, error)
- func SHA256Hex(text string) string
- func SplitYAMLDocs(manifest string) []string
- func ToSARIF(rep *Report) ([]byte, error)
- func WriteExposureJSON(w io.Writer, ex *ExposureReport) error
- func WriteReport(w io.Writer, rep *Report, format OutputFormat) error
- type Console
- type ConsoleMeta
- type ConsoleOptions
- type Delta
- type DeltaDetail
- type DeltaReport
- type Emitter
- type EngineMeta
- type Event
- type EventType
- type ExposureEdge
- type ExposureGraph
- type ExposureNode
- type ExposureReport
- type Finding
- func AnnotateFindingsWithRenderedSource(renderedPath string, renderedManifest string, findings []Finding) []Finding
- func EvaluateRules(ctx context.Context, rules Ruleset, objects []map[string]any, ...) ([]Finding, error)
- func EvaluateRulesWithSelectors(ctx context.Context, rules Ruleset, objects []map[string]any, ...) ([]Finding, error)
- func PolicyReportToFindings(rep *policy.Report) []Finding
- type FixChange
- type Input
- type Mode
- type Options
- type OutputFormat
- type PolicyOptions
- type PublicSurface
- type Report
- type Rule
- type RuleSelector
- type Ruleset
- type Runner
- type Selector
- type SelectorSet
- type Severity
- type Subject
- type Summary
- type TargetReference
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeK8SYAMLWithHelmSources ¶
DecodeK8SYAMLWithHelmSources preserves Helm template source hints by parsing documents individually and extracting "# Source:" comments before decoding.
func DecodeK8SYAMLWithSources ¶
DecodeK8SYAMLWithSources decodes a multi-document YAML manifest into objects and attaches a best-effort template source (Helm "# Source: ...") to each object, if present.
It annotates objects with: - __torque_source: string
func EvaluatePolicy ¶
func ManifestDigestSHA256 ¶
func RenderFixPlanText ¶
func RulesetDigest ¶
func RulesetDigestMulti ¶
func SplitYAMLDocs ¶
SplitYAMLDocs splits a YAML stream into raw documents. It is intentionally simple and only treats "---" at the start of a line as a separator.
func WriteExposureJSON ¶
func WriteExposureJSON(w io.Writer, ex *ExposureReport) error
func WriteReport ¶
func WriteReport(w io.Writer, rep *Report, format OutputFormat) error
Types ¶
type Console ¶
type Console struct {
// contains filtered or unexported fields
}
Console renders verify events into a single in-place updating TTY view. It is event-driven: callers should feed Event values via Observe.
func NewConsole ¶
func NewConsole(out io.Writer, meta ConsoleMeta, opts ConsoleOptions) *Console
func (*Console) SnapshotLines ¶
SnapshotLines returns the current console surface as plain lines (no cursor movement). It is intended for tests and debugging.
type ConsoleMeta ¶
type ConsoleOptions ¶
type Delta ¶
type Delta struct {
NewOrChanged []Finding
Fixed []Finding
Unchanged int
NewOrChangedDetails []DeltaDetail
FixedDetails []DeltaDetail
}
func ComputeDelta ¶
type DeltaDetail ¶
type DeltaDetail struct {
Kind string `json:"kind,omitempty"` // new|changed|fixed
Changes []string `json:"changes,omitempty"`
Current *Finding `json:"current,omitempty"`
Baseline *Finding `json:"baseline,omitempty"`
}
DeltaDetail describes why a finding is considered new/changed/fixed when comparing the current report against a baseline.
It is designed for UX consumers (HTML report, PR comments) to show a concise change narrative without having to re-derive it client-side.
type DeltaReport ¶
type DeltaReport struct {
BaselineTotal int `json:"baselineTotal,omitempty"`
Unchanged int `json:"unchanged,omitempty"`
// NewOrChanged and Fixed are kept for backwards compatibility with older
// reports/consumers.
NewOrChanged []Finding `json:"newOrChanged,omitempty"`
Fixed []Finding `json:"fixed,omitempty"`
// NewOrChangedDetails and FixedDetails provide a change narrative for compare-to:
// what changed (message/observed/expected/severity/etc) and a snapshot of the
// baseline finding.
NewOrChangedDetails []DeltaDetail `json:"newOrChangedDetails,omitempty"`
FixedDetails []DeltaDetail `json:"fixedDetails,omitempty"`
}
type EngineMeta ¶
type ExposureEdge ¶
type ExposureGraph ¶
type ExposureGraph struct {
Nodes []ExposureNode `json:"nodes,omitempty"`
Edges []ExposureEdge `json:"edges,omitempty"`
}
type ExposureNode ¶
type ExposureReport ¶
type ExposureReport struct {
PublicSurfaces []PublicSurface `json:"publicSurfaces,omitempty"`
Graph ExposureGraph `json:"graph,omitempty"`
}
func AnalyzeExposure ¶
func AnalyzeExposure(objects []map[string]any) ExposureReport
type Finding ¶
type Finding struct {
RuleID string `json:"ruleId"`
Severity Severity `json:"severity"`
Category string `json:"category,omitempty"`
Message string `json:"message"`
FieldPath string `json:"fieldPath,omitempty"`
Path string `json:"path,omitempty"`
Line int `json:"line,omitempty"`
Location string `json:"location,omitempty"`
ResourceKey string `json:"resourceKey,omitempty"`
Expected string `json:"expected,omitempty"`
Observed string `json:"observed,omitempty"`
Subject Subject `json:"subject,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
HelpURL string `json:"helpUrl,omitempty"`
Tags []string `json:"tags,omitempty"`
Evidence map[string]any `json:"evidence,omitempty"`
}
func AnnotateFindingsWithRenderedSource ¶
func AnnotateFindingsWithRenderedSource(renderedPath string, renderedManifest string, findings []Finding) []Finding
AnnotateFindingsWithRenderedSource sets Finding.Path and Finding.Line based on the rendered manifest's YAML node positions. It does not overwrite existing Path/Line values.
renderedPath should be a real file path when possible so SARIF consumers can open the artifact and jump to the line.
func EvaluateRules ¶
func EvaluateRulesWithSelectors ¶
func EvaluateRulesWithSelectors(ctx context.Context, rules Ruleset, objects []map[string]any, commonDirs []string, selectors SelectorSet, ruleSelectors []RuleSelector) ([]Finding, error)
func PolicyReportToFindings ¶
type FixChange ¶
type FixChange struct {
Kind string `json:"kind,omitempty"`
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
RuleID string `json:"ruleId,omitempty"`
Title string `json:"title,omitempty"`
PatchYAML string `json:"patchYaml,omitempty"`
}
func BuildFixPlan ¶
type Input ¶
type Input struct {
Kind string `json:"kind,omitempty"` // chart|namespace|manifest
Source string `json:"source,omitempty"`
Chart string `json:"chart,omitempty"`
Release string `json:"release,omitempty"`
Namespace string `json:"namespace,omitempty"`
RenderedSHA256 string `json:"renderedSha256,omitempty"`
CollectedAtHint string `json:"collectedAtHint,omitempty"`
}
type Options ¶
type Options struct {
Mode Mode
FailOn Severity
Format OutputFormat
RulesDir string
ExtraRules []string
Selectors SelectorSet
RuleSelectors []RuleSelector
AttestDir string
ReportPath string
Now func() time.Time
}
type OutputFormat ¶
type OutputFormat string
const ( OutputTable OutputFormat = "table" OutputJSON OutputFormat = "json" OutputSARIF OutputFormat = "sarif" OutputHTML OutputFormat = "html" OutputMD OutputFormat = "md" )
type PolicyOptions ¶
type PublicSurface ¶
type Report ¶
type Report struct {
Tool string `json:"tool"`
Engine EngineMeta `json:"engine"`
Mode Mode `json:"mode"`
FailOn Severity `json:"failOn,omitempty"`
Passed bool `json:"passed"`
Blocked bool `json:"blocked"`
EvaluatedAt time.Time `json:"evaluatedAt"`
Inputs []Input `json:"inputs,omitempty"`
Summary Summary `json:"summary"`
Findings []Finding `json:"findings,omitempty"`
Delta *DeltaReport `json:"delta,omitempty"`
Exposure *ExposureReport `json:"exposure,omitempty"`
}
func LoadReport ¶
func VerifyObjects ¶
type RuleSelector ¶
type Ruleset ¶
func LoadRuleset ¶
type Selector ¶
type Selector struct {
Kinds []string `yaml:"kinds,omitempty" json:"kinds,omitempty"`
Namespaces []string `yaml:"namespaces,omitempty" json:"namespaces,omitempty"`
Labels map[string]string `yaml:"labels,omitempty" json:"labels,omitempty"`
Regex []string `yaml:"regex,omitempty" json:"regex,omitempty"`
}
type SelectorSet ¶
type Summary ¶
type Summary struct {
Total int `json:"total"`
BySev map[Severity]int `json:"bySeverity,omitempty"`
ByRule map[string]int `json:"byRule,omitempty"`
ByRuleSeverity map[string]map[Severity]int `json:"byRuleSeverity,omitempty"`
Passed bool `json:"passed"`
Blocked bool `json:"blocked"`
}
func BuildSummary ¶
BuildSummary computes summary stats for findings.