webhook

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package webhook implements the runeward admission webhook enforcing ClusterPolicy defaults and guardrails on Sandbox and Fleet resources. The decision logic (Decide) is a pure function over a policy snapshot; Server wires it to the Kubernetes AdmissionReview contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decide

func Decide(policies []Policy, namespace string, labels map[string]string, profileName string) (allowed bool, mutatedProfile string, reason string)

Decide evaluates an admission request against every policy. If profileName is empty, the first policy with a DefaultProfile supplies it; the effective profile, namespace, and labels are then validated, first violation wins. mutatedProfile always reflects the effective profile, so the caller applies it when it differs from the incoming profileName.

func GenerateCert

func GenerateCert(dnsNames []string) (certPEM, keyPEM, caPEM []byte, err error)

GenerateCert mints an ECDSA CA plus a leaf serving certificate for the supplied DNS names (typically <svc>.<ns>.svc and <svc>.<ns>.svc.cluster.local) and returns PEM blocks: leaf cert, leaf key, and the CA cert to publish in the webhook caBundle.

func LoadOrCreateCert

func LoadOrCreateCert(ctx context.Context, client kubernetes.Interface, namespace, secretName string, dnsNames []string) (certPEM, keyPEM, caPEM []byte, err error)

LoadOrCreateCert returns a serving certificate that is stable across restarts and shared by every webhook replica. It reads the named Secret; if the Secret already holds a complete cert it is reused, otherwise a fresh cert is generated and stored. On a create race (another replica won), the winner's Secret is read back, so all replicas converge on one CA — which is what makes running more than one replica behind the Service safe.

When client is nil (no cluster access) it falls back to an ephemeral, in-memory cert, preserving the previous single-process behavior.

func Register

func Register(ctx context.Context, clientset kubernetes.Interface, caPEM []byte, service, namespace string) error

Register upserts the validating and mutating webhook configurations that route Sandbox/Fleet admission to the given Service. caPEM is published as each webhook's caBundle so the API server trusts the self-signed serving certificate.

Types

type Policy

type Policy struct {
	AllowedProfiles   []string
	DeniedProfiles    []string
	AllowedNamespaces []string
	// RequiredLabels are label keys that must be present on the resource.
	RequiredLabels []string
	// DefaultProfile is applied (mutating) when spec.profile is empty.
	DefaultProfile string
}

Policy mirrors the enforceable fields of a ClusterPolicy spec as a plain value type, so the decision logic can be tested without a cluster. The profile/namespace lists are glob patterns; empty means no constraint.

type Server

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

Server serves the admission webhook endpoints. It lists ClusterPolicies on every request so policy changes take effect without a restart.

func NewServer

func NewServer(dyn dynamic.Interface, logger *log.Logger) *Server

NewServer builds a Server backed by the given dynamic client. A nil logger uses the standard logger.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the HTTP multiplexer exposing /validate, /mutate, and /healthz.

Jump to

Keyboard shortcuts

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