Documentation
¶
Overview ¶
Package policy evaluates packages against CVE/allow/deny policy profiles.
Index ¶
- Constants
- 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) EditList(list, entry string, add bool) (changed bool, err error)
- func (r *Runtime) Evaluate(ref *gate.PackageRef, result *gate.ScanResult) gate.PolicyDecision
- func (r *Runtime) Persistent() bool
- func (r *Runtime) Update(fn func(cur RuntimeParams) RuntimeParams) error
- type RuntimeParams
- type SettingsStore
- type ValidationError
Constants ¶
const ( ListAllowlistSupply = "allowlist_supply" ListAllowlistCVE = "allowlist_cve" ListDenylist = "denylist" )
Names of the editable lists, as used by EditList and the console API.
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. Calls are serialised; 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) EditList ¶ added in v0.6.0
EditList adds or removes one entry of the named list atomically. Adding an existing entry and removing an absent one are no-ops (changed=false, nothing persisted).
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).
func (*Runtime) Update ¶ added in v0.6.0
func (r *Runtime) Update(fn func(cur RuntimeParams) RuntimeParams) error
Update reads the current params, applies fn, validates the result, persists it and installs it, all under one lock so concurrent edits cannot lose each other's changes. fn receives a copy it may modify freely. On error the current policy is unchanged.
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