Repository navigation
Commit 4b6933c
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 files changed
Lines changed: 41 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
0 commit comments