agent

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 35 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 agent connects the engine to the operator (0002 §5.2): it keeps one stream open, verifies and applies every bundle the operator sends, and reports what it applied. Without the operator the engine keeps enforcing the last bundle it applied, also across restarts through an on-disk cache; a new engine with no cache reads the bundle Secret instead.

Index

Constants

View Source
const (
	DefaultHeartbeat  = 5 * time.Second
	DefaultMinBackoff = time.Second
	DefaultMaxBackoff = 30 * time.Second
	// DefaultKeyReload is how often the public key file is checked for
	// changes: the kubelet updates a mounted ConfigMap within a minute or
	// two, and the operator waits for every engine to report a new key
	// before it signs with it.
	DefaultKeyReload = 10 * time.Second
)

Defaults of the Agent.

View Source
const SecretBundleKey = bundlesecret.BundleKey

SecretBundleKey is the key of the bundle Secret that holds the gzip-compressed, serialized SignedBundle (the operator writes it), when it fits in one Secret.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent keeps the engine's policy in sync with the operator.

func New

func New(cfg Config) (*Agent, error)

New checks cfg and reads the public keys.

func (*Agent) Applied

func (a *Agent) Applied() <-chan struct{}

Applied is closed once a bundle is applied: the cached one, the Secret's or the operator's.

func (*Agent) Collectors

func (a *Agent) Collectors() []prometheus.Collector

Collectors returns the agent's metrics, to register with the engine's.

func (*Agent) LoadCache added in v0.1.3

func (a *Agent) LoadCache() bool

LoadCache applies the cached bundle, if there is a valid one, and reports whether a bundle is applied. Only the first call (of LoadCache or Run) reads the cache. The engine calls it before it serves, so a restarted engine never answers before it enforces the cached bundle.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context) error

Run loads the cached bundle (unless LoadCache did), or else the bundle Secret's, then keeps a stream to the operator open until ctx ends, reconnecting with backoff.

func (*Agent) TrustedKeys added in v0.1.1

func (a *Agent) TrustedKeys() []string

TrustedKeys returns the IDs of the public keys bundles are verified with.

func (*Agent) Version

func (a *Agent) Version() uint64

Version returns the applied bundle's version, 0 before the first.

type Config

type Config struct {
	// Addr is the operator's distribution server, host:port.
	Addr string
	// CAFile verifies the operator's certificate; ServerName overrides the
	// name checked (default: the host of Addr).
	CAFile     string
	ServerName string
	// TokenFile holds the projected ServiceAccount token, re-read on every
	// connection since the kubelet rotates it.
	TokenFile string
	// PublicKeyFile holds the ed25519 public keys bundles may be signed
	// with: one or more raw 32-byte keys, concatenated (the trust
	// ConfigMap's trusted-keys.pub; a single key, as ed25519.pub, works
	// too). It is re-read every KeyReload, so the keys rotate without a
	// restart.
	PublicKeyFile string
	// CacheFile, if set, keeps the last applied bundle, so a restarted
	// engine enforces it before the operator is reachable.
	CacheFile string
	// Secret, if set, is read when the engine has no bundle: at startup
	// without a usable cache, and between attempts to reach the operator
	// until a bundle is applied.
	Secret *SecretSource

	EngineID      string
	PodNamespace  string
	PodName       string
	NodeName      string
	EngineVersion string

	// Compile turns a bundle into a policy set (policy.Compile with the
	// engine's options); Holder serves the applied set.
	Compile func(*bundlev1.Bundle) (*policy.Set, error)
	Holder  *policy.Holder
	// Admission is reported in heartbeats.
	Admission *pipeline.Admission
	// Events holds the security events to send to the operator (nil:
	// none).
	Events *events.Buffer
	// Stats counts the requests of each policy, reported to the operator
	// with the heartbeats (nil: none).
	Stats *events.Stats

	Logger     *slog.Logger
	Heartbeat  time.Duration
	MinBackoff time.Duration
	MaxBackoff time.Duration
	KeyReload  time.Duration
}

Config configures an Agent.

type SecretSource

type SecretSource struct {
	Namespace string
	Name      string
	// APIServer is the API server's URL; empty: the in-cluster address,
	// from KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT.
	APIServer string
	// CAFile verifies the API server's certificate.
	CAFile string
	// TokenFile holds a ServiceAccount token for the API server's own
	// audience (not the operator's), re-read on every request.
	TokenFile string
}

SecretSource reads the operator's bundle Secret through the Kubernetes API (0004 §4.6). The engine uses it when it has no bundle: a new pod with no cache, while the operator is unreachable. The bundle's signature is checked like any other's, so the Secret is no more trusted than the operator's stream. Reading it takes get on the Secret, the permission the operator already authorizes engines by, and on its chunks, for a bundle too large for one Secret (bundlesecret).

Jump to

Keyboard shortcuts

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