mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-22 12:43:32 +09:00
feat(ingress-nginx): restrict the admission webhook to the API server
The admission webhook is only ever called by the API server, but it was reachable from every pod in the cluster, in any namespace. That is avoidable attack surface: any flaw in the webhook becomes exploitable by any workload, which is what separated CVE-2025-1974 from an ordinary webhook bug. The rule is deny-only and disables default-deny. Any Cilium rule with an ingress section otherwise puts the selected endpoints behind a default-deny, which here would mean enumerating every port the controller serves and breaking traffic on the first one missed. Host-network sources are not Cilium endpoints, so a management cluster's API server is unaffected. Tenant clusters need an explicit carve-out instead: Kamaji places the API server outside the cluster and defines only the "cluster" egress selection, so webhook calls arrive from the konnectivity agent pod rather than from the API server address, and denying it would fail every Ingress create/update in the tenant cluster. Assisted-By: Claude Signed-off-by: Andrei Kvapil <andrei.kvapil@aenix.io>
This commit is contained in:
4 files changed
+163
No files matched your search
@@ -16,3 +16,9 @@ update:
|
||||
patch --no-backup-if-mismatch -p4 < patches/disable-ca-key-rotation.patch
|
||||
rm -f charts/ingress-nginx/templates/controller-deployment.yaml.orig
|
||||
rm -rf charts/ingress-nginx/changelog/
|
||||
|
||||
# --with-subchart=false: the vendored chart carries upstream's own suites, which
|
||||
# assert against upstream default values and fail under the overrides in our
|
||||
# values.yaml. They are upstream's contract, not ours; run only our own.
|
||||
test:
|
||||
helm unittest --with-subchart=false .
|
||||
@@ -0,0 +1,69 @@
|
||||
{{- if .Values.admissionWebhookPolicy.enabled }}
|
||||
{{- $inc := index .Values "ingress-nginx" | default dict }}
|
||||
{{- $webhookPort := dig "controller" "admissionWebhooks" "port" 8443 $inc }}
|
||||
---
|
||||
# The ingress-nginx admission webhook only ever needs to be reachable by the
|
||||
# API server. Leaving it reachable from every pod in the cluster is avoidable
|
||||
# attack surface: any flaw in the webhook then becomes exploitable by any
|
||||
# workload in any namespace, which is precisely what made CVE-2025-1974
|
||||
# (IngressNightmare) critical rather than merely serious.
|
||||
#
|
||||
# This policy is deny-only and explicitly disables default-deny. A Cilium rule
|
||||
# that carries an ingress section normally puts the selected endpoints behind a
|
||||
# default-deny, which here would mean enumerating every port the controller
|
||||
# serves (80, 443, metrics, the protobuf exporter, any tcp/udp services) and
|
||||
# silently breaking traffic on the first one forgotten. With
|
||||
# enableDefaultDeny.ingress=false the rule only subtracts access to the webhook
|
||||
# port and leaves everything else exactly as it was.
|
||||
#
|
||||
# Two legitimate callers are carved out of the deny:
|
||||
#
|
||||
# * host-network sources, which are not Cilium endpoints and so are never
|
||||
# matched by fromEndpoints. This covers a management cluster, where the
|
||||
# kube-apiserver runs on the host network.
|
||||
#
|
||||
# * the konnectivity agent. For a Kamaji-hosted tenant cluster the API server
|
||||
# lives outside the cluster and reaches in-cluster webhooks through the
|
||||
# konnectivity tunnel: Kamaji defines only the "cluster" egress selection
|
||||
# (internal/resources/konnectivity/egress_selector_configuration_resource.go),
|
||||
# and webhook calls fall under it. The connection therefore leaves the
|
||||
# tunnel from the agent pod in kube-system, not from the API server address,
|
||||
# so a fromEntities[kube-apiserver] allow would not match it and every
|
||||
# Ingress create/update in the tenant cluster would start failing.
|
||||
apiVersion: cilium.io/v2
|
||||
kind: CiliumNetworkPolicy
|
||||
metadata:
|
||||
name: ingress-nginx-admission-webhook
|
||||
namespace: {{ .Release.Namespace }}
|
||||
spec:
|
||||
endpointSelector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: ingress-nginx
|
||||
app.kubernetes.io/component: controller
|
||||
enableDefaultDeny:
|
||||
ingress: false
|
||||
egress: false
|
||||
ingressDeny:
|
||||
# Every pod in the cluster except the konnectivity agent. The namespace key
|
||||
# is matched with Exists so the rule spans all namespaces: a plain
|
||||
# fromEndpoints in a namespaced CiliumNetworkPolicy would only ever select
|
||||
# pods sharing this policy's namespace.
|
||||
- fromEndpoints:
|
||||
- matchExpressions:
|
||||
- key: k8s:io.kubernetes.pod.namespace
|
||||
operator: Exists
|
||||
- key: k8s-app
|
||||
operator: NotIn
|
||||
values:
|
||||
- konnectivity-agent
|
||||
toPorts:
|
||||
- ports:
|
||||
- port: {{ $webhookPort | quote }}
|
||||
protocol: TCP
|
||||
- fromEntities:
|
||||
- world
|
||||
toPorts:
|
||||
- ports:
|
||||
- port: {{ $webhookPort | quote }}
|
||||
protocol: TCP
|
||||
{{- end }}
|
||||
@@ -0,0 +1,82 @@
|
||||
suite: ingress-nginx admission webhook exposure
|
||||
release:
|
||||
name: ingress-nginx
|
||||
namespace: cozy-ingress-nginx
|
||||
templates:
|
||||
- templates/admission-webhook-networkpolicy.yaml
|
||||
tests:
|
||||
- it: denies pod traffic to the admission webhook port
|
||||
# :8443 is the admission webhook. Reachability from arbitrary pods is what
|
||||
# turned CVE-2025-1974 from a webhook bug into unauthenticated in-cluster
|
||||
# RCE, so the deny on this port is the whole point of the policy.
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.ingressDeny[0].toPorts[0].ports[0].port
|
||||
value: "8443"
|
||||
- equal:
|
||||
path: spec.ingressDeny[0].toPorts[0].ports[0].protocol
|
||||
value: TCP
|
||||
|
||||
- it: spans every namespace rather than only the release namespace
|
||||
# A bare fromEndpoints in a namespaced CiliumNetworkPolicy selects only
|
||||
# pods in the policy's own namespace, which would leave the webhook open
|
||||
# to every other namespace — the exact gap being closed here.
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.ingressDeny[0].fromEndpoints[0].matchExpressions
|
||||
content:
|
||||
key: k8s:io.kubernetes.pod.namespace
|
||||
operator: Exists
|
||||
|
||||
- it: exempts the konnectivity agent so tenant-cluster admission keeps working
|
||||
# On a Kamaji-hosted tenant cluster the API server is outside the cluster
|
||||
# and reaches webhooks through the konnectivity tunnel, so the connection
|
||||
# originates from the agent pod. Denying it would make every Ingress
|
||||
# create/update in the tenant cluster fail on the webhook call.
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.ingressDeny[0].fromEndpoints[0].matchExpressions
|
||||
content:
|
||||
key: k8s-app
|
||||
operator: NotIn
|
||||
values:
|
||||
- konnectivity-agent
|
||||
|
||||
- it: denies world traffic to the admission webhook port
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.ingressDeny[1].fromEntities
|
||||
content: world
|
||||
- equal:
|
||||
path: spec.ingressDeny[1].toPorts[0].ports[0].port
|
||||
value: "8443"
|
||||
|
||||
- it: does not put the controller behind a default deny
|
||||
# The controller also serves 80/443, metrics and the protobuf exporter.
|
||||
# Enabling default-deny here would require enumerating all of them and
|
||||
# would break traffic on the first one omitted.
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.enableDefaultDeny.ingress
|
||||
value: false
|
||||
- equal:
|
||||
path: spec.enableDefaultDeny.egress
|
||||
value: false
|
||||
- isNull:
|
||||
path: spec.ingress
|
||||
|
||||
- it: selects only the controller pods
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.endpointSelector.matchLabels["app.kubernetes.io/component"]
|
||||
value: controller
|
||||
- equal:
|
||||
path: spec.endpointSelector.matchLabels["app.kubernetes.io/name"]
|
||||
value: ingress-nginx
|
||||
|
||||
- it: can be disabled
|
||||
set:
|
||||
admissionWebhookPolicy.enabled: false
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
@@ -102,3 +102,9 @@ ingress-nginx:
|
||||
cpu: 10m
|
||||
memory: 20Mi
|
||||
|
||||
# Deny pod-to-webhook traffic on the admission port, leaving it reachable only
|
||||
# by the API server (directly on a management cluster, or through the
|
||||
# konnectivity agent on a Kamaji-hosted tenant cluster). Requires Cilium.
|
||||
admissionWebhookPolicy:
|
||||
enabled: true
|
||||
|
||||
Reference in new issue
Block a user