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) (metav1.ConditionStatus, 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 Server
- type Store
- 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" ReasonEngineNack = "EngineNack" ReasonNoEngines = "NoEngines" ReasonNotInBundle = "NotInBundle" )
Reasons of the Enforced condition.
const Audience = "inkwall-operator"
Audience is the token audience engines request.
const (
EnginesLabel = "waf.inkwall.dev/engines"
)
Report labels and keys of the replicas' engine ConfigMaps.
Variables ¶
var ( ErrUnauthenticated = errors.New("not authenticated") ErrForbidden = errors.New("not allowed to read the bundle") )
Errors of Authenticate.
Functions ¶
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"`
// 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.
func ReadEngines ¶
func ReadEngines(ctx context.Context, c client.Reader, namespace string, stale time.Duration, now time.Time) ([]Engine, error)
ReadEngines merges the replicas' reports, skipping those not refreshed within stale (their replica is gone). An engine listed twice, while it moves between replicas, counts once, with its newest connection.
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
}
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 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)
// 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.
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.ID, replacing an older one, and returns the connection to pass to Disconnect.
func (*Table) Disconnect ¶
Disconnect forgets the engine id if conn still owns its record.