bundle

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 24 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.
	BundleKey = "bundle.pb.gz"
	// 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 MaxCompressedBytes = 900 << 10

MaxCompressedBytes is the largest bundle stored: Secrets are limited to 1 MiB. Bundles reference the Core Rule Set by name, so this 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 a Secret")

ErrTooLarge is returned for a bundle over MaxCompressedBytes.

Functions

func ContentHash

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

ContentHash hashes what a bundle enforces: everything but its version, creation time 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 content of the bundle Secret's BundleKey.

func Encode

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

Encode returns the content of the bundle Secret's BundleKey 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.

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.

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, namespace string, b *bundlev1.Bundle, signed *bundlev1.SignedBundle, pub ed25519.PublicKey) error

Store writes a signed bundle to the bundle Secret.

Types

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) 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