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 ¶
const ( DefaultHeartbeat = 5 * time.Second DefaultMinBackoff = time.Second DefaultMaxBackoff = 30 * time.Second )
Defaults of the Agent.
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 (*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.
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.