Documentation
¶
Overview ¶
Package rules holds the rule engine and the rule catalogue.
A rule is a single-file affair: the struct, its registration, its documentation, and its tests all live together, and the same metadata that drives the engine renders the `quaddoc rules` reference page. There is no separate docs step to forget.
Rules are given a Project, never a lone unit. Several checks are only answerable across the whole set: whether a bind source is shared between units (QD001 and QD002), whether siblings can resolve each other (QD030), whether a name collides (QD032). See docs/spec-review.md finding F3.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Confidence ¶
type Confidence string
Confidence records whether a finding was reasoned from the units alone or confirmed against the host. The same rule can produce either, and the wording differs: without host context we say a thing may be true, with it we say it is.
const ( // Possible means the finding was derived from the units alone. Possible Confidence = "possible" // Confirmed means host context established the fact. Confirmed Confidence = "confirmed" )
type Config ¶
type Config struct {
// Disabled lists rule IDs to skip entirely.
Disabled map[string]bool
// SeverityOverride maps a rule ID to the severity to report it at.
SeverityOverride map[string]Severity
}
Config controls which rules run and at what severity.
type Context ¶
type Context struct {
Project *ir.Project
// Host is never nil. When no context was gathered it is an
// unknown-everything implementation, so rules need no nil checks.
Host hostctx.Context
// BindSourceUsage counts how many units mount each bind source. Computed
// once and shared, which is what keeps QD001 and QD002 from
// contradicting each other.
BindSourceUsage map[string]int
// contains filtered or unexported fields
}
Context is what a rule is given: the whole project, the host context if one was gathered, and the analysis shared between rules.
type Finding ¶
type Finding struct {
RuleID string `json:"rule"`
Severity Severity `json:"-"`
SeverityJS string `json:"severity"`
Confidence Confidence `json:"confidence"`
// Unit is the path of the unit the finding concerns.
Unit string `json:"unit"`
// Line is where in that unit, or 0 when the finding is about the unit
// as a whole rather than a particular line.
Line int `json:"line,omitempty"`
// Message states what is wrong, in one sentence.
Message string `json:"message"`
// Remediation is copy-pasteable, or an explicit statement that no
// mechanical fix exists and what decision the user must make instead.
Remediation string `json:"remediation"`
// Fix carries the structured detail the fix engine needs, so that it
// applies exactly what the rule decided rather than re-deriving it from
// the prose. Empty for findings with no mechanical fix.
Fix map[string]string `json:"-"`
// contains filtered or unexported fields
}
Finding is one reported problem.
func (Finding) MarkHostDowngraded ¶ added in v0.2.0
MarkHostDowngraded records that host context lowered this finding's severity, so configuration does not raise it back. Used by the SELinux rules, whose severity depends on whether the kernel enforces policy.
type Rule ¶
type Rule struct {
// ID is the QD### identifier.
ID string
// Summary is a one-line description, shown in listings.
Summary string
// Rationale explains why this matters, in prose, for the reference page.
Rationale string
// Citation names the documentation or observed behaviour the rule
// encodes. A rule without one does not ship: see CLAUDE.md.
Citation string
// DefaultSeverity applies unless configuration overrides it.
DefaultSeverity Severity
// NeedsHostContext marks rules whose findings are only confirmed with a
// host context, and which must degrade gracefully without one.
NeedsHostContext bool
// Fixable marks rules whose remediation is mechanically applicable and
// provably semantics-preserving.
Fixable bool
// Check runs the rule.
Check func(*Context) []Finding
}
Rule is one check over a project.
Metadata lives beside the implementation so the reference documentation cannot drift from what the code does.
type Severity ¶
type Severity int
Severity is how seriously a finding should be taken. It drives the exit code.
func DowngradeForSELinux ¶
func DowngradeForSELinux(mode hostctx.SELinuxMode, def Severity) (Severity, bool)
DowngradeForSELinux applies the ladder from ADR-0004 to a severity that depends on SELinux being enforced.
Under a permissive kernel the label is still wrong, it simply is not being enforced today, and turning enforcing back on would break the container. So the finding drops to a note rather than disappearing. When SELinux is absent from the kernel the finding is meaningless and is suppressed entirely; the caller drops findings for which this returns false.
func ParseSeverity ¶
ParseSeverity converts the textual form used in configuration files.