Documentation
¶
Overview ¶
Package globalwebhook implements a GLOBAL, cluster-aware validating admission webhook: a single ValidatingWebhookConfiguration, supplied to the shard at startup (via --admission-control-config-file, this plugin's config section), that fires for requests in EVERY logical cluster - without a per-workspace WebhookConfiguration object, and tamper-proof against workspace admins.
This is to admission what --authorization-webhook-config-file is to authorization: one endpoint, wired at bootstrap, applied globally. Unlike the authorization webhook it is an ADMISSION webhook, so the callout carries the full object body + operation and can DENY. The request's logical cluster is conveyed on the object via the kcp.io/cluster annotation (like kcp's per- cluster webhook plugin), stamped here for create/update (object) and delete (oldObject) so the external webhook is cluster-aware on every operation.
Configure it by putting a normal ValidatingWebhookConfiguration in this plugin's admission-config section (see docs/content/...); leave it unset and the plugin is inert. Only URL clientConfig with a caBundle is required - no per-cluster objects, no APIBindings.
Why only kcp.io/cluster, and not kcp.io/path?
Stamping the canonical workspace path as well would spare webhooks a front-proxy-style path cache, but there is no source that yields a correct path on EVERY request this plugin sees, and a wrong or missing path is worse than none:
- root and system:shard: their LogicalCluster objects carry no kcp.io/path annotation, so the path would have to be derived from the name.
- system:admin, system:system-crds, system, ...: no LogicalCluster object exists at all, so a lister lookup always misses.
- freshly created workspaces: writes from initializers and child bootstrapping race the local LogicalCluster informer, so the lookup misses for a short window after creation.
- the LogicalCluster create itself: the object does not exist yet.
Falling back to the cluster name in those cases is right for root/system:* (name == path) but hands webhook authors a hash as a "path" for workspace clusters in the race window; failing closed there breaks workspace bootstrap; omitting the annotation only sometimes makes it unreliable to program against. Webhooks that need the path can resolve it from the cluster name via the LogicalCluster (or the front-proxy index) themselves.
Index ¶
- Constants
- func Register(plugins *admission.Plugins)
- type Plugin
- func (p *Plugin) SetKubeClusterClient(client kcpkubernetesclientset.ClusterInterface)
- func (p *Plugin) SetKubeInformers(local, global kcpkubernetesinformers.SharedInformerFactory)
- func (p *Plugin) Validate(ctx context.Context, attr admission.Attributes, o admission.ObjectInterfaces) error
- func (p *Plugin) ValidateInitialization() error
Constants ¶
const (
// PluginName is the admission plugin name.
PluginName = "apis.kcp.io/GlobalValidatingWebhook"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Plugin ¶
Plugin is a global, cluster-aware validating admission webhook. It holds a static webhook source parsed once from its admission config; when that config is absent it is inert.
func NewGlobalValidatingWebhook ¶
NewGlobalValidatingWebhook parses the plugin config (a ValidatingWebhookConfiguration) into a static source. An empty config yields an inert plugin.
func (*Plugin) SetKubeClusterClient ¶
func (p *Plugin) SetKubeClusterClient(client kcpkubernetesclientset.ClusterInterface)
SetKubeClusterClient implements WantsKubeClusterClient.
func (*Plugin) SetKubeInformers ¶
func (p *Plugin) SetKubeInformers(local, global kcpkubernetesinformers.SharedInformerFactory)
SetKubeInformers implements WantsKubeInformers. Only the local factory is used (namespace informer); the source is static, so no global config informer.
func (*Plugin) Validate ¶
func (p *Plugin) Validate(ctx context.Context, attr admission.Attributes, o admission.ObjectInterfaces) error
Validate dispatches the admission request to the globally-configured webhook, with the request's logical cluster stamped on the object so the external webhook is cluster-aware.
func (*Plugin) ValidateInitialization ¶
ValidateInitialization ensures required dependencies were injected.