【发布时间】:2021-09-19 12:26:36
【问题描述】:
我在获取正确的 IP 标头时遇到了一些问题。我正在使用以下代理设置:
Cloudflare -> Amazon NLB -> Ingress-nginx (k8s)
我的 ingress-nginx 有以下配置:
config:
use-forwarded-headers: "true"
real-ip-header: "CF-Connecting-IP"
forwarded-for-header: "CF-Connecting-IP"
set-real-ip-from: "0.0.0.0/0"
proxy-buffer-size: "16k"
proxy-buffers-number: "8"
由于某种原因,x-real-ip 标头是正确的,但 x-forwarded-for 标头不正确:
REMOTE ADDR: 127.0.0.1
X FORWARDED FOR: 10.0.102.38 <- Wrong
X-REAL-IP: xx.xxx.xxx.xxx <- Correct
ingress-nginx 负载均衡器 (NLB) 具有:
External Traffic Policy: Local
根据文档。以及以下注释:
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: 3600
service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: *
service.beta.kubernetes.io/aws-load-balancer-ssl-cert: xxxx
service.beta.kubernetes.io/aws-load-balancer-ssl-ports: https
service.beta.kubernetes.io/aws-load-balancer-type: nlb
为了安全起见,我还在应用服务上启用了 ExternalTrafficPolicy: Local 但无济于事。
在配置中启用 use-proxy-protocol: "true" 会破坏应用程序(可能是因为 CloudFlare)。
2021-09-19 12:42:17
" while reading PROXY protocol, client: x.x.x.x, server: 0.0.0.0:80
任何帮助将不胜感激。
【问题讨论】:
-
GitHub 上有类似的 issie Problem with HTTPS, CloudFlare and X-Forwarded-Port header #6358。可能的解决方案是here。
标签: amazon-web-services kubernetes cloudflare