Documentation
¶
Overview ¶
Package policy evaluates packages against CVE/allow/deny policy profiles.
Index ¶
- func EncodeStored(p RuntimeParams) ([]byte, error)
- type Engine
- type PersistError
- type Runtime
- func (r *Runtime) Apply(p RuntimeParams) error
- func (r *Runtime) Check(ctx context.Context, ref *gate.PackageRef, meta *gate.PackageMetadata) gate.FilterResult
- func (r *Runtime) Current() RuntimeParams
- func (r *Runtime) Evaluate(ref *gate.PackageRef, result *gate.ScanResult) gate.PolicyDecision
- func (r *Runtime) Persistent() bool
- type RuntimeParams
- type SettingsStore
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeStored ¶
func EncodeStored(p RuntimeParams) ([]byte, error)
EncodeStored marshals the params in the current (per-gate) format; the legacy "allowlist" key is never written back.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine evaluates packages against a policy profile. It implements gate.PolicyDecider.
func NewEngine ¶
func NewEngine(cfg config.CVEConfig, profile config.PolicyProfile) *Engine
NewEngine creates a PolicyEngine from the CVE config and the active profile. Profile's CVEMinSeverity overrides cfg.BlockOn when non-empty.
func (*Engine) Evaluate ¶
func (e *Engine) Evaluate(ref *gate.PackageRef, result *gate.ScanResult) gate.PolicyDecision
Evaluate implements gate.PolicyDecider.
type PersistError ¶
type PersistError struct{ Err error }
PersistError wraps a failure to write the policy to the settings store. It is distinct from ValidationError so the console can map it to HTTP 500.
func (*PersistError) Error ¶
func (e *PersistError) Error() string
func (*PersistError) Unwrap ¶
func (e *PersistError) Unwrap() error
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime holds the current policy Engine and supply-chain Filter behind an atomic pointer so the console can swap both without restart. It implements gate.PolicyDecider and gate.SCFilter. Edits are runtime-only: the YAML config wins again after a restart.
func NewRuntime ¶
func NewRuntime(sc config.SupplyChainConfig, cve config.CVEConfig, profile config.PolicyProfile, fileAllow []string) *Runtime
NewRuntime builds the boot snapshot from config. fileAllow entries are always honored by the supply-chain filter regardless of runtime edits.
The YAML profile allowlist historically bypassed CVE and age checks, so it seeds BOTH per-gate lists. Runtime edits manage the two lists independently.
func NewRuntimeWithStore ¶
func NewRuntimeWithStore(sc config.SupplyChainConfig, cve config.CVEConfig, profile config.PolicyProfile, fileAllow []string, store SettingsStore) (*Runtime, error)
NewRuntimeWithStore seeds the store from YAML on first boot (empty store) or installs the stored params otherwise (DB wins). A nil store behaves like NewRuntime.
func (*Runtime) Apply ¶
func (r *Runtime) Apply(p RuntimeParams) error
Apply validates p and atomically swaps the active policy. Concurrent calls are safe; last writer wins (no compare-and-swap). On error the current policy is unchanged.
func (*Runtime) Check ¶
func (r *Runtime) Check(ctx context.Context, ref *gate.PackageRef, meta *gate.PackageMetadata) gate.FilterResult
Check implements gate.SCFilter against the current snapshot.
func (*Runtime) Current ¶
func (r *Runtime) Current() RuntimeParams
Current returns a copy of the active params.
func (*Runtime) Evaluate ¶
func (r *Runtime) Evaluate(ref *gate.PackageRef, result *gate.ScanResult) gate.PolicyDecision
Evaluate implements gate.PolicyDecider against the current snapshot.
func (*Runtime) Persistent ¶
Persistent reports whether policy edits are saved to a settings store and therefore survive a restart (false = runtime-only, YAML wins after restart).
type RuntimeParams ¶
type RuntimeParams struct {
Mode string `json:"mode"` // supply-chain mode: enforce | dry_run | off
MinAgeHours int `json:"min_age_hours"` // supply-chain minimum age, >= 0
CVEBlockOn string `json:"cve_block_on"` // CRITICAL | HIGH | MEDIUM | LOW
AllowlistSupply []string `json:"allowlist_supply"` // "eco/name[@version]", bypasses the age hold
AllowlistCVE []string `json:"allowlist_cve"` // "eco/name[@version]", bypasses the CVE block
Denylist []string `json:"denylist"`
}
RuntimeParams are the console-editable policy knobs (PUT /api/policy). Allowlists are per-gate: supply entries bypass only the min-age hold, cve entries bypass only the CVE block. Nothing bypasses the malware gate.
func DecodeStored ¶
func DecodeStored(b []byte) (RuntimeParams, error)
DecodeStored parses a persisted policy row, migrating the legacy single allowlist into both per-gate lists (deduplicated, order preserved).
type SettingsStore ¶
type SettingsStore interface {
LoadPolicy() (RuntimeParams, bool, error)
SavePolicy(RuntimeParams) error
}
SettingsStore persists the runtime policy params. Implemented in cmd/jo-ei by an adapter over *settings.Store that marshals RuntimeParams to/from JSON.
type ValidationError ¶
ValidationError names the parameter that failed validation.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string