Skip to content

Commit 629deec

Browse files
committed
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 <[email protected]>
1 parent ee0306b commit 629deec

4 files changed

Lines changed: 163 additions & 0 deletions

File tree

‎packages/system/ingress-nginx/Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ update:
1616
patch --no-backup-if-mismatch -p4 < patches/disable-ca-key-rotation.patch
1717
rm -f charts/ingress-nginx/templates/controller-deployment.yaml.orig
1818
rm -rf charts/ingress-nginx/changelog/
19+
20+
# --with-subchart=false: the vendored chart carries upstream's own suites, which
21+
# assert against upstream default values and fail under the overrides in our
22+
# values.yaml. They are upstream's contract, not ours; run only our own.
23+
test:
24+
helm unittest --with-subchart=false .
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{{- if .Values.admissionWebhookPolicy.enabled }}
2+
{{- $inc := index .Values "ingress-nginx" | default dict }}
3+
{{- $webhookPort := dig "controller" "admissionWebhooks" "port" 8443 $inc }}
4+
---
5+
# The ingress-nginx admission webhook only ever needs to be reachable by the
6+
# API server. Leaving it reachable from every pod in the cluster is avoidable
7+
# attack surface: any flaw in the webhook then becomes exploitable by any
8+
# workload in any namespace, which is precisely what made CVE-2025-1974
9+
# (IngressNightmare) critical rather than merely serious.
10+
#
11+
# This policy is deny-only and explicitly disables default-deny. A Cilium rule
12+
# that carries an ingress section normally puts the selected endpoints behind a
13+
# default-deny, which here would mean enumerating every port the controller
14+
# serves (80, 443, metrics, the protobuf exporter, any tcp/udp services) and
15+
# silently breaking traffic on the first one forgotten. With
16+
# enableDefaultDeny.ingress=false the rule only subtracts access to the webhook
17+
# port and leaves everything else exactly as it was.
18+
#
19+
# Two legitimate callers are carved out of the deny:
20+
#
21+
# * host-network sources, which are not Cilium endpoints and so are never
22+
# matched by fromEndpoints. This covers a management cluster, where the
23+
# kube-apiserver runs on the host network.
24+
#
25+
# * the konnectivity agent. For a Kamaji-hosted tenant cluster the API server
26+
# lives outside the cluster and reaches in-cluster webhooks through the
27+
# konnectivity tunnel: Kamaji defines only the "cluster" egress selection
28+
# (internal/resources/konnectivity/egress_selector_configuration_resource.go),
29+
# and webhook calls fall under it. The connection therefore leaves the
30+
# tunnel from the agent pod in kube-system, not from the API server address,
31+
# so a fromEntities[kube-apiserver] allow would not match it and every
32+
# Ingress create/update in the tenant cluster would start failing.
33+
apiVersion: cilium.io/v2
34+
kind: CiliumNetworkPolicy
35+
metadata:
36+
name: ingress-nginx-admission-webhook
37+
namespace: {{ .Release.Namespace }}
38+
spec:
39+
endpointSelector:
40+
matchLabels:
41+
app.kubernetes.io/name: ingress-nginx
42+
app.kubernetes.io/component: controller
43+
enableDefaultDeny:
44+
ingress: false
45+
egress: false
46+
ingressDeny:
47+
# Every pod in the cluster except the konnectivity agent. The namespace key
48+
# is matched with Exists so the rule spans all namespaces: a plain
49+
# fromEndpoints in a namespaced CiliumNetworkPolicy would only ever select
50+
# pods sharing this policy's namespace.
51+
- fromEndpoints:
52+
- matchExpressions:
53+
- key: k8s:io.kubernetes.pod.namespace
54+
operator: Exists
55+
- key: k8s-app
56+
operator: NotIn
57+
values:
58+
- konnectivity-agent
59+
toPorts:
60+
- ports:
61+
- port: {{ $webhookPort | quote }}
62+
protocol: TCP
63+
- fromEntities:
64+
- world
65+
toPorts:
66+
- ports:
67+
- port: {{ $webhookPort | quote }}
68+
protocol: TCP
69+
{{- end }}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
suite: ingress-nginx admission webhook exposure
2+
release:
3+
name: ingress-nginx
4+
namespace: cozy-ingress-nginx
5+
templates:
6+
- templates/admission-webhook-networkpolicy.yaml
7+
tests:
8+
- it: denies pod traffic to the admission webhook port
9+
# :8443 is the admission webhook. Reachability from arbitrary pods is what
10+
# turned CVE-2025-1974 from a webhook bug into unauthenticated in-cluster
11+
# RCE, so the deny on this port is the whole point of the policy.
12+
asserts:
13+
- equal:
14+
path: spec.ingressDeny[0].toPorts[0].ports[0].port
15+
value: "8443"
16+
- equal:
17+
path: spec.ingressDeny[0].toPorts[0].ports[0].protocol
18+
value: TCP
19+
20+
- it: spans every namespace rather than only the release namespace
21+
# A bare fromEndpoints in a namespaced CiliumNetworkPolicy selects only
22+
# pods in the policy's own namespace, which would leave the webhook open
23+
# to every other namespace — the exact gap being closed here.
24+
asserts:
25+
- contains:
26+
path: spec.ingressDeny[0].fromEndpoints[0].matchExpressions
27+
content:
28+
key: k8s:io.kubernetes.pod.namespace
29+
operator: Exists
30+
31+
- it: exempts the konnectivity agent so tenant-cluster admission keeps working
32+
# On a Kamaji-hosted tenant cluster the API server is outside the cluster
33+
# and reaches webhooks through the konnectivity tunnel, so the connection
34+
# originates from the agent pod. Denying it would make every Ingress
35+
# create/update in the tenant cluster fail on the webhook call.
36+
asserts:
37+
- contains:
38+
path: spec.ingressDeny[0].fromEndpoints[0].matchExpressions
39+
content:
40+
key: k8s-app
41+
operator: NotIn
42+
values:
43+
- konnectivity-agent
44+
45+
- it: denies world traffic to the admission webhook port
46+
asserts:
47+
- contains:
48+
path: spec.ingressDeny[1].fromEntities
49+
content: world
50+
- equal:
51+
path: spec.ingressDeny[1].toPorts[0].ports[0].port
52+
value: "8443"
53+
54+
- it: does not put the controller behind a default deny
55+
# The controller also serves 80/443, metrics and the protobuf exporter.
56+
# Enabling default-deny here would require enumerating all of them and
57+
# would break traffic on the first one omitted.
58+
asserts:
59+
- equal:
60+
path: spec.enableDefaultDeny.ingress
61+
value: false
62+
- equal:
63+
path: spec.enableDefaultDeny.egress
64+
value: false
65+
- isNull:
66+
path: spec.ingress
67+
68+
- it: selects only the controller pods
69+
asserts:
70+
- equal:
71+
path: spec.endpointSelector.matchLabels["app.kubernetes.io/component"]
72+
value: controller
73+
- equal:
74+
path: spec.endpointSelector.matchLabels["app.kubernetes.io/name"]
75+
value: ingress-nginx
76+
77+
- it: can be disabled
78+
set:
79+
admissionWebhookPolicy.enabled: false
80+
asserts:
81+
- hasDocuments:
82+
count: 0

‎packages/system/ingress-nginx/values.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,9 @@ ingress-nginx:
102102
cpu: 10m
103103
memory: 20Mi
104104

105+
# Deny pod-to-webhook traffic on the admission port, leaving it reachable only
106+
# by the API server (directly on a management cluster, or through the
107+
# konnectivity agent on a Kamaji-hosted tenant cluster). Requires Cilium.
108+
admissionWebhookPolicy:
109+
enabled: true
110+

0 commit comments

Comments
 (0)