From 7451d97c147fb4ced752e9efb364b7623d963fed Mon Sep 17 00:00:00 2001 From: IvanHunters Date: Wed, 22 Jul 2026 22:14:57 +0300 Subject: [PATCH] fix(talos-log-collector): add CNI-agnostic NetworkPolicy fallback Vector binds 0.0.0.0 inside the pod netns and exposes it as a containerPort, so any pod could reach : and inject forged talos_system log lines. The ingress restriction is therefore load-bearing, not defence-in-depth as the comment claimed. The CiliumNetworkPolicy only rendered when the Cilium CRD was present, leaving the receiver unprotected on non-Cilium variants (e.g. isp-hosted / noop networking). Correct the comment and, when the Cilium CRD is absent, fall back to a default-deny-ingress networking.k8s.io/v1 NetworkPolicy so the socket is never offered without protection. Signed-off-by: IvanHunters --- .../templates/networkpolicy.yaml | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/packages/system/talos-log-collector/templates/networkpolicy.yaml b/packages/system/talos-log-collector/templates/networkpolicy.yaml index c348ea8b6..707b7d080 100644 --- a/packages/system/talos-log-collector/templates/networkpolicy.yaml +++ b/packages/system/talos-log-collector/templates/networkpolicy.yaml @@ -1,11 +1,16 @@ +# Vector binds 0.0.0.0: inside the pod netns and exposes it as a +# containerPort, so the pod IP is reachable from every pod in the cluster. Any +# workload could open : and inject forged JSON lines that the +# pipeline stamps with log_source=talos_system and the real node name, straight +# into VictoriaLogs. This policy is load-bearing, not defence-in-depth: it is +# the only thing restricting the receiver to the node-local push path (Talos +# reaches it on 127.0.0.1:; portmap DNATs to the pod and SNATs the +# source to the node, so legitimate traffic arrives as the host). A CNI that +# does not enforce NetworkPolicy (e.g. the noop networking variant, or a BYO CNI +# without policy support) leaves the socket unprotected regardless. {{- if .Capabilities.APIVersions.Has "cilium.io/v2/CiliumNetworkPolicy" }} ---- -# Talos reaches the receiver on 127.0.0.1:; portmap DNATs that to -# the pod and SNATs the source to the node, so legitimate traffic arrives as -# the "host" entity. Restrict ingress on the listen port to host only, so other -# pods on the pod network cannot inject spoofed talos_system log lines. -# Defense-in-depth and Cilium-only: even without this policy the loopback -# hostPort is not reachable from the pod network, so its absence is safe. +# Cilium is present: restrict ingress on the listen port to the host entity, so +# only the node-local push path is allowed and other pods are denied. apiVersion: cilium.io/v2 kind: CiliumNetworkPolicy metadata: @@ -24,4 +29,25 @@ spec: - ports: - port: "{{ .Values.listenPort }}" protocol: TCP +{{- else }} +# No Cilium CRD: fall back to a CNI-agnostic default-deny-ingress policy so the +# socket is never offered without protection. This denies ingress from the pod +# network (the injection path) while node-local host traffic keeps flowing, the +# same way liveness/readiness probes from the node are not blocked by a +# default-deny policy; the portmap hostPort path arrives as node-local host +# traffic. +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: talos-log-collector + namespace: {{ .Release.Namespace }} + labels: + {{- include "talos-log-collector.labels" . | nindent 4 }} +spec: + podSelector: + matchLabels: + app.kubernetes.io/name: talos-log-collector + policyTypes: + - Ingress + ingress: [] {{- end }}