agent

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 29 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
)

Defaults of the Agent.

View Source
const SecretBundleKey = "bundle.pb.gz" // #nosec G101 -- a data key, not a credential

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

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 key.

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

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

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

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 cluster's ed25519 public key (the raw 32 bytes,
	// as in the bundle Secret's ed25519.pub).
	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

	Logger     *slog.Logger
	Heartbeat  time.Duration
	MinBackoff time.Duration
	MaxBackoff 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.

Jump to

Keyboard shortcuts

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