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 // 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.
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 (*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
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 ¶
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
TrustedKeys returns the IDs of the public keys bundles are verified with.
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
// ProbeReceipts returns the receipts of the operator's probes to
// report with each heartbeat (#475; nil: none).
ProbeReceipts func() []string
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).