fix client IP handling behind proxies
Deployment Config CI / Deployment Config (push) Successful in 27s
Frontend CI / Frontend (push) Successful in 3m2s
Backend CI / Backend (push) Successful in 14m8s

This commit is contained in:
2026-05-05 23:01:25 +08:00
parent ffb7d179c6
commit 3c912949e4
20 changed files with 272 additions and 16 deletions
+6
View File
@@ -1,6 +1,12 @@
server:
port: 8080
mode: release
trusted_proxies:
- 127.0.0.1
- ::1
- 10.42.0.0/16
- 10.43.0.0/16
- 172.16.0.0/12
database:
host: pgbouncer
+10
View File
@@ -87,6 +87,16 @@ k3s 默认同时支持两种访问方式。
- tenant admin: `http://<node-ip>:30080`
- ops admin: `http://<node-ip>:30081`
这两个 NodePort Service 使用 `externalTrafficPolicy: Local`,用于保留客户端源 IP,后端日志和登录审计会读取规范化后的 `X-Forwarded-For` / `X-Real-IP`
如果通过 k3s 内置 Traefik Ingress 对外提供服务,也需要把 Traefik Service 调整为保留源地址:
```bash
kubectl -n kube-system patch svc traefik -p '{"spec":{"externalTrafficPolicy":"Local"}}'
```
临时用 frpc/frps 做 TCP 隧道时,用户源 IP 通常不会穿透到 k3s;这类链路需要 proxy protocol 或 HTTP 反代写入可信 `X-Forwarded-For`,否则日志只能记录隧道出口/NAS 本地转发地址。
例如 NAS IP 是 `192.168.100.19`
- tenant admin: `http://192.168.100.19:30080`
+2
View File
@@ -471,6 +471,7 @@ metadata:
app.kubernetes.io/name: frontend
spec:
type: NodePort
externalTrafficPolicy: Local
selector:
app.kubernetes.io/name: frontend
ports:
@@ -530,6 +531,7 @@ metadata:
app.kubernetes.io/name: ops-web
spec:
type: NodePort
externalTrafficPolicy: Local
selector:
app.kubernetes.io/name: ops-web
ports:
+6
View File
@@ -1,6 +1,12 @@
server:
port: 8080
mode: release
trusted_proxies:
- 127.0.0.1
- ::1
- 10.42.0.0/16
- 10.43.0.0/16
- 172.16.0.0/12
database:
host: pgbouncer
+6
View File
@@ -1,6 +1,12 @@
server:
port: 8090
mode: release
trusted_proxies:
- 127.0.0.1
- ::1
- 10.42.0.0/16
- 10.43.0.0/16
- 172.16.0.0/12
database:
host: pgbouncer
+6
View File
@@ -1,6 +1,12 @@
server:
port: 8090
mode: release
trusted_proxies:
- 127.0.0.1
- ::1
- 10.42.0.0/16
- 10.43.0.0/16
- 172.16.0.0/12
database:
host: pgbouncer