policy

package
v1.5.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package policy evaluates deploy guardrail rules against what an app is about to run. It is pure: callers resolve the layers and the subject.

Index

Constants

View Source
const (
	ScopeOrg         = "org"
	ScopeProject     = "project"
	ScopeEnvironment = "environment"
	// OrgScopeID is the single organization-wide scope id.
	OrgScopeID = "org"
)

Scopes a rule set can be attached to, least to most specific.

View Source
const (
	RuleAllowedRegistries = "allowed_registries"
	RuleRequireReadiness  = "require_readiness_probe"
	RuleMaxMemoryMB       = "max_memory_mb"
	RuleMaxCPU            = "max_cpu"
	RuleForbidPrivileged  = "forbid_privileged"
	RuleForbidHostMounts  = "forbid_host_mounts"
	RuleRequiredLabels    = "required_labels"
	RuleMaxReplicas       = "max_replicas"
	RuleForbidLatestTag   = "forbid_latest_tag"
	RuleRequireDigest     = "require_image_digest"
	RuleRequireLimits     = "require_resource_limits"
	RuleRequireSignature  = "require_image_signature"
)

Rule ids, the keys of a Set.

View Source
const (
	CodeRegistryNotAllowed  = "policy_registry_not_allowed"
	CodeReadinessRequired   = "policy_readiness_probe_required"
	CodeMemoryCeiling       = "policy_memory_ceiling_exceeded"
	CodeCPUCeiling          = "policy_cpu_ceiling_exceeded"
	CodePrivilegedForbidden = "policy_privileged_forbidden"
	CodeHostMountForbidden  = "policy_host_mount_forbidden"
	CodeLabelRequired       = "policy_label_required"
	CodeReplicasExceeded    = "policy_replicas_exceeded"
	CodeLatestTag           = "policy_latest_tag_forbidden"
	CodeDigestRequired      = "policy_image_digest_required"
	CodeLimitsRequired      = "policy_resource_limits_required"
	CodeSignatureRequired   = "policy_image_signature_required"
	CodeSignatureUnverified = "policy_image_signature_unverifiable"
	// CodeViolation is the response code of a blocked deploy.
	CodeViolation = "policy_violation"
)

Stable machine readable violation codes.

View Source
const (
	SigVerified     = "verified"
	SigUnsigned     = "unsigned"
	SigInvalid      = "invalid"
	SigUntrusted    = "untrusted"
	SigUnverifiable = "unverifiable"
)

Signature verdict statuses.

View Source
const (
	ReasonNotChecked          = "not_checked"
	ReasonNoTrustedSigners    = "no_trusted_signers"
	ReasonNotPinned           = "image_not_pinned_by_digest"
	ReasonRegistryUnreachable = "registry_unreachable"
	ReasonTrustRootMissing    = "trust_root_unavailable"
	ReasonTimeout             = "verification_timed_out"
	ReasonNoSignature         = "no_signature"
	ReasonBadSignature        = "signature_invalid"
	ReasonSignerNotTrusted    = "signer_not_trusted"
)

Typed reasons a signature could not be verified or was refused.

Variables

This section is empty.

Functions

func CheckSignerItem

func CheckSignerItem(item string) error

CheckSignerItem validates one trusted signer list entry on write.

func RegistryOf

func RegistryOf(image string) string

RegistryOf returns the registry host an image reference pulls from.

func RuleIDs

func RuleIDs() []string

RuleIDs lists every known rule in display order.

func Validate

func Validate(s Set) error

Validate rejects unknown rules, modes, and rules missing what they need.

Types

type Mode

type Mode string

Mode is how a rule reacts: off ignores it, warn reports it, enforce blocks.

const (
	ModeOff     Mode = "off"
	ModeWarn    Mode = "warn"
	ModeEnforce Mode = "enforce"
)

Rule modes.

type Rule

type Rule struct {
	Mode   Mode     `json:"mode"`
	Values []string `json:"values,omitempty"`
	Limit  float64  `json:"limit,omitempty"`
}

Rule is one guardrail. Values carries list rules (registries, labels, allowed host path prefixes); Limit carries numeric ceilings.

type Set

type Set map[string]Rule

Set maps a rule id to its rule.

func Merge

func Merge(layers ...Set) Set

Merge layers rule sets from least to most specific; a later layer's rule replaces an earlier one with the same id, so an environment can relax or tighten what the organization set.

type SignatureVerdict

type SignatureVerdict struct {
	Status string `json:"status"`
	Reason string `json:"reason,omitempty"`
	Signer string `json:"signer,omitempty"`
	Digest string `json:"digest,omitempty"`
}

SignatureVerdict is what verifying an image against the trusted signer list found. Signer names who signed when Status is verified.

type Signer

type Signer struct {
	Key         *ecdsa.PublicKey
	Fingerprint string
	Issuer      string
	Identity    string
}

Signer is one entry of the trusted signer list: a public key, or a keyless identity pinned to its OIDC issuer. Both parts of a keyless signer are matched exactly, never by pattern.

func ParseSigner

func ParseSigner(item string) (Signer, error)

ParseSigner reads "key:<base64 PKIX DER ECDSA key>" or "keyless:<issuer url>|<identity>".

func ParseSigners

func ParseSigners(items []string) ([]Signer, error)

ParseSigners parses a list, skipping nothing: one bad entry fails the whole list so a typo cannot silently shrink what is trusted.

func (Signer) Label

func (s Signer) Label() string

Label is the stable name of the signer used in verdicts and audit rows.

type Subject

type Subject struct {
	Image        string
	MemoryBytes  int64
	NanoCPUs     int64
	HasReadiness bool
	Privileged   bool
	HostMounts   []string
	Labels       map[string]string
	Replicas     int
	// Signature is the image signature verdict. Nil means no check ran, which
	// the signature rule treats as unverifiable rather than as a pass.
	Signature *SignatureVerdict
}

Subject is the deploy being judged. Zero MemoryBytes or NanoCPUs mean no limit is set, which a ceiling treats as exceeding it.

type Violation

type Violation struct {
	Rule       string `json:"rule"`
	Code       string `json:"code"`
	Mode       Mode   `json:"mode"`
	Message    string `json:"message"`
	NextAction string `json:"next_action"`
}

Violation is one rule a subject breaks, with a stable code and the next action for a human.

func Blocking

func Blocking(vs []Violation) []Violation

Blocking returns the violations that stop a deploy.

func Evaluate

func Evaluate(s Set, subj Subject) []Violation

Evaluate returns every violation of s by subj, in rule display order.

func (Violation) Blocks

func (v Violation) Blocks() bool

Blocks reports whether this violation stops a deploy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL