bundle

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 26 Imported by: 1 module, 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 bundle builds, signs and stores policy bundles (0004 §4.6). The bundle Secret is both what the distribution server sends and the engines' cold-start source, and it carries the version sequence, so a new leader continues it.

Index

Constants

View Source
const (
	BundleSecret     = "inkwall-bundle"
	SigningKeySecret = "inkwall-bundle-signing-key" // #nosec G101 -- the Secret's name, not a credential
)

Names of the Secrets in the operator's namespace.

View Source
const (
	// BundleKey holds the gzip-compressed, serialized SignedBundle, when it
	// fits in one Secret; else ManifestKey lists its chunks.
	BundleKey   = bundlesecret.BundleKey
	ManifestKey = bundlesecret.ManifestKey
	// PublicKeyKey holds the ed25519 public key the bundle is signed with,
	// so an engine reading the Secret can check which key it needs. In the
	// signing key Secret and the trust ConfigMap it is the active key.
	PublicKeyKey = "ed25519.pub"
)

Keys of the bundle Secret.

View Source
const (
	VersionAnnotation = "waf.inkwall.dev/bundle-version"
	HashAnnotation    = "waf.inkwall.dev/content-hash"
	// KeyIDAnnotation names the key the bundle is signed with.
	KeyIDAnnotation = "waf.inkwall.dev/key-id"
)

Annotations on the bundle Secret, for people and tools.

View Source
const ChunkLabel = "waf.inkwall.dev/bundle-chunk"

ChunkLabel marks the chunk Secrets of a bundle too large for one Secret.

View Source
const MaxCompressedBytes = bundlesecret.MaxBytes

MaxCompressedBytes is the largest bundle stored, in chunks of bundlesecret.ChunkBytes: Secrets are limited to 1 MiB. Bundles reference the Core Rule Set by name, so one Secret takes many thousands of policies.

View Source
const (
	// RotationPhaseAnnotation is the rotation's phase, for people and
	// tools: Publishing or Retiring, absent between rotations.
	RotationPhaseAnnotation = "waf.inkwall.dev/rotation-phase"
)

Annotations on the signing key Secret.

View Source
const (

	// TrustedKeysKey holds every public key engines must accept now, in the
	// bundlekey format: the active key and, during a rotation, the next or
	// the previous one. The trust ConfigMaps carry it.
	TrustedKeysKey = "trusted-keys.pub"
)

Keys of the signing key Secret. ed25519.key, ed25519.pub (PublicKeyKey) and key-id are the active key, as before key rotation.

Variables

View Source
var ErrTooLarge = errors.New("bundle too large for its Secrets")

ErrTooLarge is returned for a bundle over MaxCompressedBytes, or over bundlesecret.MaxBundleBytes decompressed.

Functions

func CompressedSize added in v0.2.0

func CompressedSize(s *corev1.Secret) int

CompressedSize returns the size of the bundle Secret s's compressed bundle, in one Secret or in chunks.

func ContentHash

func ContentHash(b *bundlev1.Bundle) ([]byte, error)

ContentHash hashes what a bundle enforces: everything but its version, creation time, policy versions and the hash itself. Encoding is deterministic, so equal content gives an equal hash within one operator version.

func Decode

func Decode(data []byte) (*bundlev1.SignedBundle, error)

Decode reads the compressed bundle of the bundle Secret's BundleKey, or of its chunks joined.

func Encode

func Encode(signed *bundlev1.SignedBundle) ([]byte, error)

Encode returns the compressed bundle for signed: the reverse of Decode.

func Load

func Load(ctx context.Context, c client.Reader, namespace string) (*bundlev1.Bundle, string, error)

Load reads the current bundle from its Secret, and the ID of the key it is signed with; nil if there is none. If its chunks don't match its manifest (bundlesecret.ErrIncomplete), the bundle has only the version of the Secret's annotation, to continue the sequence.

func Next

func Next(current, content *bundlev1.Bundle, lastVersion uint64, now time.Time, resign bool) (*bundlev1.Bundle, bool, error)

Next returns the bundle to publish for content, given the current one (nil if none), and whether it differs: unchanged content keeps the current version, unless resign asks for a new one (the signing key changed). lastVersion is the highest version this process published, so a deleted Secret doesn't restart the sequence while the leader runs.

A new bundle is content itself, not a copy, with its version, creation time, hash and policy versions set: the caller gives content up. A policy's version is the current bundle's for it if the new bundle doesn't change what it enforces (PolicyHashes), else the new version.

func PolicyHashes added in v0.3.0

func PolicyHashes(b *bundlev1.Bundle) (map[string][sha256.Size]byte, error)

PolicyHashes hashes what each policy of b enforces, by policy id: the policy, the rule sets it binds and whether b is suspended. A policy's hash changes only with a bundle that changes it, so its status needn't be written for every bundle (#149).

func PolicyVersions added in v0.3.0

func PolicyVersions(b *bundlev1.Bundle) map[string]uint64

PolicyVersions returns, by policy id, the first bundle that enforces each policy of b as it is in b. A bundle without them (from an operator before v0.3.0) gives its own version: it enforces every policy it has.

func Prune added in v0.2.0

func Prune(ctx context.Context, c client.Client, r client.Reader, namespace string) error

Prune deletes the chunk Secrets the bundle Secret's manifest doesn't list: those of a bundle replaced since. r reads the bundle Secret uncached, c lists the chunks.

func Read added in v0.2.0

Read returns the signed bundle of the bundle Secret s, reading its chunks with c if it has a manifest.

func ReadCompressed added in v0.3.0

func ReadCompressed(ctx context.Context, c client.Reader, s *corev1.Secret) ([]byte, error)

ReadCompressed returns the compressed bundle of the bundle Secret s, as Decode reads it: its BundleKey, or its chunks joined, read with c.

func SaveKeyring

func SaveKeyring(ctx context.Context, c client.Client, namespace string, k *Keyring, s *corev1.Secret) error

SaveKeyring writes k to the signing key Secret: a new one if s is nil, else s, read by LoadKeyring, whose resourceVersion makes a concurrent write fail rather than be lost.

func Store

func Store(ctx context.Context, c client.Client, r client.Reader, namespace string, b *bundlev1.Bundle,
	signed *bundlev1.SignedBundle, pub ed25519.PublicKey) (int, error)

Store writes a signed bundle to the bundle Secret, and returns its compressed size (also with ErrTooLarge, when known). A bundle over bundlesecret.ChunkBytes is split into chunk Secrets, written before the manifest that points at them, to the names the current manifest doesn't use; Prune deletes the others after. c writes, r reads uncached: the current manifest decides where the chunks go.

Types

type Current added in v0.3.0

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

Current keeps the bundle last loaded or stored, with its compressed form, so Load decodes the bundle Secret only when it holds another bundle: decoding a large bundle on every build costs megabytes (#213). The bundle it returns is shared: don't modify it.

func (*Current) Load added in v0.3.0

func (cur *Current) Load(ctx context.Context, c client.Reader, namespace string) (*bundlev1.Bundle, string, error)

Load is the package's Load, without decoding the Secret if it holds the bundle kept.

func (*Current) Store added in v0.3.0

func (cur *Current) Store(ctx context.Context, c client.Client, r client.Reader, namespace string, b *bundlev1.Bundle,
	signed *bundlev1.SignedBundle, pub ed25519.PublicKey) (int, error)

Store is the package's Store, keeping b once it is stored.

type EngineKeys

type EngineKeys struct {
	// Name identifies the engine to people (its pod).
	Name string
	// TrustedKeys are the key IDs the engine reported.
	TrustedKeys []string
	// Applied is the bundle version the engine runs.
	Applied uint64
}

EngineKeys is what a rotation needs to know of a connected engine.

type Keyring

type Keyring struct {
	// Active signs bundles.
	Active *Signer
	// Next is published and will sign (PhasePublishing).
	Next *Signer
	// Previous signed before Active and is still trusted (PhaseRetiring).
	Previous ed25519.PublicKey
	// PhaseSince is when the phase began; zero when idle.
	PhaseSince time.Time
	// SwitchVersion is the first bundle signed by Active, once it is
	// published (PhaseRetiring).
	SwitchVersion uint64
	// ActiveSince is when Active began to sign.
	ActiveSince time.Time
	// Request is the last rotation request handled.
	Request string
}

Keyring is the cluster's bundle signing keys, kept in the signing key Secret.

func LoadKeyring

func LoadKeyring(ctx context.Context, c client.Reader, namespace string) (*Keyring, *corev1.Secret, error)

LoadKeyring reads the keyring from the signing key Secret, and returns the Secret to pass to SaveKeyring; nil, nil if there is none.

func NewKeyring

func NewKeyring(now time.Time) (*Keyring, error)

NewKeyring generates a keyring with one key.

func (*Keyring) Phase

func (k *Keyring) Phase() Phase

Phase returns the rotation's phase.

func (*Keyring) Trusted

func (k *Keyring) Trusted() []ed25519.PublicKey

Trusted returns the public keys engines must accept now: the active one first.

func (*Keyring) TrustedIDs

func (k *Keyring) TrustedIDs() []string

TrustedIDs returns the IDs of the trusted keys, as Trusted orders them.

type Phase

type Phase string

Phase is where a key rotation is.

const (
	// PhaseIdle: one key, which signs.
	PhaseIdle Phase = ""
	// PhasePublishing: the next key is published to the engines; the active
	// one still signs.
	PhasePublishing Phase = "Publishing"
	// PhaseRetiring: the new key signs; the previous one stays trusted
	// until every engine runs a bundle signed by the new one.
	PhaseRetiring Phase = "Retiring"
)

The phases of a rotation (0004 §4.6).

type RotationInput

type RotationInput struct {
	Now time.Time
	// Request is the InkwallConfig's waf.inkwall.dev/rotate-signing-key: a
	// value not handled yet starts a rotation.
	Request string
	// Interval, if not 0, rotates a key that has signed this long.
	Interval time.Duration
	// Grace is the least time each phase lasts: the kubelet takes a minute
	// or two to update a mounted ConfigMap, and an engine that isn't
	// connected now isn't in Engines.
	Grace time.Duration
	// Engines are the connected engines. EnginesKnown is false while the
	// list may be incomplete (a new leader, before the replicas' reports
	// are all in).
	Engines      []EngineKeys
	EnginesKnown bool
	// BundleVersion and BundleKeyID describe the published bundle.
	BundleVersion uint64
	BundleKeyID   string
}

RotationInput is what a rotation step decides on.

type Signer

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

Signer signs bundles.

func GenerateSigner

func GenerateSigner() (*Signer, error)

GenerateSigner returns a Signer for a new key.

func NewSigner

func NewSigner(key ed25519.PrivateKey) *Signer

NewSigner returns a Signer for key, with a key ID derived from its public key (bundlekey.ID).

func (*Signer) KeyID

func (s *Signer) KeyID() string

KeyID identifies the key.

func (*Signer) ProbeKey added in v0.4.0

func (s *Signer) ProbeKey() []byte

ProbeKey is the key of the HAProxy probe (0002 §6.4), which the bundle carries to the engines: an HMAC of a fixed label under the signing key's seed, so it needs no Secret of its own and changes with the signing key.

func (*Signer) Public

func (s *Signer) Public() ed25519.PublicKey

Public returns the public key.

func (*Signer) Sign

func (s *Signer) Sign(b *bundlev1.Bundle) (*bundlev1.SignedBundle, error)

Sign serializes and signs b.

type Step

type Step struct {
	// Keyring is the new keyring; the same one when nothing changed.
	Keyring *Keyring
	Changed bool
	// Event names a change of phase: "started", "switched" or "retired".
	Event string
	// Waiting says what the rotation waits for; "" when nothing.
	Waiting string
}

Step is the outcome of a rotation step.

func Rotate

func Rotate(k *Keyring, in RotationInput) (Step, error)

Rotate takes the next step of a key rotation (0004 §4.6): it starts one on request or when the key is due; publishes the next key and keeps signing with the active one until every connected engine trusts the next; then switches to it, keeping the previous key trusted until every connected engine runs a bundle signed by the new one; and retires the previous key. Each phase lasts at least in.Grace.

Jump to

Keyboard shortcuts

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