我已经在this question中尝试了答案。这是我当前的配置:
apiVersion: v1
kind: ConfigMap
metadata:
labels:
helm.sh/chart: ingress-nginx-2.13.0
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: 0.35.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
name: ingress-nginx-controller
namespace: ingress-nginx
data:
use-proxy-protocol: 'true'
enable-real-ip: "true"
proxy-real-ip-cidr: "173.245.48.0/20,173.245.48.0/20,103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,141.101.64.0/18,108.162.192.0/18,190.93.240.0/20,188.114.96.0/20,197.234.240.0/22,198.41.128.0/17,162.158.0.0/15,104.16.0.0/12,172.64.0.0/13,131.0.72.0/22,2400:cb00::/32,2606:4700::/32,2803:f800::/32,2405:b500::/32,2405:8100::/32,2a06:98c0::/29,2c0f:f248::/32"
# use-forwarded-headers: "true"
# compute-full-forwarded-for: "true"
# forwarded-for-header: "Cf-Connecting-Ip"
# forwarded-for-header: "X-Original-Forwarded-For"
server-snippet: |
real_ip_header CF-Connecting-IP;
字符串
而且我尝试过的配置中没有一个实际上是将始发IP作为真实的IP。
在我应用配置之前,我得到:
Host: example.com
X-Request-ID: deadcafe
X-Real-IP: 162.158.X.X (A Cloudflare IP)
X-Forwarded-For: 162.158.X.X (Same as above)
X-Forwarded-Proto: https
X-Forwarded-Host: example.com
X-Forwarded-Port: 80
X-Scheme: https
X-Original-Forwarded-For: <The Originating IP that I want>
Accept-Encoding: gzip
CF-IPCountry: IN
CF-RAY: cafedeed
CF-Visitor: {"scheme":"https"}
user-agent: Mozilla/5.0
accept-language: en-US,en;q=0.5
referer: https://pv-hr.jptec.in/
upgrade-insecure-requests: 1
cookie: __cfduid=012dadfad
CF-Request-ID: 01234faddad
CF-Connecting-IP: <The Originating IP that I want>
CDN-Loop: cloudflare
型
应用配置Map后,头文件为:
Host: example.com
X-Request-ID: 0123fda
X-Real-IP: 10.X.X.X (An IP that matches the private ip of the Digital Ocean droplets in the vpc, so guessing its the load balancer)
X-Forwarded-For: 10.X.X.X (Same as above)
X-Forwarded-Proto: http
X-Forwarded-Host: example.com
X-Forwarded-Port: 80
X-Scheme: http
X-Original-Forwarded-For: <Originating IP>
Accept-Encoding: gzip
CF-IPCountry: US
CF-RAY: 5005deeb
CF-Visitor: {"scheme":"https"}
accept: /
user-agent: Mozilla/5.0
CF-Request-ID: 1EE7af
CF-Connecting-IP: <Originating IP>
CDN-Loop: cloudflare
型
配置后唯一的变化是real-ip现在指向Digital Ocean vpc上的某个内部资源。我无法追踪到它,但我猜它是负载均衡器。我确信它是DO资源,因为它匹配kubernetes节点的ip。所以,我真的不知道为什么会发生这种情况,我应该做些什么来获得真正的IP始发IP。
2条答案
按热度按时间t3irkdon1#
你面临的问题在这里:
第一个月
但是,所看到的流量来自您的DO LB而不是
10.x.x.x
。这导致此规则将其忽略。我做了以下操作来使它正常工作:
字符串
安全提示:这将适用于所有流量,即使它不是来自Cloudflare本身。因此,有人可以欺骗请求的头部来冒充另一个IP地址。
eni9jsuy2#
我也遇到了同样的问题,上面的回答对我没有帮助。
这就是我为解决这个问题所做的:
1 -在
ingress-nginx-controller
中,我添加了以下注解:字符串
2 -在
ingress-nginx-controller
的Config Maps
中,我在数据中添加了以下内容:在这里,我们也设置use-proxy-protocol
,添加set_真实的_ip_from(CloudFlares Ips)服务器片段可以如下所示或#真实的_ip_header X-Forwarded-For;请参阅for more请使用此link获取更新的cloudflare Ips列表
型