Skip to content

Commit 3800f63

Browse files
committed
fix(ingress): trust CF-Connecting-IP only from Cloudflare ranges
cloudflareProxy passed the Cloudflare ranges to the controller under set_real_ip_from, which is an nginx directive and not an ingress-nginx ConfigMap key, so the controller dropped it without a warning. With use-forwarded-headers on, the realip module then trusted every source from the default proxy-real-ip-cidr of 0.0.0.0/0, and any client that reached the load balancer directly could set CF-Connecting-IP to an address of its choice. That address is what whitelist-source-range checks, so the tenant whitelist, and any per-Ingress one, could be walked past with one header. proxy-real-ip-cidr is the key the controller reads for the trusted ranges. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 5f5d8e9 commit 3800f63

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎packages/extra/ingress/templates/nginx-ingress.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ spec:
120120
whitelist-source-range: "{{ join "," . }}"
121121
{{- end }}
122122
{{- if .Values.cloudflareProxy }}
123-
set_real_ip_from: "{{ include "ingress.cloudflare-ips" . }}"
123+
proxy-real-ip-cidr: "{{ include "ingress.cloudflare-ips" . }}"
124124
use-forwarded-headers: "true"
125125
server-snippet: "real_ip_header CF-Connecting-IP;"
126126
{{- end }}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
suite: ingress cloudflareProxy wiring
2+
templates:
3+
- templates/nginx-ingress.yaml
4+
release:
5+
name: ingress
6+
namespace: tenant-foo
7+
set:
8+
_cluster: {}
9+
cloudflareProxy: true
10+
tests:
11+
- it: trusts CF-Connecting-IP only from the Cloudflare ranges
12+
asserts:
13+
- matchRegex:
14+
path: spec.values.ingress-nginx.controller.config.proxy-real-ip-cidr
15+
pattern: ^[0-9a-f.:/]+(,[0-9a-f.:/]+)+$
16+
- notMatchRegex:
17+
path: spec.values.ingress-nginx.controller.config.proxy-real-ip-cidr
18+
pattern: (^|,)(0\.0\.0\.0/0|::/0)(,|$)
19+
- equal:
20+
path: spec.values.ingress-nginx.controller.config.use-forwarded-headers
21+
value: "true"
22+
- equal:
23+
path: spec.values.ingress-nginx.controller.config.server-snippet
24+
value: "real_ip_header CF-Connecting-IP;"
25+
26+
- it: does not use set_real_ip_from, which is not an ingress-nginx ConfigMap key
27+
asserts:
28+
- notExists:
29+
path: spec.values.ingress-nginx.controller.config.set_real_ip_from
30+
31+
- it: keeps the whitelist next to the trusted ranges
32+
set:
33+
whitelist:
34+
- 192.0.2.0/24
35+
asserts:
36+
- equal:
37+
path: spec.values.ingress-nginx.controller.config.whitelist-source-range
38+
value: 192.0.2.0/24
39+
- exists:
40+
path: spec.values.ingress-nginx.controller.config.proxy-real-ip-cidr

0 commit comments

Comments
 (0)