Documentation
¶
Index ¶
- Constants
- Variables
- func PolicyOrSet(set *api.PolicySet, pcy *api.Policy) any
- func PolicyOrSetOrGroup(set *api.PolicySet, pcy *api.Policy, grp *api.PolicyGroup) any
- type Compiler
- func (compiler *Compiler) Compile(data []byte, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, *api.PolicyGroup, error)
- func (compiler *Compiler) CompileFile(path string, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, *api.PolicyGroup, error)
- func (compiler *Compiler) CompileLocation(location string, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, *api.PolicyGroup, error)
- func (compiler *Compiler) CompilePolicy(p *api.Policy, funcs ...options.OptFn) (*api.Policy, error)
- func (compiler *Compiler) CompilePolicyGroup(grp *api.PolicyGroup, funcs ...options.OptFn) (*api.PolicyGroup, error)
- func (compiler *Compiler) CompileRemote(uri string, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, *api.PolicyGroup, error)
- func (compiler *Compiler) CompileSet(set *api.PolicySet, funcs ...options.OptFn) (*api.PolicySet, error)
- func (compiler *Compiler) CompileVerify(data []byte, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, grp *api.PolicyGroup, ...)
- func (compiler *Compiler) CompileVerifyFile(path string, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, *api.PolicyGroup, attestation.Verification, error)
- func (compiler *Compiler) CompileVerifyLocation(location string, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, grp *api.PolicyGroup, ...)
- func (compiler *Compiler) CompileVerifyRemote(uri string, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, grp *api.PolicyGroup, ...)
- type CompilerOptions
- type Fetcher
- func (gf *Fetcher) Get(uri string) ([]byte, error)
- func (gf *Fetcher) GetFromGit(locator string) ([]byte, error)
- func (gf *Fetcher) GetFromHTTP(url string) ([]byte, error)
- func (gf *Fetcher) GetGroup(uris []string) ([][]byte, error)
- func (gf *Fetcher) GetGroupBatched(uris []string, batchSize int) ([][]byte, error)
- type Parser
- func (p *Parser) Open(location string, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, *api.PolicyGroup, error)
- func (p *Parser) OpenVerify(location string, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, grp *api.PolicyGroup, ...)
- func (p *Parser) ParsePolicy(data []byte, funcs ...options.OptFn) (*api.Policy, error)
- func (p *Parser) ParsePolicyFile(path string, funcs ...options.OptFn) (*api.Policy, error)
- func (p *Parser) ParsePolicyGroup(policyGroupData []byte, funcs ...options.OptFn) (*api.PolicyGroup, error)
- func (p *Parser) ParsePolicyGroupFile(path string, funcs ...options.OptFn) (*api.PolicyGroup, error)
- func (p *Parser) ParsePolicyOrSet(data []byte, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, error)
- func (p *Parser) ParsePolicySet(policySetData []byte, funcs ...options.OptFn) (*api.PolicySet, error)
- func (p *Parser) ParsePolicySetFile(path string, funcs ...options.OptFn) (*api.PolicySet, error)
- func (p *Parser) ParseVerifyPolicy(data []byte, funcs ...options.OptFn) (*api.Policy, attestation.Verification, error)
- func (p *Parser) ParseVerifyPolicyGroup(policyGroupData []byte, funcs ...options.OptFn) (*api.PolicyGroup, attestation.Verification, error)
- func (p *Parser) ParseVerifyPolicyOrSet(data []byte, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, v attestation.Verification, err error)
- func (p *Parser) ParseVerifyPolicyOrSetOrGroup(data []byte, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, grp *api.PolicyGroup, ...)
- func (p *Parser) ParseVerifyPolicySet(policySetData []byte, funcs ...options.OptFn) (*api.PolicySet, attestation.Verification, error)
- type PolicyFetcher
- type RefUpdate
- type Signer
- type StorageBackend
- type Updater
Constants ¶
const ( AssertModeAND = "AND" AssertModeOR = "OR" EnforceOn = "ON" EnforceOff = "OFF" )
Variables ¶
var ErrParseInconsistency = errors.New("internal error: fetched reference ID and policy ID mismatch")
This error is thrown if a fetchedRef lists a policy ID not contained in its policy or policy set. If it's ever thrown it is definitely a bug:
var ErrUnsupportedLocationURI = errors.New("unsupported policy location")
Functions ¶
func PolicyOrSet ¶
PolicyOrSet takes a policy or policyset and returns the one that is not nill
func PolicyOrSetOrGroup ¶ added in v0.4.0
PolicyOrSet takes a policy or policyset and returns the one that is not nill
Types ¶
type Compiler ¶
type Compiler struct {
Options CompilerOptions
Store StorageBackend
// contains filtered or unexported fields
}
Compiler is the policy compiler
func NewCompiler ¶
func NewCompiler() *Compiler
func (*Compiler) Compile ¶
func (compiler *Compiler) Compile(data []byte, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, *api.PolicyGroup, error)
CompileVerify compiles a policy, while verifying its signature
func (*Compiler) CompileFile ¶
func (compiler *Compiler) CompileFile(path string, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, *api.PolicyGroup, error)
CompileFile reads data from a local file and returns either a policy set or policy.
func (*Compiler) CompileLocation ¶
func (*Compiler) CompilePolicy ¶
Compile builds a policy set fetching any remote pieces as necessary
func (*Compiler) CompilePolicyGroup ¶ added in v0.4.0
func (compiler *Compiler) CompilePolicyGroup(grp *api.PolicyGroup, funcs ...options.OptFn) (*api.PolicyGroup, error)
Compile builds a policy set fetching any remote pieces as necessary
func (*Compiler) CompileRemote ¶
func (compiler *Compiler) CompileRemote(uri string, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, *api.PolicyGroup, error)
CompileRemote reads a policy or policy set from a remote location. The location URI can be a git VCS locator using HTTPS or SSH as transport or an HTTPS URL.
func (*Compiler) CompileSet ¶
func (compiler *Compiler) CompileSet(set *api.PolicySet, funcs ...options.OptFn) (*api.PolicySet, error)
Compile builds a policy set fetching any remote pieces as necessary
func (*Compiler) CompileVerify ¶ added in v0.2.0
func (compiler *Compiler) CompileVerify(data []byte, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, grp *api.PolicyGroup, ver attestation.Verification, err error)
CompileVerify is the main method to assemble policies and groups.
Compiling means fetching all the policy references and assembling a policy in memory from the fetched data.
func (*Compiler) CompileVerifyFile ¶ added in v0.2.0
func (compiler *Compiler) CompileVerifyFile(path string, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, *api.PolicyGroup, attestation.Verification, error)
CompileFile reads data from a local file and returns either a policy set or policy.
func (*Compiler) CompileVerifyLocation ¶ added in v0.2.0
func (compiler *Compiler) CompileVerifyLocation(location string, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, grp *api.PolicyGroup, ver attestation.Verification, err error)
CompileLocaCompileVerifyLocationtion takes a location string and parses a policy or PolicySet as read from it. The location will be tested, if it is a URL or VCS locator, it will be retrieved remotely. If its a local file, it will be read from disk. Anything else throws an error.
This function variant returns the signature verification.
func (*Compiler) CompileVerifyRemote ¶ added in v0.2.0
func (compiler *Compiler) CompileVerifyRemote(uri string, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, grp *api.PolicyGroup, ver attestation.Verification, err error)
CompileRemote reads a policy or policy set from a remote location. The location URI can be a git VCS locator using HTTPS or SSH as transport or an HTTPS URL.
type CompilerOptions ¶
type CompilerOptions struct {
// MaxRemoteRecursion captures the maximum recursion level the
// compiler will do to fetch remote content. Note that this setting
// causes exponential requests, so be careful when defining a value.
MaxRemoteRecursion int
// MaxParallelFetches limits the number of concurrent remote fetches.
// Default: 50
MaxParallelFetches int
// MaxTotalFetches limits the total number of remote fetches during compilation.
// This prevents exponential expansion attacks.
// Default: 100
MaxTotalFetches int
}
CompilerOptions are the settings of the compiler itself.
type Fetcher ¶
Fetcher is the ampel policy fetcher. It optimizes retrieval of policy data from repositories and source control systems.
func NewFetcher ¶
func NewFetcher() *Fetcher
func NewFetcherWithLimits ¶ added in v0.4.2
NewFetcherWithLimits creates a new Fetcher with the specified limits.
func (*Fetcher) GetFromGit ¶
GetFromGit gets data from a git repository at the specified revision with size limits.
func (*Fetcher) GetFromHTTP ¶
GetFromHTTP retrieves data from an http endpoint with size limits.
func (*Fetcher) GetGroup ¶
GetGroup fetches a list of uris that can be HTTP(S) URLs or SPDX VCS locators. The functions uses the vcslocator module and the k8s http agent to fetch in parallel. The returned slice if byte-slices is guarranteed to preserve the URL order. If a request fails, this function returns a single error and discards all data.
Retries are currently not supported but will probably be at a later point once the VCS locator module supports retrying.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser implements methods to read the policy and policy set json files. Note that the parser only deals with decoding json. Use the policy compiler to assemble policies with external/remote references.
func (*Parser) Open ¶
func (p *Parser) Open(location string, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, *api.PolicyGroup, error)
Open opens a Policy or policySet. This function supports remote locations (https URLs or VCS locators) and will eventually verify signatures after reading and parsing data (still under construction).
func (*Parser) OpenVerify ¶ added in v0.2.0
func (p *Parser) OpenVerify(location string, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, grp *api.PolicyGroup, v attestation.Verification, err error)
Open opens a Policy or policySet. This function supports remote locations (https URLs or VCS locators) and will eventually verify signatures after reading and parsing data (still under construction).
func (*Parser) ParsePolicy ¶
ParsePolicy parses a policy from its JSON representation or an envelope
func (*Parser) ParsePolicyFile ¶
ParsePolicyFile parses a policy from a file
func (*Parser) ParsePolicyGroup ¶ added in v0.4.0
func (p *Parser) ParsePolicyGroup(policyGroupData []byte, funcs ...options.OptFn) (*api.PolicyGroup, error)
ParseSet parses a policy set.
func (*Parser) ParsePolicyGroupFile ¶ added in v0.4.0
func (p *Parser) ParsePolicyGroupFile(path string, funcs ...options.OptFn) (*api.PolicyGroup, error)
ParsePolicyGroupFile parses a policy group from a file
func (*Parser) ParsePolicyOrSet ¶
func (p *Parser) ParsePolicyOrSet(data []byte, funcs ...options.OptFn) (*api.PolicySet, *api.Policy, error)
ParsePolicyOrSet takes json data and tries to parse a policy or a policy set out of it. Returns an error if the JSON data is none.
func (*Parser) ParsePolicySet ¶
func (p *Parser) ParsePolicySet(policySetData []byte, funcs ...options.OptFn) (*api.PolicySet, error)
ParseSet parses a policy set.
func (*Parser) ParsePolicySetFile ¶
ParseFile parses a policySet from a file
func (*Parser) ParseVerifyPolicy ¶ added in v0.2.0
func (p *Parser) ParseVerifyPolicy(data []byte, funcs ...options.OptFn) (*api.Policy, attestation.Verification, error)
ParsePolicy parses a policy from its JSON representation or an envelope
func (*Parser) ParseVerifyPolicyGroup ¶ added in v0.4.0
func (p *Parser) ParseVerifyPolicyGroup(policyGroupData []byte, funcs ...options.OptFn) (*api.PolicyGroup, attestation.Verification, error)
ParseSet parses a policy set.
func (*Parser) ParseVerifyPolicyOrSet ¶ added in v0.2.0
func (p *Parser) ParseVerifyPolicyOrSet(data []byte, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, v attestation.Verification, err error)
deprecated
func (*Parser) ParseVerifyPolicyOrSetOrGroup ¶ added in v0.4.0
func (p *Parser) ParseVerifyPolicyOrSetOrGroup(data []byte, funcs ...options.OptFn) (set *api.PolicySet, pcy *api.Policy, grp *api.PolicyGroup, v attestation.Verification, err error)
ParseVerifyPolicyOrSet parses a policy and verifies the signatures. It returns a PolicySet or Policy and the signature verification results object.
func (*Parser) ParseVerifyPolicySet ¶ added in v0.2.0
func (p *Parser) ParseVerifyPolicySet(policySetData []byte, funcs ...options.OptFn) (*api.PolicySet, attestation.Verification, error)
ParseSet parses a policy set.
type PolicyFetcher ¶
type RefUpdate ¶ added in v0.4.6
RefUpdate describes one external reference whose upstream content has changed. Old is the reference as it appears in the policy source; New is a ref pointing at the new commit with refreshed digests.
type Signer ¶
type Signer struct {
Options options.SignerOptions
}
Signer is the policy/policy set signer object. Signing is done by wrapping the policies in an in-toto statement and the predicate/* wrappers before passing them to the sigstore signer.
func NewSigner ¶
func NewSigner(funcs ...options.SignerOptFn) *Signer
NewSigner returns a policy signer with the specified options
func (*Signer) SignPolicyData ¶
SignPolicyData signs raw policy data
func (*Signer) SignPolicyFile ¶
SignBundleToFile signs a policy file and writes it to a filename derived from the original.
type StorageBackend ¶
type StorageBackend interface {
StoreReference(api.RemoteReference) error
StoreReferenceWithReturn(api.RemoteReference) (*api.PolicySet, *api.Policy, *api.PolicyGroup, error)
GetReferencedPolicy(api.RemoteReference) (*api.Policy, error)
GetReferencedGroup(api.RemoteReference) (*api.PolicyGroup, error)
}
Storage backend is an interface that fronts systems that store and index policies
type Updater ¶ added in v0.4.6
type Updater struct {
// MaxParallel caps concurrent remote operations. Defaults to 4.
MaxParallel int
}
Updater checks policy source files for references that have updates available in their upstream repositories.
func NewUpdater ¶ added in v0.4.6
func NewUpdater() *Updater
NewUpdater returns a new Updater with sane defaults.
func (*Updater) ApplyUpdates ¶ added in v0.4.6
ApplyUpdates patches each file in the given updates map in place, using the same backend as Update. This is the method to call when the updates were computed elsewhere (e.g. loaded from a previously-saved plan) and only the filesystem patch step needs to run. Returns the subset of updates that were actually applied (i.e. whose old values were present in their source file).
func (*Updater) CheckUpdates ¶ added in v0.4.6
CheckUpdates resolves each location (a policy file, a directory, or a VCS locator) into a set of policy source files, extracts their external references and checks each referenced repository for updates. The returned map is keyed by source file path and lists the references that need to be updated.
func (*Updater) Update ¶ added in v0.4.6
Update checks the given locations for available reference updates and patches the matching policy source files in place. Only filesystem locations (files or directories) are patched; VCS-locator locations are skipped because their resolved files live in a temporary clone. The returned map lists the updates that were actually applied, keyed by source file path.