wiring

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 50 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 wiring sends a proxy's protected routes to the engine (0004 §4.4), through one Integration per proxy. For Traefik: an operator-owned ForwardAuth Middleware in each namespace with protected routes, attached to protected Ingresses through Traefik's router.middlewares annotation, to protected IngressRoutes' routes through their middlewares, and to protected HTTPRoutes' rules through an ExtensionRef filter.

Index

Constants

View Source
const (
	ReasonProgrammed            = "Programmed"
	ReasonControllerUnsupported = "ControllerUnsupported"
	ReasonWiringFailed          = "WiringFailed"
	ReasonPendingRestart        = "PendingRestart"
	ReasonSidecarMissing        = "SidecarMissing"
	ReasonNoTargets             = "NoTargets"
	ReasonInjectionDisabled     = "InjectionDisabled"
	ReasonPending               = "Pending"
	// ReasonIntegrationDisabled: the operator may not wire the proxy that
	// serves a target (Disable).
	ReasonIntegrationDisabled = "IntegrationDisabled"
	// ReasonUnwired: `inkwall-operator unwire` (helm uninstall) unwired
	// the routes and stopped the operator.
	ReasonUnwired = "Unwired"
)

Reasons of the Programmed condition.

View Source
const (
	// MiddlewareName is the operator's Middleware in each protected
	// namespace; not "inkwall", so it can't take over one made by hand.
	MiddlewareName = "inkwall-waf"
	// MiddlewaresAnnotation lists an Ingress router's Middlewares.
	MiddlewaresAnnotation = "traefik.ingress.kubernetes.io/router.middlewares"
	// WiredAnnotation marks an Ingress, IngressRoute or HTTPRoute the
	// operator wired, with the Middleware it added (MiddlewareRef on an
	// Ingress, MiddlewareName on the others), so it removes exactly that.
	WiredAnnotation = "waf.inkwall.dev/wired"
)

Names of the Traefik wiring.

View Source
const (
	// EnvoyBackend is the operator's Backend, the engine's socket, in each
	// namespace with protected HTTPRoutes.
	EnvoyBackend = "inkwall-engine"
)

Names of the Envoy Gateway wiring.

View Source
const Finalizer = "waf.inkwall.dev/unwire"

Finalizer holds a WAFPolicy until the operator has unwired its routes, so a policy deleted while the operator is down is unwired once it is back. Only the wiring controller adds it; it and `inkwall-operator unwire` remove it.

Variables

View Source
var (
	EnvoyProxyGVK           = schema.GroupVersionKind{Group: "gateway.envoyproxy.io", Version: "v1alpha1", Kind: "EnvoyProxy"}
	EnvoyExtensionPolicyGVK = schema.GroupVersionKind{Group: "gateway.envoyproxy.io", Version: "v1alpha1", Kind: "EnvoyExtensionPolicy"}
	BackendGVK              = schema.GroupVersionKind{Group: "gateway.envoyproxy.io", Version: "v1alpha1", Kind: "Backend"}
	ClientTrafficPolicyGVK  = schema.GroupVersionKind{Group: "gateway.envoyproxy.io", Version: "v1alpha1", Kind: "ClientTrafficPolicy"}
	// GatewayGVK and HTTPRouteGVK are the Gateway API's, read typed.
	GatewayGVK   = schema.GroupVersionKind{Group: gatewayv1.GroupName, Version: "v1", Kind: "Gateway"}
	HTTPRouteGVK = schema.GroupVersionKind{Group: gatewayv1.GroupName, Version: "v1", Kind: "HTTPRoute"}
	// GatewayClassGVK is read unstructured, as discovery does.
	GatewayClassGVK = schema.GroupVersionKind{Group: gatewayv1.GroupName, Version: "v1", Kind: "GatewayClass"}
)

Envoy Gateway's kinds, read and written unstructured: the operator doesn't depend on Envoy Gateway's Go module.

Functions

func Controller

func Controller(ing *networkingv1.Ingress, classes map[string]string, defaultClass string) string

Controller returns the controller of the IngressClass serving ing, or "" when it can't be told. classes maps class names to their controllers; defaultClass is the class marked default, if any.

func ForwardAuthMatches

func ForwardAuthMatches(m *unstructured.Unstructured) bool

ForwardAuthMatches reports whether a Middleware's spec is the operator's.

func IngressRoutes added in v0.1.1

func IngressRoutes(ctx context.Context, c client.Client) (routes []unstructured.Unstructured, installed bool, err error)

IngressRoutes lists Traefik's IngressRoutes; installed is false, with none, when their CRD isn't.

func IsDefaultClass

func IsDefaultClass(ic *networkingv1.IngressClass) bool

IsDefaultClass reports whether an IngressClass is the cluster default.

func Middleware

func Middleware(namespace string) *unstructured.Unstructured

Middleware returns the operator's Middleware for namespace.

func MiddlewareRef

func MiddlewareRef(namespace string) string

MiddlewareRef is how an Ingress in namespace refers to the operator's Middleware there.

func WithMiddleware

func WithMiddleware(current, ref string) string

WithMiddleware returns the annotation value with ref added (first, so the engine sees the request before other Middlewares change it), unchanged if present.

func WithRouteMiddleware added in v0.1.1

func WithRouteMiddleware(ir *unstructured.Unstructured, want bool) (bool, error)

WithRouteMiddleware adds the operator's Middleware to every route of an IngressRoute (want), first, or removes it from them. A route refers to it by name only: Traefik looks it up in the IngressRoute's namespace, which needs no allowCrossNamespace. The user's Middlewares stay, in order. It reports whether ir changed.

func WithRuleFilter added in v0.3.0

func WithRuleFilter(hr *unstructured.Unstructured, sel rules) (bool, error)

WithRuleFilter adds the operator's Middleware, as an ExtensionRef filter, first to the rules of an HTTPRoute that sel selects, and removes it from the others. The reference has no namespace: Traefik looks the Middleware up in the HTTPRoute's. The user's filters stay, in order. It reports whether hr changed.

func WithoutMiddleware

func WithoutMiddleware(current, ref string) string

WithoutMiddleware returns the annotation value without ref.

Types

type Config added in v0.3.0

type Config struct {
	// Pods select the proxies' pods; nil: the defaults.
	Pods *integrations.Selectors
	// Watches of kinds whose CRD may be missing, once it is installed;
	// nil: only read at each reconcile.
	IngressRoutes, HTTPRoutes, Gateways, GatewayClasses, EnvoyProxies, ExtensionPolicies, TrafficPolicies *crdwatch.Kind
	// Sidecar is the engine Envoy Gateway's pods get, before the
	// InkwallConfig's settings.
	Sidecar injection.Sidecar
}

Config is what the integrations need besides the clients.

type EnvoyGateway added in v0.3.0

type EnvoyGateway struct {
	Client client.Client
	// APIReader reads the operator's objects uncached.
	APIReader client.Reader
	// Pods selects Envoy Gateway's Envoy pods.
	Pods labels.Selector
	// Sidecar is the engine put into the Envoy pods, before the
	// InkwallConfig's engine settings.
	Sidecar injection.Sidecar
	// Watches of kinds whose CRD may be missing; nil: only read at each
	// reconcile.
	HTTPRoutes, Gateways, GatewayClasses, EnvoyProxies, ExtensionPolicies, TrafficPolicies *crdwatch.Kind
}

EnvoyGateway is the wiring of Envoy Gateway: its HTTPRoutes.

func (*EnvoyGateway) Kinds added in v0.3.0

func (*EnvoyGateway) Kinds() []schema.GroupKind

Kinds implements Integration.

func (*EnvoyGateway) Name added in v0.3.0

func (*EnvoyGateway) Name() string

Name implements Integration.

func (*EnvoyGateway) Unwire added in v0.3.0

func (e *EnvoyGateway) Unwire(ctx context.Context, c client.Client) (map[string]int, error)

Unwire implements Integration: the routes stop calling the engine, then the engine leaves the Envoy pods (Envoy Gateway rolls them), and the users' Gateways and EnvoyProxies are as they were.

func (*EnvoyGateway) Watch added in v0.3.0

Watch implements Integration.

func (*EnvoyGateway) Wire added in v0.3.0

func (e *EnvoyGateway) Wire(ctx context.Context, targets map[Target]bool, off bool) (*Result, error)

Wire implements Integration: it puts the engine into the Envoy pods of the Gateways serving protected HTTPRoutes, attaches the engine to those routes once the pods have it, and removes the rest.

func (*EnvoyGateway) Wired added in v0.3.0

func (e *EnvoyGateway) Wired(ctx context.Context, tg Target) (bool, error)

Wired implements Integration: the route has the operator's EnvoyExtensionPolicy.

type Integration added in v0.3.0

type Integration interface {
	// Name is integrations.Integration.Name, e.g. "traefik", and the
	// integration label of the wiring metrics.
	Name() string
	// Kinds are the target kinds it wires.
	Kinds() []schema.GroupKind
	// Watch has c reconcile when what the wiring reads, besides the
	// policies, changes: routes, classes, the proxy's pods, its own
	// objects.
	Watch(c controller.Controller, cache cache.Cache, h handler.EventHandler) error
	// Wire wires the targets (those of the live policies, of its kinds)
	// that its proxy serves, and unwires every other route it wired; with
	// off, it unwires them all. It reports on each target, and on what it
	// couldn't do with an error; a nil Result means it did nothing.
	Wire(ctx context.Context, targets map[Target]bool, off bool) (*Result, error)
	// Wired reports whether a target is still wired, read from the API
	// server: a policy being deleted is released once none of its targets
	// is. A target that doesn't exist isn't.
	Wired(ctx context.Context, t Target) (bool, error)
	// Unwire removes all of its wiring, at uninstall. It counts what it
	// changed, by kind.
	Unwire(ctx context.Context, c client.Client) (map[string]int, error)
}

Integration is the wiring of one proxy (0004 §4.2): the target kinds it wires, how, and what it reports on each target. integrations.Integration describes the same proxy to discovery and injection. The wiring controller runs every integration at each reconcile; several may share a kind (Ingress, HTTPRoute), each wiring the targets its proxy serves.

func Disable added in v0.3.0

func Disable(in Integration, why string, c client.Client, cfg Config) Integration

Disable wraps an integration the operator may not wire, and why (its ClusterRole isn't granted, 0004 §7). The wrapper neither watches nor touches the proxy's objects, which it may not read; it reads only the routes and classes, which every integration may, to report the targets its proxy serves as IntegrationDisabled. It can't unwire them: what it wired before stays wired, and a deleted policy isn't held for it. cfg has the watches of the routes and classes.

func Integrations added in v0.3.0

func Integrations(c client.Client, reader client.Reader, cfg Config) []Integration

Integrations are the wiring of every proxy Inkwall integrates: Traefik and Envoy Gateway.

type Reconciler

type Reconciler struct {
	Client client.Client
	// PodWebhook is the MutatingWebhookConfiguration that injects the
	// engine: a proxy pod created after it without the engine was missed
	// by the webhook (SidecarMissing), one created before it predates
	// Inkwall (PendingRestart).
	PodWebhook string
	// Integrations wire the proxies (Integrations).
	Integrations []Integration
	// Disabled: the engine isn't injected (--inject=false), so new proxy
	// pods won't have it. Every route the operator wired is unwired, and
	// the policies are released from the finalizer.
	Disabled bool
}

Reconciler wires protected routes. It runs on the leader.

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(ctx context.Context, _ reconcile.Request) (reconcile.Result, error)

Reconcile has every integration wire the protected routes of its proxy and unwire the rest, releases the deleted policies once their routes are unwired, and reports Programmed.

func (*Reconciler) SetupWithManager

func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager registers the controller.

type Result added in v0.3.0

type Result struct {
	// Proxy names the proxy in conditions, e.g. "Traefik".
	Proxy string
	// Targets has each target that exists, or that it can't tell about.
	// One that doesn't exist is left out (Accepted reports it).
	Targets map[Target]TargetState
	// Pods are the proxy's pods, whose engine the wired routes go to.
	Pods []corev1.Pod
	// Rolling: the proxy's own controller replaces its pods without the
	// engine (Envoy Gateway, once its EnvoyProxy has it), rather than the
	// Pod webhook injecting new ones; they are PendingRestart.
	Rolling bool
	// Disabled: the integration is disabled, and why (Disable); the
	// targets its proxy serves aren't wired.
	Disabled string
}

Result is what an integration did, for Programmed.

type Target added in v0.3.0

type Target struct {
	Kind schema.GroupKind
	Key  types.NamespacedName
	// Section is an HTTPRoute's rule (sectionName), or "" for the route.
	Section string
}

Target is a route a policy protects.

type TargetState added in v0.3.0

type TargetState struct {
	// Unsupported: its proxy doesn't serve the target, and why (another
	// proxy does, or none). Another integration may.
	Unsupported string
	// Failed: why it couldn't be wired.
	Failed string
	// Wired: the integration keeps the target wired.
	Wired bool
	// Pending: wired, but not in force yet, and why (the proxy hasn't
	// accepted its configuration yet).
	Pending string
	// Partly: it is wired, but some of its traffic goes through proxies
	// Inkwall doesn't wire, and which.
	Partly string
}

TargetState is a target as an integration sees it.

type Traefik added in v0.3.0

type Traefik struct {
	Client client.Client
	// APIReader reads Middlewares and targets uncached.
	APIReader client.Reader
	// Pods selects Traefik's pods (integrations.Selectors).
	Pods labels.Selector
	// Watches of IngressRoutes, HTTPRoutes, Gateways and GatewayClasses,
	// once their CRDs are installed; nil: only read at each reconcile.
	IngressRoutes, HTTPRoutes, Gateways, GatewayClasses *crdwatch.Kind
	// contains filtered or unexported fields
}

Traefik is the wiring of Traefik: its Ingresses, IngressRoutes, and the HTTPRoutes of its Gateway API provider.

func (*Traefik) Kinds added in v0.3.0

func (*Traefik) Kinds() []schema.GroupKind

Kinds implements Integration.

func (*Traefik) Name added in v0.3.0

func (*Traefik) Name() string

Name implements Integration.

func (*Traefik) Unwire added in v0.3.0

func (*Traefik) Unwire(ctx context.Context, c client.Client) (map[string]int, error)

Unwire implements Integration: it removes the operator's Middleware from every Ingress, IngressRoute and HTTPRoute it wired, then deletes the Middlewares.

func (*Traefik) Watch added in v0.3.0

Watch implements Integration.

func (*Traefik) Wire added in v0.3.0

func (t *Traefik) Wire(ctx context.Context, targets map[Target]bool, off bool) (*Result, error)

Wire implements Integration: it wires every protected Traefik Ingress and IngressRoute, and unwires the rest.

func (*Traefik) Wired added in v0.3.0

func (t *Traefik) Wired(ctx context.Context, tg Target) (bool, error)

Wired implements Integration: the target carries WiredAnnotation.

type Unwired added in v0.1.1

type Unwired struct {
	// Objects counts the proxies' objects unwired or deleted, by kind.
	Objects  map[string]int
	Policies int
	// Forbidden are the integrations the operator may not unwire (their
	// ClusterRole isn't granted, as when it disabled them): what they
	// wired, if anything, stays.
	Forbidden []string
}

Unwired counts what Unwire changed.

func Unwire

func Unwire(ctx context.Context, c client.Client) (Unwired, error)

Unwire undoes the wiring at uninstall: every integration removes its wiring, keeping the user's own (for Traefik, the operator's Middleware from every Ingress, IngressRoute and HTTPRoute it wired, then the Middlewares it created). Then every WAFPolicy is reported Programmed=False and Ready=False (Unwired), and released from the finalizer, which no operator will remove any more. The proxies then stop sending those routes to the engine, which a proxy pod started after the uninstall doesn't have. Run it with the operator stopped, or it wires them again.

Jump to

Keyboard shortcuts

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