imagelife

package
v1.5.20 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package imagelife builds the image inventory of a node, decides which images retention may free, and verifies image signatures. Nothing here talks to Docker: callers pass records in and execute the plans.

Index

Constants

View Source
const (
	RoleLive           = "live"
	RoleRollbackTarget = "rollback_target"
	RoleRecent         = "recent"
	RoleHistory        = "history"
	// RolePendingDeploy marks an image a queued, held or running deploy still needs.
	RolePendingDeploy = "pending_deploy"
)

Roles an app can have for an image.

Variables

View Source
var ErrNoSignature = errors.New("no signature found for this image")

ErrNoSignature means the registry holds no signature for the image.

View Source
var ErrRegistry = errors.New("registry read failed")

ErrRegistry marks a failure to read the registry, as opposed to a bad signature.

View Source
var ErrSignatureMismatch = errors.New("no signature matched the configured public key")

ErrSignatureMismatch means signatures exist but none verifies for the key.

Functions

func DigestOfRecord

func DigestOfRecord(r docker.ImageRecord) string

DigestOfRecord returns the registry digest of r, or "" for a local build.

func IsPendingStatus

func IsPendingStatus(status string) bool

IsPendingStatus reports whether a deploy in this status still needs its image.

func ParsePublicKey

func ParsePublicKey(pemData []byte) (*ecdsa.PublicKey, error)

ParsePublicKey reads a PEM encoded ECDSA public key.

func Reclaimable

func Reclaimable(e Entry) int64

Reclaimable is the space freeing e returns, net of layers other images share.

func RemovalBlock

func RemovalBlock(e Entry) string

RemovalBlock returns why an explicit removal of e must be refused, or "" when it may go. Unlike retention it lets the user remove unmanaged and old deploy images on purpose, but never one a container or a rollback needs.

func RemoveRefs

func RemoveRefs(e Entry) []string

RemoveRefs returns the references to delete, in order, to free e: each tag, or the ID for an untagged image.

func SignPayload

func SignPayload(priv *ecdsa.PrivateKey, repo, digest string) (payload []byte, sigB64 string, err error)

SignPayload builds the signed payload and signature for digest. It exists so tests and tooling can produce what Verify consumes.

Types

type AppState

type AppState struct {
	Name        string
	LiveImage   string
	LiveImageID string
	// Attempts is newest first.
	Attempts []Attempt
	Pins     []Pin
	// Keep overrides the global keep count for this app when above zero.
	Keep int
}

AppState is what one app contributes to the inventory.

type AppUse

type AppUse struct {
	App       string    `json:"app"`
	Role      string    `json:"role"`
	DeployID  string    `json:"deploy_id,omitempty"`
	Source    string    `json:"source,omitempty"`
	CommitSHA string    `json:"commit_sha,omitempty"`
	Branch    string    `json:"branch,omitempty"`
	At        time.Time `json:"at,omitempty"`
}

AppUse says how an app relates to one image.

type Attempt

type Attempt struct {
	ID        string
	Image     string
	Digest    string
	Source    string
	CommitSHA string
	Branch    string
	Status    string
	StartedAt time.Time
	// Pinned is set when a person pinned the deploy, so its image is never freed.
	Pinned bool
}

Attempt is the slice of a deploy attempt the inventory needs.

type BundleSource

type BundleSource func(ctx context.Context, ref string, creds Credentials) ([]verify.SignedEntity, error)

BundleSource returns the Sigstore bundles stored for an image digest.

type Credentials

type Credentials struct{ Username, Password string }

Credentials authenticate registry reads.

type Entry

type Entry struct {
	ID            string    `json:"id"`
	Digest        string    `json:"digest,omitempty"`
	Tags          []string  `json:"tags"`
	SizeBytes     int64     `json:"size_bytes"`
	SharedBytes   int64     `json:"shared_bytes"`
	Containers    int64     `json:"containers"`
	CreatedAt     time.Time `json:"created_at"`
	Apps          []AppUse  `json:"apps"`
	Protected     bool      `json:"protected"`
	ProtectReason string    `json:"protect_reason,omitempty"`
	// Unmanaged is true when no app of this platform owns the image.
	Unmanaged bool `json:"unmanaged"`
	// InUse is true when any container, running or stopped, uses the image.
	InUse bool `json:"in_use"`
	// Removable says an explicit user removal is allowed right now.
	Removable       bool   `json:"removable"`
	RemovableReason string `json:"removable_reason,omitempty"`
	BlockedReason   string `json:"blocked_reason,omitempty"`
	// contains filtered or unexported fields
}

Entry is one image with its owners and retention status.

func Build

func Build(records []docker.ImageRecord, apps []AppState, keepPerApp int, minAge time.Duration, now time.Time) []Entry

Build joins image records with app deploy history. keepPerApp is how many newest succeeded deploys per app count as "recent" and stay protected. Entries come back biggest first.

func UnmanagedUnused

func UnmanagedUnused(entries []Entry) []Entry

UnmanagedUnused lists the entries an include_unmanaged_unused request removes.

func (Entry) MatchesAttempt

func (e Entry) MatchesAttempt(a Attempt) bool

MatchesAttempt reports whether a deploy attempt refers to this image.

type Pin

type Pin struct {
	DeployID string
	Image    string
	ImageID  string
	PinRef   string
}

Pin is a rollback pin: an image kept alive as a rollback target.

type Plan

type Plan struct {
	Remove       []Entry `json:"remove"`
	ReclaimBytes int64   `json:"reclaim_bytes"`
	// ReclaimMaxBytes and ReclaimExact say how far ReclaimBytes can undercount when removed images share layers.
	ReclaimMaxBytes int64 `json:"reclaim_max_bytes"`
	ReclaimExact    bool  `json:"reclaim_exact"`
	KeptCount       int   `json:"kept_count"`
}

Plan is the outcome of retention: what would be freed and what is kept.

func PlanGC

func PlanGC(entries []Entry) Plan

PlanGC selects every unprotected entry. Protected images are never in Remove, whatever the policy says.

type ReclaimEstimate

type ReclaimEstimate struct {
	MinBytes int64 `json:"reclaimable_bytes"`
	MaxBytes int64 `json:"reclaimable_max_bytes"`
	// Exact is true when at most one image in the set shares layers, so nothing is counted twice.
	Exact bool `json:"reclaimable_exact"`
}

ReclaimEstimate bounds the space freed by removing a set of images together. SharedBytes counts layers shared with any other image, including ones in the set, so per-image net sizes are a floor and the sum of shared bytes can only add to it.

func EstimateReclaim

func EstimateReclaim(entries []Entry) ReclaimEstimate

EstimateReclaim sums net sizes and widens the range when two or more removed images share layers.

type TrustRootFunc

type TrustRootFunc func(ctx context.Context) (root.TrustedMaterial, error)

TrustRootFunc loads the Sigstore trusted material for keyless checks.

type TrustVerifier

type TrustVerifier struct {
	Keys    *Verifier
	Bundles BundleSource
	Root    TrustRootFunc
	// SkipSCT drops the certificate timestamp requirement. Only test
	// authorities, which issue no SCTs, need it.
	SkipSCT bool
}

TrustVerifier checks an image against a trusted signer list. It never trusts a signature on its own: a signer must match by key or by exact issuer and identity.

func NewTrustVerifier

func NewTrustVerifier(load TrustRootFunc) *TrustVerifier

NewTrustVerifier returns a verifier that reads signatures from the image's registry and the Sigstore root from load.

func (*TrustVerifier) Verify

func (t *TrustVerifier) Verify(ctx context.Context, image string, signers []policy.Signer, creds Credentials) policy.SignatureVerdict

Verify judges image (which must carry a sha256 digest) against signers.

type Verifier

type Verifier struct {
	HTTP *http.Client
}

Verifier checks cosign key-based signatures (ECDSA P-256) stored beside the image in its registry as a sha256-<digest>.sig tag.

func NewVerifier

func NewVerifier() *Verifier

NewVerifier returns a Verifier with a bounded HTTP timeout.

func (*Verifier) ReferrerBundles

func (v *Verifier) ReferrerBundles(ctx context.Context, ref string, creds Credentials) ([]verify.SignedEntity, error)

ReferrerBundles reads the Sigstore bundles attached to ref through the registry's OCI referrers API. An empty result means none are attached. At most maxReferrerBundles are read so a hostile registry cannot make a deploy download without bound.

func (*Verifier) Verify

func (v *Verifier) Verify(ctx context.Context, ref string, pub *ecdsa.PublicKey, creds Credentials) error

Verify checks that ref (repo@sha256:...) carries a signature made by pub.

Jump to

Keyboard shortcuts

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