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
- Variables
- func CompressedSize(s *corev1.Secret) int
- func ContentHash(b *bundlev1.Bundle) ([]byte, error)
- func Decode(data []byte) (*bundlev1.SignedBundle, error)
- func Encode(signed *bundlev1.SignedBundle) ([]byte, error)
- func Load(ctx context.Context, c client.Reader, namespace string) (*bundlev1.Bundle, string, error)
- func Next(current, content *bundlev1.Bundle, lastVersion uint64, now time.Time, ...) (*bundlev1.Bundle, bool, error)
- func PolicyHashes(b *bundlev1.Bundle) (map[string][sha256.Size]byte, error)
- func PolicyVersions(b *bundlev1.Bundle) map[string]uint64
- func Prune(ctx context.Context, c client.Client, r client.Reader, namespace string) error
- func Read(ctx context.Context, c client.Reader, s *corev1.Secret) (*bundlev1.SignedBundle, error)
- func ReadCompressed(ctx context.Context, c client.Reader, s *corev1.Secret) ([]byte, error)
- func SaveKeyring(ctx context.Context, c client.Client, namespace string, k *Keyring, ...) error
- func Store(ctx context.Context, c client.Client, r client.Reader, namespace string, ...) (int, error)
- type Current
- type EngineKeys
- type Keyring
- type Phase
- type RotationInput
- type Signer
- type Step
Constants ¶
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.
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.
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.
const ChunkLabel = "waf.inkwall.dev/bundle-chunk"
ChunkLabel marks the chunk Secrets of a bundle too large for one Secret.
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.
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.
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 ¶
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
CompressedSize returns the size of the bundle Secret s's compressed bundle, in one Secret or in chunks.
func ContentHash ¶
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 ¶
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
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
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
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
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.
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 ¶
NewKeyring generates a keyring with one key.
func (*Keyring) Trusted ¶
Trusted returns the public keys engines must accept now: the active one first.
func (*Keyring) TrustedIDs ¶
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 ¶
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).
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.