webhook

package
v0.7.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 53 Imported by: 1 module, 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 webhook holds the operator's admission webhooks. The validating webhook checks what the CRD schemas can't (0004 §3.1, level 2): rule sets must compile the way the engine loads them, and policy paths must be ones the engine's router can match. In Managed mode it also keeps the control plane's policies to the operator (SourceGuard), and warns about the InkwallConfig's deprecated fields.

Index

Constants

View Source
const (
	PodWebhookName             = "pods.waf.inkwall.dev"
	HAProxyPodWebhookName      = "haproxy.pods.waf.inkwall.dev"
	IstioIngressPodWebhookName = "istio-ingress.pods.waf.inkwall.dev"
)

PodWebhookName is the Pod webhook in MutatingConfigName, for Traefik's pods; HAProxyPodWebhookName, the same handler for the HAProxy Kubernetes Ingress Controller's, and IstioIngressPodWebhookName for Istio's ingress gateways' (a webhook has one objectSelector). Istio's own injector rewrites its pods too: that webhook is called again (reinvocationPolicy IfNeeded) to mount the engine's socket in istio-proxy if that mount was lost.

View Source
const AuditMessage = "policy change"

AuditMessage is the audit log line's message.

View Source
const InjectPath = "/mutate-v1-pod"

InjectPath is the Pod webhook's path.

View Source
const MutatingConfigName = "inkwall-operator-mutating"

MutatingConfigName is the MutatingWebhookConfiguration of the Pod webhook; the certificate rotator injects its CA bundle.

View Source
const PolicyWebhookName = "wafpolicies.waf.inkwall.dev"

PolicyWebhookName is the WAFPolicy webhook in ValidatingConfigName.

View Source
const Redacted = "<redacted>"

Redacted replaces a value the audit record never shows.

View Source
const ValidatingConfigName = "inkwall-operator-validating"

ValidatingConfigName is the ValidatingWebhookConfiguration the webhooks below are registered in; the certificate rotator injects its CA bundle.

Variables

PodWebhooks are the Pod webhooks, each with its integration.

Functions

func AddCertRotator

func AddCertRotator(mgr manager.Manager, o CertOptions, ready chan struct{}) error

AddCertRotator keeps a self-signed CA and serving certificate in the Secret, writes the certificate to CertDir and injects the CA into the validating webhook configuration, renewing them before they expire. ready is closed once the certificate files are in place and the CA is injected. It runs on every replica, so each one can serve; the replicas share the Secret. The Secret must exist (EnsureCertSecret).

func EnsureCertSecret

func EnsureCertSecret(ctx context.Context, c client.Client, key types.NamespacedName) error

EnsureCertSecret creates the empty certificate Secret if it doesn't exist; the rotator only fills an existing one. It runs before the manager starts, so it uses a direct client.

func OperatorUser added in v0.1.1

func OperatorUser(ctx context.Context, c client.Client) (string, error)

OperatorUser asks the API server who the operator is (SelfSubjectReview, which every authenticated user may ask), so the guard knows its writes whatever its ServiceAccount is called.

func ServiceDNSNames

func ServiceDNSNames(service, namespace string) []string

ServiceDNSNames returns the names of a Service, for CertOptions.DNSNames.

func Setup

func Setup(mgr manager.Manager, inject *PodInjector, guard *SourceGuard, audit *Auditor) error

Setup registers the validating webhooks with mgr's webhook server, and the Pod webhook when inject is set. guard keeps the control plane's objects to the operator; audit records the changes the webhooks admit (nil: none).

Types

type Auditor

type Auditor struct {
	// Log gets one AuditMessage line per change, at Info.
	Log logr.Logger
	// Events creates one Event (events.k8s.io/v1) on the object for each
	// change, of its own: never a series, which an event recorder would
	// make of two users' changes, under the first one's note. Nil: none.
	Events EventWriter
	// Instance names this replica in the Events (reportingInstance).
	Instance string
	// EventLimit, if set, limits the Events of each namespace: a burst of
	// changes, e.g. a GitOps sync of many objects, records Events up to it,
	// and is logged and counted in full.
	EventLimit *EventLimiter
	// Operator is the user the operator writes as (OperatorUser): its
	// changes are marked operator: true.
	Operator string
	// contains filtered or unexported fields
}

Auditor records the changes the validating webhooks admit.

type CertOptions

type CertOptions struct {
	// Secret holds the CA and the serving certificate, shared by every
	// replica.
	Secret types.NamespacedName
	// CertDir is where the certificate files are written for the webhook
	// server.
	CertDir string
	// DNSNames are the names the certificate is valid for: the webhook
	// Service's, and the distribution Service's.
	DNSNames []string
	// ControllerName names the rotator's controller; "": cert-rotator.
	// controller-runtime refuses two controllers of the same name in a
	// process, whatever its manager's SkipNameValidation (the rotator's
	// controller isn't the manager's).
	ControllerName string
	// InjectWebhooks injects the CA into the validating webhook
	// configuration; off when the webhook is disabled.
	InjectWebhooks bool
	// InjectPodWebhook also injects it into the mutating configuration of
	// the Pod webhook.
	InjectPodWebhook bool
}

CertOptions configures the webhook's serving certificate.

type Change

type Change struct {
	// Path is the field's, e.g. spec.mode or spec.skip.paths.
	Path string `json:"path"`
	// Old and New are a scalar's values, cut to maxValue bytes, or {} for
	// an empty object; absent: unset.
	Old string `json:"old,omitempty"`
	New string `json:"new,omitempty"`
	// Added and Removed count a list's items added and removed;
	// AddedItems and RemovedItems show the first maxItems, as JSON, each
	// cut to maxItem bytes.
	Added        int      `json:"added,omitempty"`
	Removed      int      `json:"removed,omitempty"`
	AddedItems   []string `json:"addedItems,omitempty"`
	RemovedItems []string `json:"removedItems,omitempty"`
	// Reordered: the list holds the same items in another order.
	Reordered bool `json:"reordered,omitempty"`
}

Change is one changed field of the spec, or one changed list.

func Summarize

func Summarize(oldSpec, newSpec any) (changes []Change, omitted int, paths []string)

Summarize compares two specs as generic JSON (nil: none, on create or delete), and returns the changes that fit in maxChanges bytes, how many more there were, and the first maxNotePaths changed paths. Values are redacted (fieldMode).

type EventLimiter

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

EventLimiter limits the audit Events of each namespace on its own (the cluster-scoped objects' as one more), so a burst in one namespace leaves the others theirs. It tracks up to a bound of namespaces: past it, the namespaces it doesn't track share one limit.

func NewEventLimiter

func NewEventLimiter(perSecond float64, burst, namespaces int) *EventLimiter

NewEventLimiter limits each namespace's Events to perSecond, burst at once, tracking up to namespaces of them.

func (*EventLimiter) Allow

func (l *EventLimiter) Allow(namespace string, now time.Time) bool

Allow reports whether an Event in namespace ("" for a cluster-scoped object) may be created at now, and takes its token; a nil EventLimiter allows every one.

type EventWriter

type EventWriter interface {
	Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
}

EventWriter creates the audit Events: a client.Client.

type PodInjector

type PodInjector struct {
	// Client reads the InkwallConfig.
	Client client.Reader
	// Decoder decodes pods.
	Decoder admission.Decoder
	// Image and PullPolicy are the engine's, unless InkwallConfig sets one.
	Image      string
	PullPolicy corev1.PullPolicy
	// PullSecrets are added to the pod's imagePullSecrets.
	PullSecrets []string
	// OperatorAddr is the distribution server engines connect to.
	OperatorAddr string
	// Integrations recognise proxy pods; nil: the defaults.
	Integrations *integrations.Selectors
	// Namespaces are the proxy namespaces: a pod elsewhere isn't a proxy
	// pod, whatever its labels (the webhook's namespaceSelector leaves it
	// out already).
	Namespaces integrations.Namespaces
	// Disabled are the integrations the operator may not wire, by name
	// (0004 §7): their pods don't get the engine.
	Disabled map[string]string
	// BundleSecret is the bundle Secret, namespace/name, engines read when
	// the operator is unreachable.
	BundleSecret string
}

PodInjector adds the engine to proxy pods.

func (*PodInjector) Handle

Handle injects the engine into a pod of a known proxy.

type Record

type Record struct {
	Operation       string
	Kind            string
	Namespace       string
	Name            string
	UID             string
	Generation      int64
	ResourceVersion string
	User            string
	Groups          []string
	GroupsOmitted   int
	ServiceAccount  string
	Operator        bool
	Changes         []Change
	ChangesOmitted  int
	// Paths are the first maxNotePaths changed paths, the omitted ones
	// too.
	Paths []string
}

Record is one audit record: who changed what, how.

type SourceGuard added in v0.1.1

type SourceGuard struct {
	// Operator is the user the operator writes as (OperatorUser).
	Operator string
	// Reader reads the InkwallConfig, whose mode decides.
	Reader client.Reader
}

SourceGuard keeps the control plane's objects, labelled inkwall.dev/source: saas, to the operator while the cluster is in Managed mode (0004 §4.9): no one else may create, change or delete them, or add or remove the label. In the other modes the operator doesn't write them, so they are ordinary objects again, which their owners can clean up.

Jump to

Keyboard shortcuts

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