Documentation
¶
Index ¶
- Constants
- Variables
- func PolicyOrSet(set *api.PolicySet, pcy *api.Policy) any
- type Compiler
- func (compiler *Compiler) Compile(data []byte) (set *api.PolicySet, pcy *api.Policy, err error)
- func (compiler *Compiler) CompileFile(path string) (set *api.PolicySet, pcy *api.Policy, err error)
- func (compiler *Compiler) CompileLocation(location string) (set *api.PolicySet, pcy *api.Policy, err error)
- func (compiler *Compiler) CompilePolicy(p *api.Policy) (*api.Policy, error)
- func (compiler *Compiler) CompileRemote(uri string) (set *api.PolicySet, pcy *api.Policy, err error)
- func (compiler *Compiler) CompileSet(set *api.PolicySet) (*api.PolicySet, error)
- type CompilerOptions
- type Fetcher
- type Parser
- func (p *Parser) Open(location string) (set *api.PolicySet, pcy *api.Policy, err error)
- func (p *Parser) ParsePolicy(data []byte) (*api.Policy, error)
- func (p *Parser) ParsePolicyFile(path string) (*api.Policy, error)
- func (p *Parser) ParsePolicyOrSet(data []byte) (set *api.PolicySet, pcy *api.Policy, err error)
- func (p *Parser) ParsePolicySet(policySetData []byte) (*api.PolicySet, error)
- func (p *Parser) ParsePolicySetFile(path string) (*api.PolicySet, error)
- type PolicyFetcher
- type Signer
- type StorageBackend
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 ¶
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 ¶
Compile is the main method to assemble policies.
Compiling means fetching all the policy references and assembling a policy in memory from the fetched data.
func (*Compiler) CompileFile ¶
CompileFile reads data from a local file and returns either a policy set or policy
func (*Compiler) CompileLocation ¶
func (compiler *Compiler) CompileLocation(location string) (set *api.PolicySet, pcy *api.Policy, err error)
CompileLocation takes a location string and parses a policy or policy set 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.
func (*Compiler) CompilePolicy ¶
Compile builds a policy set fetching any remote pieces as necessary
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
}
type Fetcher ¶
type Fetcher struct{}
Fetcher is the ampel policy fetcher. It optimizes retrieval of policy data from repositories and source control systems.
func NewFetcher ¶
func NewFetcher() *Fetcher
func (*Fetcher) GetFromGit ¶
GetFromGit gets data from a git repository at the specified revision
func (*Fetcher) GetFromHTTP ¶
GetFromHTTP retrieves data from an http endpoint
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 ¶
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 file
func (*Parser) ParsePolicyFile ¶
ParsePolicyFile parses a policy from a file
func (*Parser) ParsePolicyOrSet ¶
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 ¶
ParseSet parses a policy set.
type PolicyFetcher ¶
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.PolicyRef) error
StoreReferenceWithReturn(*api.PolicyRef) (*api.PolicySet, *api.Policy, error)
GetReferencedPolicy(*api.PolicyRef) (*api.Policy, error)
}
Storage backend is an interface that fronts systems that store and index policies