policy

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package policy provides helper functions for creating BuildKit source policies. It wraps the official github.com/moby/buildkit/sourcepolicy/pb types.

Index

Constants

View Source
const (
	PolicyActionAllow   = spb.PolicyAction_ALLOW
	PolicyActionDeny    = spb.PolicyAction_DENY
	PolicyActionConvert = spb.PolicyAction_CONVERT

	MatchTypeWildcard = spb.MatchType_WILDCARD
	MatchTypeExact    = spb.MatchType_EXACT
	MatchTypeRegex    = spb.MatchType_REGEX

	AttrMatchEqual    = spb.AttrMatch_EQUAL
	AttrMatchNotEqual = spb.AttrMatch_NOTEQUAL
	AttrMatchMatches  = spb.AttrMatch_MATCHES
)

Re-export constants

Variables

This section is empty.

Functions

func AddGitChecksumRule

func AddGitChecksumRule(p *Policy, gitURL, checksum string)

AddGitChecksumRule adds a rule that pins a Git source to a specific commit checksum The gitURL should be the original URL as it appears in the Dockerfile (e.g., https://github.com/owner/repo.git#ref) The checksum should be the full 40-character commit SHA

func AddHTTPChecksumRule

func AddHTTPChecksumRule(p *Policy, url, checksum string)

AddHTTPChecksumRule adds a rule that pins an HTTP/HTTPS source to a specific checksum The checksum should be in the format "sha256:..." or similar digest format

func AddHTTPChecksumRuleWithHeaders

func AddHTTPChecksumRuleWithHeaders(p *Policy, url, checksum string, headers map[string]string)

AddHTTPChecksumRuleWithHeaders adds a rule that pins an HTTP/HTTPS source to a specific checksum and optionally includes HTTP headers in the source policy.

Headers are stored with the "http.header." prefix as defined by BuildKit's AttrHTTPHeaderPrefix. This is important for resources that vary by request headers (indicated by the Vary response header).

Example: If a resource varies by Accept-Encoding, the headers map should contain:

{"accept-encoding": "gzip, deflate"}

This will be stored in the policy as "http.header.accept-encoding" attribute.

func AddPinRule

func AddPinRule(p *Policy, originalRef, pinnedRef string)

AddPinRule adds a rule that pins an image reference to a specific digest

func Validate

func Validate(p *Policy) error

Validate checks that the policy is valid by performing a JSON round-trip through the BuildKit sourcepolicy/pb types. This is the same validation that BuildKit performs when loading a policy file via json.Unmarshal.

func ValidateWithEvaluate

func ValidateWithEvaluate(ctx context.Context, p *Policy) error

ValidateWithEvaluate performs deeper validation by running each rule through BuildKit's sourcepolicy engine. This tests that the generated rules can actually be evaluated against source operations, providing runtime validation beyond structural correctness.

Types

type AttrConstraint

type AttrConstraint = spb.AttrConstraint

Re-export types from buildkit sourcepolicy/pb for convenience

type AttrMatch

type AttrMatch = spb.AttrMatch

Re-export types from buildkit sourcepolicy/pb for convenience

type MatchType

type MatchType = spb.MatchType

Re-export types from buildkit sourcepolicy/pb for convenience

type Policy

type Policy = spb.Policy

Re-export types from buildkit sourcepolicy/pb for convenience

func NewPolicy

func NewPolicy() *Policy

NewPolicy creates a new policy with the default version

type PolicyAction

type PolicyAction = spb.PolicyAction

Re-export types from buildkit sourcepolicy/pb for convenience

type Rule

type Rule = spb.Rule

Re-export types from buildkit sourcepolicy/pb for convenience

type Selector

type Selector = spb.Selector

Re-export types from buildkit sourcepolicy/pb for convenience

type Update

type Update = spb.Update

Re-export types from buildkit sourcepolicy/pb for convenience

Jump to

Keyboard shortcuts

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