distribution

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: 45 Imported by: 0 modules, 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 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

View Source
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.

View Source
const (
	ReasonEnforced      = "Enforced"
	ReasonEnginesBehind = "EnginesBehind"
	ReasonEngineNack    = "EngineNack"
	ReasonNoEngines     = "NoEngines"
	ReasonNotInBundle   = "NotInBundle"
)

Reasons of the Enforced condition.

View Source
const Audience = "inkwall-operator"

Audience is the token audience engines request.

View Source
const (
	EnginesLabel = "waf.inkwall.dev/engines"
)

Report labels and keys of the replicas' engine ConfigMaps.

Variables

View Source
var (
	ErrUnauthenticated = errors.New("not authenticated")
	ErrForbidden       = errors.New("not allowed to read the bundle")
)

Errors of Authenticate.

Functions

func Enforced

func Enforced(version int64, engines []Engine) (metav1.ConditionStatus, string, string)

Enforced computes a policy's Enforced condition: whether every connected engine runs a bundle that contains the policy's current generation (status.bundleVersion). Every engine gets the same bundle, so every engine counts until engines are matched to the routes they serve.

func Ready

func Ready(conds []metav1.Condition, generation int64) metav1.Condition

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.

Types

type Authenticator

type Authenticator interface {
	Authenticate(ctx context.Context, token string) (Identity, error)
}

Authenticator checks an engine's bearer token.

type BundleSource

type BundleSource struct {
	Client    client.Client
	Namespace string
	Store     *Store
}

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"`
	// 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.

func (*GRPCServer) Start

func (g *GRPCServer) Start(ctx context.Context) error

Start implements manager.Runnable.

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

func (a *KubeAuthenticator) Authenticate(ctx context.Context, token string) (Identity, error)

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

func (*Publisher) NeedLeaderElection() bool

NeedLeaderElection implements LeaderElectionRunnable.

func (*Publisher) Start

func (p *Publisher) Start(ctx context.Context) error

Start implements manager.Runnable.

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

func (*Reporter) NeedLeaderElection() bool

NeedLeaderElection implements LeaderElectionRunnable.

func (*Reporter) Start

func (r *Reporter) Start(ctx context.Context) error

Start implements manager.Runnable.

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
	// contains filtered or unexported fields
}

Server implements BundleService.

func NewServer

func NewServer(bundles *Store, engines *Table, auth Authenticator, replica string, log logr.Logger) *Server

NewServer returns a Server with the defaults.

func (*Server) Watch

func (s *Server) Watch(stream agentv1.BundleService_WatchServer) error

Watch serves one engine: Hello, then the current bundle and every new one, while recording its acks, nacks and heartbeats.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store holds the current bundle and tells streams when it changes.

func NewStore

func NewStore() *Store

NewStore returns an empty store.

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

func (s *Store) Set(signed *bundlev1.SignedBundle, version uint64)

Set makes signed, of version, the current bundle.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is a replica's connected engines.

func NewTable

func NewTable() *Table

NewTable returns an empty table.

func (*Table) Connect

func (t *Table) Connect(e Engine) uint64

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

func (t *Table) Disconnect(id string, conn uint64)

Disconnect forgets the engine id if conn still owns its record.

func (*Table) Snapshot

func (t *Table) Snapshot() ([]Engine, uint64)

Snapshot returns the engines sorted by ID, and a generation that changes whenever the table does.

func (*Table) Update

func (t *Table) Update(id string, f func(*Engine) bool)

Update changes the engine with id, if it is connected; f reports whether it changed anything.

Jump to

Keyboard shortcuts

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