Documentation
¶
Index ¶
- Constants
- Variables
- func AcceptSingleArchiveEntry(_, wanted string, candidates []string) (string, error)
- func CommunityPolicyPath(org, repo string) string
- func DefaultPolicyRepository(host, org string) string
- func OrgPolicyPath() string
- func PolicyPath(repo string) string
- func PolicyPaths(repo string) []string
- func PolicyPathsLabel(repo string) string
- type ArchiveEntrySelector
- type ArtifactKind
- type ArtifactSelector
- type Dropper
- func (dropper *Dropper) CheckUpdates(refs ...string) ([]*UpdateStatus, error)
- func (dropper *Dropper) FindInstalled(ref string) ([]*inventory.Record, error)
- func (dropper *Dropper) Get(spec github.AssetDataProvider, funcs ...FuncGetOption) error
- func (dropper *Dropper) Install(spec github.AssetDataProvider, funcs ...FuncGetOption) error
- func (dropper *Dropper) ListInstalled() ([]*inventory.Record, error)
- func (dropper *Dropper) Remove(record *inventory.Record, funcs ...FuncGetOption) error
- func (dropper *Dropper) Update(status *UpdateStatus, funcs ...FuncGetOption) error
- type Event
- type FuncGetOption
- func WithArchiveEntry(entryPath string) FuncGetOption
- func WithArchiveEntrySelector(fn ArchiveEntrySelector) FuncGetOption
- func WithArtifactSelector(fn ArtifactSelector) FuncGetOption
- func WithAttestationPath(path string) FuncGetOption
- func WithBinDir(dir string) FuncGetOption
- func WithDownloadPath(path string) FuncGetOption
- func WithDownloadType(t string) FuncGetOption
- func WithPlatform(slug string) FuncGetOption
- func WithReinstall(reinstall bool) FuncGetOption
- func WithRequiredArchiveEntry(entryPath string) FuncGetOption
- func WithTransferTimeOut(seconds int) FuncGetOption
- func WithVerifyDownloads(verify bool) FuncGetOption
- func WithVerifyWhenPossible(when bool) FuncGetOption
- type FuncOption
- type GetOptions
- type InstallArtifact
- type KeptVerification
- type NoopListener
- type Options
- type PolicyRequest
- type ProgressListener
- type UpdateStatus
Constants ¶
const ( ContextHost = "drop_host" // GitHub host, e.g. github.com ContextOrg = "drop_org" // repository owner ContextRepo = "drop_repo" // repository name ContextRepository = "drop_repository" // repository URL ContextTag = "drop_tag" // release tag as published, e.g. v1.2.3 ContextVersion = "drop_version" // release tag without the leading v, e.g. 1.2.3 ContextAsset = "drop_asset" // name of the release asset being verified ContextOS = "drop_os" // operating system of the asset, when known ContextArch = "drop_arch" // architecture of the asset, when known )
Context values drop exposes to policies about the artifact under verification. Policies declare the ones they use in their context block.
const ( EventObjectArchive = "archive" EventObjectAsset = "asset" EventObjectAttestation = "attestation" EventObjectInstall = "install" EventObjectPolicy = "policy" EventObjectRemove = "remove" EventObjectVerification = "verification" EventVerbDone = "done" EventVerbGet = "get" EventVerbResult = "result" EventVerbRunning = "running" EventVerbSaved = "saved" EventVerbSkipped = "skipped" // Data fields of verification result events (one per policy) EventDataPolicy = "policy" EventDataStatus = "status" EventDataMessage = "message" EventDataResults = "results" // EventDataCommunity flags policy events about the community repository EventDataCommunity = "community" )
const CommunityPolicyRepositoryURL = "https://github.com/policylabs/oss"
CommunityPolicyRepositoryURL is the repository of community maintained policies, consulted when a project publishes none of its own.
const DefaultAttestationFormat = "ampel"
DefaultAttestationFormat is the attestation type written when none is specified.
const PolicyRequestTitlePrefix = "✨ Community Policies Request: "
PolicyRequestTitlePrefix marks community policy request issues so they stand out in the community policy repository's issue list.
Variables ¶
var ( // ErrNoBinaryInArchive is returned when an archive holds no native // executable for the target platform. ErrNoBinaryInArchive = errors.New("archive contains no executable for the platform") // ErrNoMatchingArchiveEntry is returned when an archive ships executables // but none is named after the installable. ErrNoMatchingArchiveEntry = errors.New("no executable named after the installable in the archive") // ErrBadArchiveEntry is returned when the entry the user asked for is // not in the archive or is not an executable for the platform. ErrBadArchiveEntry = errors.New("requested archive entry cannot be installed") )
var ( ErrNoPolicyAvailable = errors.New("no verification policies available for artifact") ErrVerificationFailed = errors.New("asset failed verification, refusing to install") ErrNoPolicyApplies = errors.New("none of the verification policies apply to this release") ErrNoPlatformVariant = errors.New("no installable variant found for the specified platform") ErrInstallAborted = errors.New("installation aborted") ErrAlreadyInstalled = errors.New("already installed") // ErrInstallModified is returned when the version being installed is // already recorded as installed, but the file in the system is missing // or is no longer the one that was installed. ErrInstallModified = errors.New("installed file does not match its installation record") )
var ( ErrNoInstallableArtifact = errors.New("release has no binary or compatible package for this platform") ErrOnlyArchives = errors.New("release only ships archives in unsupported formats for this platform") ErrAmbiguousInstallable = errors.New("release ships several installables") )
var AttestationFormats = verifier.ResultsAttestationFormats
AttestationFormats lists the types of attestation drop can write about a verification: the full ampel result set, a SLSA verification summary (vsa) or an in-toto simple verification result (svr).
var ErrInvalidAttestationFormat = errors.New("invalid attestation format")
ErrInvalidAttestationFormat is returned when an unknown attestation format is requested.
var ErrNotInstalled = errors.New("app not installed with drop")
ErrNotInstalled is returned when an app reference names nothing in the inventory of apps installed with drop.
Functions ¶
func AcceptSingleArchiveEntry ¶
AcceptSingleArchiveEntry is an ArchiveEntrySelector for runs that opted out of prompts: it installs the only executable found in an archive and fails when there are several to choose from.
func CommunityPolicyPath ¶
CommunityPolicyPath returns the directory inside the community policy repository holding the release policies of a repository.
func DefaultPolicyRepository ¶
DefaultPolicyRepository returns the URL of the repository where drop looks for the policies of a publisher when no alternative source is configured: the organization's .github repository.
func OrgPolicyPath ¶
func OrgPolicyPath() string
OrgPolicyPath returns the directory inside a policy repository holding the policies that apply to the releases of every repository in the organization.
func PolicyPath ¶
PolicyPath returns the directory inside a policy repository holding the release policies of a repository.
func PolicyPaths ¶
PolicyPaths returns the directories read for a repository's policies, the organization-wide one first.
func PolicyPathsLabel ¶
PolicyPathsLabel renders the policy directories of a repository compactly for messages: ampel/policies/release/{_,repo}/
Types ¶
type ArchiveEntrySelector ¶
ArchiveEntrySelector chooses which executable inside an archive to install when none is named after the installable. It receives the archive filename, the installable name and the paths of the executables found, and returns the chosen path, or ErrInstallAborted when the user declines. The CLI injects an interactive implementation when running on a terminal.
type ArtifactKind ¶
type ArtifactKind string
ArtifactKind distinguishes the kinds of artifacts the installer can handle.
const ( ArtifactBinary ArtifactKind = "binary" ArtifactPackage ArtifactKind = "package" ArtifactArchive ArtifactKind = "archive" )
type ArtifactSelector ¶
type ArtifactSelector func(candidates []*InstallArtifact) (*InstallArtifact, error)
ArtifactSelector resolves an ambiguous choice between install candidates. The CLI injects an interactive implementation when running on a terminal.
type Dropper ¶
type Dropper struct {
Options Options
// contains filtered or unexported fields
}
func New ¶
func New(funcs ...FuncOption) (*Dropper, error)
func (*Dropper) CheckUpdates ¶
func (dropper *Dropper) CheckUpdates(refs ...string) ([]*UpdateStatus, error)
CheckUpdates reads the inventory of installed apps and checks the GitHub releases of each of them to see if a newer version is available.
When app references are passed, only the apps they name are checked. A reference is the name of an installed app or the repository it came from (org/repo or host/org/repo), and may be a glob pattern such as "cos*" or "sigstore/*". A reference naming no installed app returns an error wrapping ErrNotInstalled.
func (*Dropper) FindInstalled ¶ added in v0.2.1
FindInstalled returns the inventory records an app reference names, in inventory order. A reference is the name of an installed app, or the repository it came from as org/repo or host/org/repo (optionally with a scheme), which names every app installed from it.
func (*Dropper) Get ¶
func (dropper *Dropper) Get(spec github.AssetDataProvider, funcs ...FuncGetOption) error
Get downloads and verifies an artifact from a GitHub release.
func (*Dropper) Install ¶
func (dropper *Dropper) Install(spec github.AssetDataProvider, funcs ...FuncGetOption) error
Install downloads, verifies and installs an artifact from a release
func (*Dropper) ListInstalled ¶ added in v0.2.0
ListInstalled returns the apps installed with drop as recorded in the inventory, sorted by repository and name. It reads no network data.
func (*Dropper) Remove ¶ added in v0.2.1
func (dropper *Dropper) Remove(record *inventory.Record, funcs ...FuncGetOption) error
Remove uninstalls an app installed with drop, deleting its binary or removing its package through the package manager, and drops it from the inventory. The inventory is left untouched when the removal fails.
func (*Dropper) Update ¶
func (dropper *Dropper) Update(status *UpdateStatus, funcs ...FuncGetOption) error
Update reinstalls an app from the latest release of its repository, reusing the choices recorded when it was originally installed.
type Event ¶
func (*Event) GetDataField ¶
type FuncGetOption ¶
type FuncGetOption func(*GetOptions) error
func WithArchiveEntry ¶
func WithArchiveEntry(entryPath string) FuncGetOption
WithArchiveEntry pins the file to install from an archive, falling back to the regular selection when the archive does not hold it anymore.
func WithArchiveEntrySelector ¶
func WithArchiveEntrySelector(fn ArchiveEntrySelector) FuncGetOption
func WithArtifactSelector ¶
func WithArtifactSelector(fn ArtifactSelector) FuncGetOption
func WithAttestationPath ¶
func WithAttestationPath(path string) FuncGetOption
WithAttestationPath sets where the attestation of the verification is written: a file path, a directory or empty for the default location.
func WithBinDir ¶
func WithBinDir(dir string) FuncGetOption
func WithDownloadPath ¶
func WithDownloadPath(path string) FuncGetOption
func WithDownloadType ¶
func WithDownloadType(t string) FuncGetOption
func WithReinstall ¶
func WithReinstall(reinstall bool) FuncGetOption
WithReinstall allows installing an app that is already installed. The choices made when it was first installed are reused unless overridden.
func WithRequiredArchiveEntry ¶
func WithRequiredArchiveEntry(entryPath string) FuncGetOption
WithRequiredArchiveEntry names the file to install from an archive. The installation fails if the archive does not hold an executable at that path.
func WithTransferTimeOut ¶
func WithTransferTimeOut(seconds int) FuncGetOption
func WithVerifyDownloads ¶
func WithVerifyDownloads(verify bool) FuncGetOption
func WithVerifyWhenPossible ¶ added in v0.2.2
func WithVerifyWhenPossible(when bool) FuncGetOption
WithVerifyWhenPossible verifies the artifact when policies are published for it and lets it through without verification when there are none (see GetOptions.VerifyWhenPossible).
type FuncOption ¶
func WithAttestation ¶
func WithAttestation(format string) FuncOption
WithAttestation enables writing an attestation of every verification in the specified format (one of AttestationFormats, the default when empty).
func WithCommunityPolicyRepository ¶
func WithCommunityPolicyRepository(repoURL string) FuncOption
WithCommunityPolicyRepository sets the repository of community policies consulted when a project has none of its own. An empty URL disables the fallback.
func WithListener ¶
func WithListener(listener ProgressListener) FuncOption
func WithPolicyRepository ¶
func WithPolicyRepository(repoURL string) FuncOption
WithPolicyRepository sets the repository policies are read from instead of the .github repository of the artifact's organization: a GitHub repository (URL or org/repo slug) or a local git checkout given as a file:// URL or a directory path (the committed contents are read, not the working tree). Policies are read from ampel/policies/release/<repo>/ and the org-wide ampel/policies/release/_/ in either case.
func WithSigner ¶
func WithSigner(s *signer.Signer) FuncOption
WithSigner sets the signer used to sign attestations. A nil signer writes unsigned statements.
type GetOptions ¶
type GetOptions struct {
// Embedded dropper options to pass to implementation
Options
// Directory where the asset will be downloaded
DownloadPath string
// Platform to download
OS string
Arch string
// Filename to store the downloaded asset
FileName string
// TransferTimeOut is the number of seconds after which the http request
// will time out.
TransferTimeOut int
// SkipVerification instructs the dropper engine to skip the artifact
// security verification. This allows the tool to be used as a curl-like
// thing for repos.
SkipVerification bool
// VerifyWhenPossible verifies the artifact when verification policies
// are published for it and installs it without verification when there
// are none, or none of them applies to it, instead of refusing to. An
// artifact that policies apply to and fails them is still refused. It
// is how an app that was installed without verification is updated:
// with whatever the release offers by then.
VerifyWhenPossible bool
// DownloadType is "a","b" or "p" and determines which download we do
DownloadType string
// BinDir is the directory where binaries are installed by the install
// subcommand.
BinDir string
// Selector resolves the choice between a binary and a package when a
// release offers both for the local system.
Selector ArtifactSelector
// ArchiveEntry pins the path inside the archive of the file to install
// when installing from an archive. Updates set it from the inventory
// so the choice made when the app was first installed is reused.
ArchiveEntry string
// ArchiveEntryRequired makes a missing or non installable ArchiveEntry
// an error instead of falling back to the regular selection. It is set
// when the user names the entry explicitly.
ArchiveEntryRequired bool
// EntrySelector chooses the executable to install from an archive when
// none is named after the installable.
EntrySelector ArchiveEntrySelector
// AttestationPath is where the attestation of the verification is
// written: a file path, a directory (which gets the default filename)
// or empty to use the default filename in the download directory.
AttestationPath string
// Reinstall allows installing an app that is already recorded in the
// inventory. The recorded choices (artifact kind, archive entry) are
// reused unless overridden, and when the new installation replaces the
// previous one in another format, the previous artifact is removed.
Reinstall bool
// contains filtered or unexported fields
}
type InstallArtifact ¶
type InstallArtifact struct {
// Kind is the artifact type: binary, package or archive.
Kind ArtifactKind
// PackageFormat is the package type (rpm, deb, apk) when Kind is package.
PackageFormat string
// Asset is the release asset variant to download.
Asset *github.Asset
// Name is the installable name identifying the app. It keys the app in
// the inventory and is the name updates look up in newer releases.
Name string
// InstallName is the name the binary gets when installed into the path.
// It usually matches Name (plus .exe on windows) but can differ when
// the installed file is not named after the installable.
InstallName string
// ArchiveEntry is the path inside the archive of the installed file
// when Kind is archive. It is filled in once the archive is inspected
// and stays empty for bare compressed files.
ArchiveEntry string
}
InstallArtifact is a concrete release asset chosen for installation.
type KeptVerification ¶ added in v0.2.2
type KeptVerification struct {
// contains filtered or unexported fields
}
KeptVerification is the results of the verification of an artifact, kept before the artifact is installed. Until the installation is recorded they sit beside the results of the installation they would replace, which stay as they are if the artifact does not get installed.
func (*KeptVerification) Discard ¶ added in v0.2.2
func (k *KeptVerification) Discard()
Discard removes results that will not be part of an installation's record: the artifact was not installed. It does nothing to results that already are.
type NoopListener ¶
type NoopListener struct{}
NoopListener is a listener tht just swallows events without doing anything
func (*NoopListener) HandleEvent ¶
func (*NoopListener) HandleEvent(event *Event)
type Options ¶
type Options struct {
// PolicyRepository overrides the repository policies are read from.
PolicyRepository string
// CommunityPolicyRepository is consulted when a project publishes no
// policies of its own (and no PolicyRepository override is set). Empty
// disables the fallback.
CommunityPolicyRepository string
Listener ProgressListener
// Attest enables writing an attestation of every verification
// performed, in the AttestFormat format.
Attest bool
// AttestFormat is the type of attestation written (see
// AttestationFormats).
AttestFormat string
// Signer signs the attestations. When nil, the bare in-toto statement
// is written instead.
Signer *signer.Signer
}
type PolicyRequest ¶
type PolicyRequest struct {
// Repository coordinates of the project lacking policies
Host string
Org string
Repo string
// PolicyRepository is the URL where drop looked for policies
PolicyRepository string
// CommunityRepository is the URL of the community policy repository
// that was checked as well, empty when none was.
CommunityRepository string
// Release is the tag of the release drop checked for policies
Release string
// Version and Platform of the drop binary filing the request
Version string
Platform string
}
PolicyRequest describes a request for the community to write policies for an open source repository that has none. Requests are filed as issues in the community policy repository.
func (*PolicyRequest) Body ¶
func (pr *PolicyRequest) Body() string
Body returns the markdown body of the request issue.
func (*PolicyRequest) ReleaseURL ¶
func (pr *PolicyRequest) ReleaseURL() string
ReleaseURL returns the URL of the release that was checked, or an empty string when no release is recorded.
func (*PolicyRequest) RepositoryURL ¶
func (pr *PolicyRequest) RepositoryURL() string
RepositoryURL returns the URL of the requested repository.
func (*PolicyRequest) Slug ¶
func (pr *PolicyRequest) Slug() string
Slug returns the org/repo slug of the requested repository.
func (*PolicyRequest) Title ¶
func (pr *PolicyRequest) Title() string
Title returns the title of the request issue.
func (*PolicyRequest) URL ¶
func (pr *PolicyRequest) URL() string
URL returns the link to open a prefilled issue in the community policy repository (CommunityRepository, or the default when empty). Filing the issue happens in the browser, where the user is signed in to GitHub, so no token is required.
type ProgressListener ¶
type ProgressListener interface {
HandleEvent(event *Event)
}
ProgressListener is an object that reacts to the events from the downloader.
type UpdateStatus ¶
type UpdateStatus struct {
// Record is the inventory entry of the installed app.
Record *inventory.Record
// LatestVersion is the newest release available in the repository.
LatestVersion string
// UpdateAvailable is true when the latest release is newer than the
// installed version.
UpdateAvailable bool
// Error captures a per-app check failure (API errors, repository
// gone, etc) without aborting the rest of the checks.
Error error
}
UpdateStatus describes the update state of an app installed with drop.