Documentation
¶
Overview ¶
Package distribution serves bundles to the engines (0004 §4.7): every operator replica runs the BundleService, pushes each new bundle to its connected engines, and records what they applied. The leader merges the replicas' records into the Enforced condition of each policy.
Index ¶
- Constants
- Variables
- func Enforced(version int64, engines []Engine, leftOut, missing int) (metav1.ConditionStatus, string, string)
- func Key(id Identity, engineID string) string
- func Ready(conds []metav1.Condition, generation int64) metav1.Condition
- type Authenticator
- type BundleSource
- type Engine
- type GRPCServer
- type Identity
- type KubeAuthenticator
- type Publisher
- type Reporter
- type ServedPod
- type ServedPods
- type Server
- type Store
- func (s *Store) Current() (*bundlev1.SignedBundle, uint64, <-chan struct{})
- func (s *Store) HasPolicy(id string) bool
- func (s *Store) PolicyVersion(id string) uint64
- func (s *Store) Set(signed *bundlev1.SignedBundle, version uint64)
- func (s *Store) SetPolicies(versions map[string]uint64, suspended bool)
- func (s *Store) Suspended() bool
- type Table
Constants ¶
const ( // DefaultHelloTimeout bounds how long an engine may take to say Hello. DefaultHelloTimeout = 10 * time.Second // DefaultIdleTimeout closes a stream that sent nothing (no heartbeat) // for this long; engines send heartbeats every few seconds. DefaultIdleTimeout = 30 * time.Second // DefaultMaxSends bounds concurrent bundle sends, so a new bundle for // hundreds of engines doesn't spike the operator. DefaultMaxSends = 50 )
Defaults of the Server.
const ( ReasonEnforced = "Enforced" ReasonEnginesBehind = "EnginesBehind" // ReasonEnginesUnreported: a replica's engine report was over its // size limit, so not every engine is known. ReasonEnginesUnreported = "EnginesUnreported" ReasonEngineNack = "EngineNack" ReasonNoEngines = "NoEngines" ReasonNotInBundle = "NotInBundle" // ReasonEnginesOutdated: an engine runs the bundle but is too old to // enforce a field the policy sets, which it ignores. ReasonEnginesOutdated = "EnginesOutdated" // ReasonSuspended: the bundle suspends inspection (the InkwallConfig's // spec.suspend), so engines allow every request. ReasonSuspended = "Suspended" )
Reasons of the Enforced condition.
const ( DroppedNotInBundle = "not_in_bundle" DroppedLatencyBuckets = "latency_buckets" DroppedEvicted = "evicted" )
Reasons of RequestStatsDropped.
const Audience = "inkwall-operator"
Audience is the token audience engines request.
const DefaultConfigEvery = 5 * time.Second
DefaultConfigEvery is the Reporter's default ConfigEvery.
const DefaultGone = 2 * time.Minute
DefaultGone is the Reporter's default Gone: more than an engine's longest wait between reconnects (30 s), once a replica answers it. It bounds only engines that report no pod: one whose pod is known counts while its pod exists (#695).
const (
EnginesLabel = enginereport.Label
)
Report labels and keys of the replicas' engine ConfigMaps (operator/enginereport, which reads them).
Variables ¶
var ( ErrUnauthenticated = errors.New("not authenticated") ErrForbidden = errors.New("not allowed to read the bundle") )
Errors of Authenticate.
var ( // RequestStatsDropped counts, per policy and report, the request counts // this replica drops: here, and in the controlplane package's totals. RequestStatsDropped = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "inkwall_operator_request_stats_dropped_total", Help: "Policies' request counts this replica dropped, by reason: not_in_bundle (an engine reported a policy the bundle served here doesn't have), latency_buckets (its latency was counted in other buckets: the counts are kept, the latency dropped), evicted (the totals of a policy no longer in the bundle, forgotten so they stay bounded).", }, []string{"reason"}) )
Functions ¶
func Enforced ¶
func Enforced(version int64, engines []Engine, leftOut, missing int) (metav1.ConditionStatus, string, string)
Enforced computes a policy's Enforced condition: whether every engine given runs a bundle that contains the policy's current generation: the first such bundle is its status.bundleVersion, and later ones have it too. The engines given are those that serve the policy's routes, or all of them when that isn't known (ServedPods).
leftOut engines are connected but missing from their replica's report. missing counts the policy's proxy pods with the engine container whose engine isn't connected: until it is, the pod may serve an older bundle.
The messages don't count engines, so engines connecting or going away don't rewrite every policy's status; the inkwall_operator_engines metric has the counts. EngineNack names the first engine (by ID) that rejected the bundle, with its error.
func Key ¶ added in v0.4.3
Key is the table key of an engine authenticated as id that says it is engineID: the pod its token is bound to, otherwise its ServiceAccount and engineID. An engine can't take the record of another pod, or of another ServiceAccount's engine, by naming its engine ID.
func Ready ¶
Ready combines a policy's conditions (0004 §3.2): True when Accepted, Programmed and Enforced all are; otherwise the first that isn't, by its reason, so kubectl shows what is missing. Suspended inspection (Enforced's reason Suspended) comes first: whatever else holds, every engine allows every request (#291).
Types ¶
type Authenticator ¶
Authenticator checks an engine's bearer token.
type BundleSource ¶
BundleSource loads the bundle Secret into the Store on every replica.
func (*BundleSource) Reconcile ¶
func (b *BundleSource) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error)
Reconcile loads the current bundle.
func (*BundleSource) SetupWithManager ¶
func (b *BundleSource) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager registers the source with mgr.
type Engine ¶
type Engine struct {
// ID is the engine's own, from its Hello.
ID string `json:"id"`
// ServiceAccount authenticated the stream, as "namespace/name".
ServiceAccount string `json:"serviceAccount"`
// Pod and node: from the token when it is bound to a pod, otherwise as
// the engine reported them.
PodNamespace string `json:"podNamespace,omitempty"`
PodName string `json:"podName,omitempty"`
NodeName string `json:"nodeName,omitempty"`
EngineVersion string `json:"engineVersion,omitempty"`
// Applied is the newest bundle version the engine runs.
Applied uint64 `json:"applied"`
// Rejected is the newest version the engine refused, and why.
Rejected uint64 `json:"rejected,omitempty"`
RejectError string `json:"rejectError,omitempty"`
// TrustedKeys are the IDs of the bundle signing keys the engine
// accepts; empty from an engine older than key rotation.
TrustedKeys []string `json:"trustedKeys,omitempty"`
// ProbeReceipts are the receipts of the operator's probes the engine
// verified where the proxy discards its answer (#475), as its last
// heartbeat reported them: the leader's probe matches them.
ProbeReceipts []string `json:"probeReceipts,omitempty"`
// Replica is the operator replica the engine is connected to.
Replica string `json:"replica"`
ConnectedAt time.Time `json:"connectedAt"`
// contains filtered or unexported fields
}
Engine is what a replica knows about one connected engine.
type GRPCServer ¶
type GRPCServer struct {
Port int
CertDir string
Ready <-chan struct{}
Service agentv1.BundleServiceServer
// contains filtered or unexported fields
}
GRPCServer serves the BundleService over TLS, with the certificate in CertDir (the webhook's), once Ready is closed.
func (*GRPCServer) Check ¶
func (g *GRPCServer) Check(*http.Request) error
Check is a readiness check: the server is listening.
func (*GRPCServer) NeedLeaderElection ¶
func (*GRPCServer) NeedLeaderElection() bool
NeedLeaderElection implements LeaderElectionRunnable: every replica serves.
type Identity ¶
type Identity struct {
// ServiceAccount as "namespace/name".
ServiceAccount string
// The pod the token is bound to, if it is.
PodNamespace string
PodName string
}
Identity is an authenticated engine.
type KubeAuthenticator ¶
type KubeAuthenticator struct {
Client client.Client
// Namespace is the operator's, where the bundle Secret is.
Namespace string
// TTL caches a successful check, so reconnecting engines don't each
// cost two API calls. Revoking access takes effect after at most TTL.
TTL time.Duration
Now func() time.Time
// contains filtered or unexported fields
}
KubeAuthenticator checks tokens with TokenReview, and authorizes them with a SubjectAccessReview for reading the bundle Secret.
func (*KubeAuthenticator) Authenticate ¶
Authenticate implements Authenticator.
type Publisher ¶
type Publisher struct {
Client client.Client
// Reader reads uncached: the manager only caches ConfigMaps of rules.
Reader client.Reader
Namespace string
Replica string
// Owner, if set, is the replica's Pod: its ConfigMap goes with it.
Owner *metav1.OwnerReference
Engines *Table
Interval time.Duration
Refresh time.Duration
}
Publisher writes a replica's engines to its ConfigMap when they change, and at least every Refresh, so the leader can tell a live replica from a dead one.
func (*Publisher) NeedLeaderElection ¶
NeedLeaderElection implements LeaderElectionRunnable.
type Reporter ¶
type Reporter struct {
Client client.Client
// Reader reads the reports uncached (the manager doesn't cache them).
Reader client.Reader
Namespace string
Interval time.Duration
// Stale is how old a replica's report may be before it is ignored.
Stale time.Duration
// Store has the bundle being served, for the engine metrics.
Store *Store
// Served maps policies to the pods that serve them; nil: every engine
// counts for every policy.
Served *ServedPods
// ConfigEvery is the least time between two writes of the engine
// counts to the InkwallConfig's status, so engines connecting don't
// churn it; 0: DefaultConfigEvery.
ConfigEvery time.Duration
// Gone is how long an engine that disconnected, and reports no pod,
// still holds back the policies it counts for, while it hasn't run
// their current version (#675): it serves the bundle it last ran until
// it reconnects. For a policy whose pods aren't known (raw Envoy, the
// standalone proxy), nothing else tells that it is missing. An engine
// that reports its pod holds them back while the pod exists, however
// long it is away (#695). 0: DefaultGone.
Gone time.Duration
// Now is the clock; nil: time.Now.
Now func() time.Time
// contains filtered or unexported fields
}
Reporter writes the Enforced condition of every policy. It runs on the leader, from the replicas' engine reports.
func (*Reporter) NeedLeaderElection ¶
NeedLeaderElection implements LeaderElectionRunnable.
type ServedPod ¶ added in v0.6.0
type ServedPod struct {
// Integration runs the pod's proxy.
Integration string
// Engine: the pod is running, with the engine container, so an engine
// of it is expected to be connected.
Engine bool
}
ServedPod is a pod that serves a policy's routes.
type ServedPods ¶ added in v0.5.0
type ServedPods struct {
// contains filtered or unexported fields
}
ServedPods are the proxy pods that serve each policy's routes, from the wiring's results, so that only their engines count for its Enforced condition (#371). The wiring controller sets them at each reconcile; the Reporter reads them. Both run on the leader.
It fails safe: a policy whose pods aren't known counts every engine, and an engine counts for every policy when it reports no pod, or when its pod isn't one any policy is mapped to (a pod the wiring hasn't seen yet). A running pod with the engine container whose engine isn't connected holds its policies back (#652): until it reconnects, it may serve an older bundle.
type Server ¶
type Server struct {
agentv1.UnimplementedBundleServiceServer
Bundles *Store
Engines *Table
Auth Authenticator
// Replica names this operator replica in the engine records.
Replica string
Log logr.Logger
HelloTimeout time.Duration
IdleTimeout time.Duration
// Events receives the engines' security events, stamped with the
// stream's engine and pod. Nil: they are counted and discarded.
Events func(*eventsv1.EventBatch)
// Stats receives what the engines counted per policy since their
// previous report. Nil: discarded.
Stats func([]*eventsv1.PolicyStats)
// contains filtered or unexported fields
}
Server implements BundleService.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store holds the current bundle and tells streams when it changes.
func (*Store) Current ¶
func (s *Store) Current() (*bundlev1.SignedBundle, uint64, <-chan struct{})
Current returns the current bundle (nil before the first), its version, and a channel closed when it is replaced.
func (*Store) HasPolicy ¶ added in v0.3.0
HasPolicy reports whether the current bundle has the policy id.
func (*Store) PolicyVersion ¶ added in v0.3.1
PolicyVersion returns the first bundle that enforces the policy id as the current bundle does; 0 if it doesn't have it.
func (*Store) Set ¶
func (s *Store) Set(signed *bundlev1.SignedBundle, version uint64)
Set makes signed, of version, the current bundle.
func (*Store) SetPolicies ¶ added in v0.3.0
SetPolicies records the current bundle's policies, the only ones whose request counts are taken from engines, with the first bundle that enforces each as it is now; and whether the bundle suspends inspection.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is a replica's connected engines.
func (*Table) Connect ¶
Connect records a new stream for the engine e under key (Key), replacing an older one, and returns the connection to pass to Update and Disconnect.
func (*Table) Disconnect ¶
Disconnect forgets the record of key if conn still owns it.