Documentation
¶
Overview ¶
Package policy loads `.fendix.yaml` — the repo-committable policy file that lets AppSec teams pin Fendix's scan behavior in source control instead of via a long shell-script of CLI flags.
Precedence (lowest to highest):
- Cobra defaults (e.g. workers=10).
- Policy file values (set on Apply when the user did NOT pass the corresponding CLI flag).
- Explicit CLI flags (override policy file when present).
The policy file is intentionally a STRICT subset of the scan-flag surface: only the values teams reasonably want to commit are reflected here. One-shot flags like `--baseline`, `--save-baseline`, `--debug-bundle` are intentionally NOT in the schema — those are per-invocation runtime knobs, not policy.
Index ¶
Constants ¶
const DefaultPath = ".fendix.yaml"
DefaultPath is the canonical filename. Looked up from the scan command's working directory when --config is not passed and the file exists.
const SupportedVersion = 1
SupportedVersion is the policy-schema version this build understands. Newer files will be rejected to surface the upgrade requirement loudly rather than silently ignoring fields the binary doesn't know.
Variables ¶
var ( ErrUnsupportedVersion = errors.New("policy file version is not supported by this fendix build") ErrInvalidFailOn = errors.New("policy.fail_on must be CRITICAL, HIGH, MEDIUM, LOW, or empty") )
Errors from the policy layer.
Functions ¶
This section is empty.
Types ¶
type ApplyTo ¶
type ApplyTo struct {
SetFailOn func(string)
SetEnableActive func(bool)
SetWorkers func(int)
SetTimeoutSec func(int)
SetDelayMs func(int)
SetFormat func(string)
SetCrawlDepth func(int)
SetMaxEndpoints func(int)
SetWordlistPath func(string)
SetRespectRobots func(bool)
SetMaxRequests func(int64)
SetMaxDuration func(time.Duration)
SetIgnorePath func(string)
SetAuthProfile func(string)
SetDeescalateTests func(bool)
SetEnforceConfidence func(bool)
}
ApplyTo writes the policy onto a ScanConfig-shaped target via a small per-field setter callback bag. The callbacks live in the scan command (or wherever ScanConfig is defined) so this package has no compile-time coupling to internal/models. Each setter is only invoked when the policy field is present AND the corresponding CLI flag is NOT in `cli`. Returns the number of fields written.
Setter callbacks are nil-safe — pass nil to skip a field (useful in tests that exercise only a subset of the schema).
type AuthSection ¶
type AuthSection struct {
Profile string `yaml:"profile,omitempty"`
}
AuthSection points at a profile in ~/.fendix/profiles/. The literal secret value is intentionally NOT a field — committable policy must not contain credentials. A `profile` reference is fine because it expands at scan time against the user's local profiles dir.
type BudgetsSection ¶
type BudgetsSection struct {
MaxRequests *int64 `yaml:"max_requests,omitempty"`
MaxDuration *time.Duration `yaml:"max_duration,omitempty"`
}
BudgetsSection covers the global request/duration soft caps from TASK-095. Teams gate CI runs on these to keep scan cost predictable.
type CLISet ¶
CLISet declares which CLI flag names the user passed explicitly. Apply only writes a policy value to a ScanConfig field when the matching CLI flag is NOT in this set — that's how CLI overrides policy. Pass cobra's flag.Changed() result for each flag name.
type CrawlerSection ¶
type CrawlerSection struct {
CrawlDepth *int `yaml:"crawl_depth,omitempty"`
MaxEndpoints *int `yaml:"max_endpoints,omitempty"`
WordlistPath string `yaml:"wordlist_path,omitempty"`
RespectRobots *bool `yaml:"respect_robots,omitempty"`
}
CrawlerSection covers endpoint discovery knobs that affect the scan surface and reliability. WordlistPath is a string (no pointer) — an empty path means "use the built-in CommonPaths" which matches the CLI flag's default behavior.
type Policy ¶
type Policy struct {
Version int `yaml:"version"`
FailOn string `yaml:"fail_on,omitempty"`
Scan *ScanSection `yaml:"scan,omitempty"`
Crawler *CrawlerSection `yaml:"crawler,omitempty"`
Budgets *BudgetsSection `yaml:"budgets,omitempty"`
Auth *AuthSection `yaml:"auth,omitempty"`
// IgnorePath maps to the `--ignore` CLI flag; teams typically
// commit a `.fendix-ignore` alongside `.fendix.yaml` and want the
// path explicit in the policy.
IgnorePath string `yaml:"ignore_path,omitempty"`
}
Policy is the parsed `.fendix.yaml`. Pointer fields distinguish "explicitly set in the file" from "absent" — Apply only writes a value to ScanConfig when the field is present in the file AND the user didn't pass the corresponding CLI flag.
func Load ¶
Load reads and parses a policy file. Returns nil if path is empty or the file does not exist (the latter is only an error when the caller passed --config explicitly; that condition is the caller's responsibility to surface). Returns ErrUnsupportedVersion when the file's version is greater than SupportedVersion or missing.
type ScanSection ¶
type ScanSection struct {
EnableActive *bool `yaml:"enable_active,omitempty"`
Workers *int `yaml:"workers,omitempty"`
TimeoutSec *int `yaml:"timeout,omitempty"`
DelayMs *int `yaml:"delay_ms,omitempty"`
Format *string `yaml:"format,omitempty"`
// DeescalateTests reports findings in test/fixture code as INFO rather
// than WARN (v1.1 B3). Committable because "do we gate on test-code
// findings?" is a team triage policy, not a per-invocation knob. Defaults
// to the CLI default (true) when absent.
DeescalateTests *bool `yaml:"deescalate_tests,omitempty"`
// EnforceConfidence gates --fail-on on the deterministic confidence band
// (v1.2.2 FIX-08). Committable for the same reason deescalate_tests is:
// "how much corroboration do we demand before failing a build?" is a team
// triage policy, not a per-invocation knob. Defaults to the CLI default
// (true) when absent.
EnforceConfidence *bool `yaml:"enforce_confidence,omitempty"`
}
ScanSection mirrors the scan-runtime knobs that make sense to commit. enable_active is a deliberate inclusion: teams that *want* active probing in CI shouldn't have to remember the flag every time. Per the safety contract, --enable-active still requires an explicit user/policy opt-in (default false).