collector

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: Apache-2.0 Imports: 19 Imported by: 3

README

Carabiner Attestation Collector and Parsers

This repository contains the carabiner attestation collector and various parsers for envelopes, statment types (well, only in-toto is upported ATM!) and predicates.

The two main consumers of this repository are 🔴🟡🟢 AMPEL and 🥨 bnd but any project that needs to download, read and query attestations can benefit from this module.

This project handles attestations using an abstraction above the vanilla intoto attestations by relying on the Carabiner Attestation Framework.

Concepts

We often talk about The Collector but this is a very broad term.

In reality, all interactions are done using The Agent, an object that coordinates reading and writing attestation data from Repositories through collectors that know how to talk to them:

flowchart LR
    A[Agent] <-->|Fetch Call| B(Call Multiplex)
    B <--> C1[Collector A]
    B <--> C2[Collector B]
    B <--> C3[Collector C]
    C1 <-->|HTTP| D1(HTTP Repository)
    C2 <-->|Filesystem| D2(Directory)
    C3 <-->|API| D3(Other Backend)

Definitions

Here are some definitions about each component. Most code definitions of the following concepts are in interfaces in the Carabiner Attestations Framework, most definitions can be found in repository.go.

Repository

A Repository is a data source to read or write attestations. Repositories range in complexity from a file (eg a jsonl file) all the way to a full system backed by a database.

Repositories can vary in their capabilities, for example a repository may only serve but not store attestations. Repositories can also implement more specialized behaviors, for example may expose querying capabilities to fetch attestations by predicate type or subject digest.

To talk to a repository, a collector driver needs to be implemented (see below).

Collector Agent

The agent exposes the public API for attestation storage and retrieval. To read and write data, an agent is configured with collectors that know how to retrieve data from a specific repository.

Collector Driver

A collector driver (or simply a collector), is a short program that implements the attestation.Fetch (or Store) interface.

Collectors capture the logic to talk to a specific, instantiated repository type. This means an agent loads a configured collector driver to communicate with an instance of a repository type. For example, to read data from two jsonl files, the agent loads two collectors for each driver.

Collectors can expose more advanced capabilities of a backend, for example if a collector implementes the attestation.FetcherByPredicateType interface, the agent will use it to fetch by predicate type instead of pulling data and then filtering it in memory.

Attestation Queries

An Attestation Query subsets a group of Envelopes by applying a series of filters. To run one, a program configures an attestation.Query object by loading a number of filters and then Runs it on slice of attestations.

Here is a short example that filters a group of envelopes (wrapped attestations) by looking for predicate types and digests:


    attestations := []attestation.Envelope{}

    // .... load here the attestations variable ...

    // Create a new query:
    query := attestation.NewQuery().WithFilter(
            // add a filter that looks for OpenVEX attestations:
			&filters.PredicateTypeMatcher{
				PredicateTypes: map[attestation.PredicateType]struct{}{
					attestation.PredicateType("https://openvex.dev/ns/v0.2.0"): struct{}{},
				},

            // add a filter that looks for a specific subject:
			}).WithFilter(
			&filters.SubjectHashMatcher{
				HashSets: []map[string]string{
					{"sha256": "2775bba8b2170bef2f91b79d4f179fd87724ffee32b4a20b8304856fd3bf4b8f"},
				},
			},
	)

    // Run the query:
    attestations = query.Run(attestations)

This project is Copyright © by Carabiner Systems and released under the Apache-2.0 license, meaning you can use it and contribute back ideas and patches. If you use the collector, be sure to let us know!!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoFetcherConfigured = errors.New("no repository with fetch capabilities configured")
	ErrNoStorerConfigured  = errors.New("no repository with store capabilities configured")
)
View Source
var (
	ErrTypeAlreadyRegistered = errors.New("collector type already registered")
)

Functions

func LoadDefaultRepositoryTypes

func LoadDefaultRepositoryTypes() error

LoadDefaultRepositoryTypes loads the default repository types into the in-memory list to get them ready for instantiation.

func RegisterCollectorType

func RegisterCollectorType(moniker string, factory RepositoryFactory) error

RegisterCollectorType registers a new type of collector

func RepositoryFromString

func RepositoryFromString(init string) (attestation.Repository, error)

func UnregisterCollectorType

func UnregisterCollectorType(moniker string)

RegisterCollectorType registers a new type of collector

Types

type Agent

type Agent struct {
	Options      Options
	Cache        Cache
	Repositories []attestation.Repository
}

Agent is the attestations collector agent. The agent registers a number of repositories and can look for attestations in them.

The agent exposes the attestation.Fetcher and attestation.Storer methods, when called, the collector agent invokes the corresponding method in all configured repository drivers.

func New

func New(funcs ...InitFunction) (*Agent, error)

New returns a new agent with the default options

func NewWithOptions

func NewWithOptions(opts *Options) *Agent

NewWithOptions returns a new agent configured with a specific options set

func (*Agent) AddRepository

func (agent *Agent) AddRepository(repos ...attestation.Repository) error

AddRepsitory adds a new repository to collect attestations

func (*Agent) AddRepositoryFromString

func (agent *Agent) AddRepositoryFromString(init string) error

func (*Agent) Fetch

func (agent *Agent) Fetch(ctx context.Context, optFn ...FetchOptionsFunc) ([]attestation.Envelope, error)

Fetch is a general attestation fetcher. It is intended to return attestations in the preferred order of the driver without any optimization whatsoever.

func (*Agent) FetchAttestationsByPredicateType

func (agent *Agent) FetchAttestationsByPredicateType(ctx context.Context, pt []attestation.PredicateType, optFn ...FetchOptionsFunc) ([]attestation.Envelope, error)

FetchAttestationsByPredicateType requests all attestations of a particular type from the configured repositories.

func (*Agent) FetchAttestationsBySubject

func (agent *Agent) FetchAttestationsBySubject(ctx context.Context, subjects []attestation.Subject, optFn ...FetchOptionsFunc) ([]attestation.Envelope, error)

FetchAttestationsBySubject requests all attestations about a list of subjects from the configured repositories. It is understood that the repos will return all attestations available about the specified subjects.

type Cache

type Cache interface {
	StoreAttestationsByPredicateType(context.Context, []attestation.PredicateType, *[]attestation.Envelope) error
	GetAttestationsByPredicateType(context.Context, []attestation.PredicateType) (*[]attestation.Envelope, error)
	StoreAttestationsBySubject(context.Context, []attestation.Subject, *[]attestation.Envelope) error
	GetAttestationsBySubject(context.Context, []attestation.Subject) (*[]attestation.Envelope, error)
}

type FetchOptionsFunc

type FetchOptionsFunc func(*attestation.FetchOptions)

FetchOptionsFunc are functions to define options when fetching

func WithLimit added in v0.1.2

func WithLimit(n int) FetchOptionsFunc

WithLimit sets the maximum number of attestations to be returned by the agent

func WithQuery

func WithQuery(q *attestation.Query) FetchOptionsFunc

WithQuery passes a query to the options set

type InitFunction

type InitFunction func(*Agent) error

func WithParallelFetches

func WithParallelFetches(threads int) InitFunction

func WithParallelStores

func WithParallelStores(threads int) InitFunction

func WithRepository

func WithRepository(repo attestation.Repository) InitFunction

type MemoryCache

type MemoryCache struct {
	// contains filtered or unexported fields
}

func NewMemoryCache

func NewMemoryCache() *MemoryCache

func (*MemoryCache) GetAttestationsByPredicateType

func (memcache *MemoryCache) GetAttestationsByPredicateType(ctx context.Context, pt []attestation.PredicateType) (*[]attestation.Envelope, error)

func (*MemoryCache) GetAttestationsBySubject

func (memcache *MemoryCache) GetAttestationsBySubject(ctx context.Context, subjects []attestation.Subject) (*[]attestation.Envelope, error)

func (*MemoryCache) StoreAttestationsByPredicateType

func (memcache *MemoryCache) StoreAttestationsByPredicateType(ctx context.Context, pt []attestation.PredicateType, atts *[]attestation.Envelope) error

func (*MemoryCache) StoreAttestationsBySubject

func (memcache *MemoryCache) StoreAttestationsBySubject(ctx context.Context, subjects []attestation.Subject, atts *[]attestation.Envelope) error

type Options

type Options struct {
	UserAgentString string

	// FailIfNoFetchers Return an error when fetching if no repos are configured (instead of just nil)
	FailIfNoFetchers bool

	// Use cache controls if the agent uses the attestation cache
	UseCache bool

	ParallelFetches int
	ParallelStores  int
	Fetch           attestation.FetchOptions
	Store           attestation.StoreOptions
}

Options groups the configuration knob for the collector agent

type RepositoryFactory

type RepositoryFactory func(string) (attestation.Repository, error)

type StoreOptionsFunc

type StoreOptionsFunc func(*attestation.StoreOptions)

StoreOptionsFunc are functions to define options when fetching

Directories

Path Synopsis
bare
Package bare implenta a parser to make non-signed attestations compatible with the ampel policy engine.
Package bare implenta a parser to make non-signed attestations compatible with the ampel policy engine.
bundle
Packager bundle provides functionality to work with the sigstore budle format
Packager bundle provides functionality to work with the sigstore budle format
generic
Package generic is a generic predicate that can be used as a wrapper for most predicate payloads
Package generic is a generic predicate that can be used as a wrapper for most predicate payloads
osv
vsa
repository
filesystem
Package filesystem implements an attestation collector from a fs.FS
Package filesystem implements an attestation collector from a fs.FS
git
Package git implements an attestations collector that works on a git repository.
Package git implements an attestations collector that works on a git repository.
github
Package github implements a collector that reads from the GitHub attestations store.
Package github implements a collector that reads from the GitHub attestations store.
http
Package http implements an attestations collector that reads data from an https endpoint.
Package http implements an attestations collector that reads data from an https endpoint.
jsonl
Package jsonl implements an attestations collector that reads from files using the JSON Lines (jsonl) format.
Package jsonl implements an attestations collector that reads from files using the JSON Lines (jsonl) format.
note
Package note implements an attestation fetcher that can read from git commit notes.
Package note implements an attestation fetcher that can read from git commit notes.
ossrebuild
Package http implements an attestations collector that reads data from an https endpoint.
Package http implements an attestations collector that reads data from an https endpoint.
intoto
Package intoto implements a parser and a statement variant for attestations in the in-toto format.
Package intoto implements a parser and a statement variant for attestations in the in-toto format.

Jump to

Keyboard shortcuts

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