https://github.com/istio/istio/issues/7607
使用envoyfilter:
---
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: ingressgateway-user-ip
namespace: ingress
spec:
workloadLabels:
app: istio-ingressgateway
filters:
- listenerMatch:
portNumber: 443
listenerType: ANY
filterName: envoy.lua
filterType: HTTP
filterConfig:
inlineCode: |
function envoy_on_request(request_handle)
local xff_header = request_handle:headers():get("X-Forwarded-For")
local first_ip = string.gmatch(xff_header, "(%d+.%d+.%d+.%d+)")();
request_handle:headers():add("X-Custom-User-IP", first_ip);
end
优化
function envoy_on_request(request_handle)
local xff_header = request_handle:headers():get("X-Forwarded-For");
local client_ip
for ip in string.gmatch (xff_header, "(%d+.%d+.%d+.%d+)") do
client_ip = ip
end
request_handle:headers():add("x-client-ip", client_ip);
end
网友评论