Skip to content

Commit 4b6933c

Browse files
authored
fix(ingress): trust CF-Connecting-IP only from Cloudflare ranges (#4444)
<!-- Thank you for making a contribution! Here are some tips for you: - Use Conventional Commits for the PR title: `type(scope): description` - Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore - Scopes are not an exhaustive list — pick the most specific scope for the change and extend the list when a genuinely new area appears. Examples: - System components: dashboard, platform, operator, cilium, kube-ovn, linstor, fluxcd, cluster-api - Managed apps: postgres, mariadb, redis, kafka, clickhouse, virtual-machine, kubernetes - Development and maintenance: api, hack, tests, ci, docs, maintenance - Breaking changes: append `!` after type/scope (`feat(api)!: ...`) or add a `BREAKING CHANGE:` footer - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `kind/backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does With `cloudflareProxy: true` on a tenant Ingress app, any client that reaches the load balancer directly can pick its own source address by sending a `CF-Connecting-IP` header, and that address is what `whitelist-source-range` checks. So the tenant `whitelist`, and any per-Ingress whitelist behind the same controller, can be bypassed with one header. The chart passes the Cloudflare ranges to the controller as `set_real_ip_from`. That is an nginx directive, not an ingress-nginx ConfigMap key, so the controller drops it without a warning. `use-forwarded-headers: "true"` turns the realip module on, and it then trusts every source from the default `proxy-real-ip-cidr`, which is `0.0.0.0/0` (ingress-nginx v1.11.5, `internal/ingress/controller/config/config.go` and the `set_real_ip_from` loop in `nginx.tmpl`). This has been the case since the option was added. The fix renames the key to `proxy-real-ip-cidr`. Traffic that comes through Cloudflare keeps the visitor address as before. A direct connection keeps its own address, whatever it puts in the header. If something between Cloudflare and the controller rewrites the source address, the header stops being trusted and the whitelist sees that hop instead; that is the correct result for a header that can only be trusted from known senders. The new test checks that the trusted ranges land under the key the controller reads, that they are not a catch-all, and that `set_real_ip_from` is gone. ### Screenshots No UI change. ### Downstream repositories Template-only change in `packages/extra/ingress`: no values key, schema, package, platform, installer or `hack/` change, so nothing in the trigger map is reached. - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note ```release-note fix(ingress): with `cloudflareProxy` enabled, `CF-Connecting-IP` is now trusted only from Cloudflare's address ranges. Before, the Cloudflare ranges were passed under a key ingress-nginx ignores, so any client reaching the load balancer directly could set the header and get past the ingress `whitelist`. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Updated Cloudflare proxy IP configuration to use ingress-nginx’s supported setting, preserving forwarded-header and client IP handling. * Ensured Cloudflare proxy IP ranges remain configured when a whitelist is set. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 5f5d8e9 + 3800f63 commit 4b6933c

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)