fix(iap): 4 处 IAP location 补 X-Auth-* 注头 + 文档同步 (v0.7.22)
影响:sso_iap 验签后只设 $auth_* nginx 变量, 不会自动给 proxy_pass 请求加
X-Auth-User 等 5 个头. v0.7.22 前 4 处 IAP location 全部漏, demo app 读
X-Auth-User 拿到空字符串; nginx access log 显示 auth_user=admin ≠ 头已注.
补 5 行后下游 request.headers 正常, /me 端到端返用户身份.
改动:
- deploy/nginx.conf:/proxy/app-crm/{callback,/} + /proxy/app-mobile/{callback,/}
四段 IAP location 各加 5 行 proxy_set_header X-Auth-* $auth_*.
- deploy/k8s/ipass-sso.yaml:镜像 tag v0.7.21 → v0.7.22; 头部注释记录此坑.
- docs/iap.md §6 坑列表加 #0, 附 5 行注头示例 + 解释 access log 误导.
- docs/integrate-with-iap.md §2.2 注释提醒(不照搬 4 段示例避免冗长);
§6 ipass-sso 端 checklist + 失败排查表各加一条.
设计:sso_iap 注头责任全在 nginx.conf(不打算让 sso 插件自动改请求头——
保持 $auth_* 变量语义纯粹, 不想动就 $auth_* 直接用; 想要头自己
proxy_set_header, 跟 $arg_XXX / $http_XXX 风格一致).
Co-Authored-By: Claude Code <[email protected]>
This commit is contained in:
1 parent
c3d005c9f8
commit
ddc396c992
4 files changed
+69
-2
No files matched your search
@@ -1,6 +1,14 @@
|
||||
# ============================================================================
|
||||
# ipass-sso K8s 部署清单(wuguirong 租户 ns)—— SSO-only 精简版
|
||||
#
|
||||
# 2026-10-12 升级 v0.7.21 → v0.7.22 (IAP 补 proxy_set_header X-Auth-* 注头):
|
||||
# - v0.7.21 nginx.conf IAP location 块只有 sso_iap on, 缺 proxy_set_header
|
||||
# X-Auth-User $auth_user 等 5 行, 导致 demo app 收不到 X-Auth-User 头
|
||||
# - 源码确认: ipass-plugin-sso/src/lib.rs:140 sso_iap 模块只设 nginx 变量
|
||||
# $auth_user/$auth_email/$auth_groups/$auth_sub/$auth_token, 不自动加 header
|
||||
# - 必须在每个 IAP location 块显式 proxy_set_header (4 处, 覆盖 app-crm /
|
||||
# app-mobile 的 callback + iap 主块, callback 虽无 sso_sid 也保持一致)
|
||||
#
|
||||
# 2026-10-12 升级 v0.7.20 → v0.7.21 (IAP upstream 改 K8s Service + 删 hostAliases):
|
||||
# - nginx.conf upstream: host.docker.internal:18101/18102 → app-crm-svc:8000
|
||||
# / app-mobile-svc:8000 (同 ns ClusterIP, 见 deploy/k8s/iap-demo.yaml)
|
||||
@@ -63,7 +71,7 @@ spec:
|
||||
# 之后业务写盘才炸,最难查)。幂等,每次滚动都会跑。
|
||||
initContainers:
|
||||
- name: init-data-dir
|
||||
image: crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com/ssw188/nginx:ipass-sso-v0.7.21
|
||||
image: crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com/ssw188/nginx:ipass-sso-v0.7.22
|
||||
imagePullPolicy: IfNotPresent
|
||||
command: ["bash", "-c", "mkdir -p /persist/sso && ls -la /persist"]
|
||||
securityContext:
|
||||
@@ -75,7 +83,7 @@ spec:
|
||||
mountPath: /persist
|
||||
containers:
|
||||
- name: ipass-sso
|
||||
image: crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com/ssw188/nginx:ipass-sso-v0.7.21
|
||||
image: crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com/ssw188/nginx:ipass-sso-v0.7.22
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- name: http
|
||||
|
||||
@@ -192,6 +192,13 @@ http {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
# IAP 头注入: sso_iap 模块只设 nginx 变量 $auth_*, 不自动加 header
|
||||
# 必须在每个 IAP location 显式 proxy_set_header (v0.7.22 补)
|
||||
proxy_set_header X-Auth-User $auth_user;
|
||||
proxy_set_header X-Auth-Email $auth_email;
|
||||
proxy_set_header X-Auth-Groups $auth_groups;
|
||||
proxy_set_header X-Auth-Sub $auth_sub;
|
||||
proxy_set_header X-Auth-Token $auth_token;
|
||||
}
|
||||
location /proxy/app-crm/ {
|
||||
ipass_api off; # 防 merge_loc_conf 漏父级 ipass_api on
|
||||
@@ -207,6 +214,13 @@ http {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
# IAP 头注入: sso_iap 模块只设 nginx 变量 $auth_*, 不自动加 header
|
||||
# 必须在每个 IAP location 显式 proxy_set_header (v0.7.22 补)
|
||||
proxy_set_header X-Auth-User $auth_user;
|
||||
proxy_set_header X-Auth-Email $auth_email;
|
||||
proxy_set_header X-Auth-Groups $auth_groups;
|
||||
proxy_set_header X-Auth-Sub $auth_sub;
|
||||
proxy_set_header X-Auth-Token $auth_token;
|
||||
}
|
||||
location /proxy/app-mobile/callback {
|
||||
ipass_api off;
|
||||
@@ -217,6 +231,13 @@ http {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
# IAP 头注入: sso_iap 模块只设 nginx 变量 $auth_*, 不自动加 header
|
||||
# 必须在每个 IAP location 显式 proxy_set_header (v0.7.22 补)
|
||||
proxy_set_header X-Auth-User $auth_user;
|
||||
proxy_set_header X-Auth-Email $auth_email;
|
||||
proxy_set_header X-Auth-Groups $auth_groups;
|
||||
proxy_set_header X-Auth-Sub $auth_sub;
|
||||
proxy_set_header X-Auth-Token $auth_token;
|
||||
}
|
||||
location /proxy/app-mobile/ {
|
||||
ipass_api off;
|
||||
@@ -231,6 +252,13 @@ http {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
# IAP 头注入: sso_iap 模块只设 nginx 变量 $auth_*, 不自动加 header
|
||||
# 必须在每个 IAP location 显式 proxy_set_header (v0.7.22 补)
|
||||
proxy_set_header X-Auth-User $auth_user;
|
||||
proxy_set_header X-Auth-Email $auth_email;
|
||||
proxy_set_header X-Auth-Groups $auth_groups;
|
||||
proxy_set_header X-Auth-Sub $auth_sub;
|
||||
proxy_set_header X-Auth-Token $auth_token;
|
||||
}
|
||||
|
||||
# ---- IAP 401 兜底:跳企微登录,redirect 保留原 URL ----
|
||||
|
||||
+15
@@ -133,6 +133,21 @@ auth_user=admin auth_sub=admin [email protected] auth_groups=admin
|
||||
|
||||
## 6. 踩过的坑(来自实测)
|
||||
|
||||
0. **`sso_iap` 只设 nginx 变量不自动注头**(2026-10-12 v0.7.22 实测踩):sso_iap
|
||||
验签后把身份写进 `$auth_user/$auth_email/...` nginx 变量,但**不会**自动给
|
||||
`proxy_pass` 出去的请求加 `X-Auth-*` 头。必须每个 sso_iap location 显式:
|
||||
```nginx
|
||||
proxy_set_header X-Auth-User $auth_user;
|
||||
proxy_set_header X-Auth-Email $auth_email;
|
||||
proxy_set_header X-Auth-Groups $auth_groups;
|
||||
proxy_set_header X-Auth-Sub $auth_sub;
|
||||
proxy_set_header X-Auth-Token $auth_token;
|
||||
```
|
||||
漏了之后表现是:sso_iap 验签通过、请求 200 到下游,但下游 `request.headers`
|
||||
看不到 X-Auth-*(demo app 读 `X-Auth-User` 拿到空字符串)。**nginx access log
|
||||
里 `auth_user=admin` ≠ 头已注**(access log 直接读 nginx 变量,不代表
|
||||
proxy_set_header 拼到了请求上)。
|
||||
|
||||
1. **`/oauth/token` 返回的是 `{code,data,msg}` 信封**——下游用 `access_token` 字段取
|
||||
会取到 `data` 那个对象。改用 `/oauth/v20/token`(MaxKey 兼容端点,裸 OAuth2 响应)。
|
||||
2. **shm/disk 不一致**:`active.jwk.json` 落盘但 pod 内存里可能已经有新 kid(admin
|
||||
|
||||
@@ -92,6 +92,13 @@ location /proxy/app-crm/callback {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
# sso_iap 只设 $auth_* 变量, 不会自动加 X-Auth-* 头给下游
|
||||
# (2026-10-12 v0.7.22 实测踩, 缺这 5 行 demo app 读 X-Auth-User 拿到空字符串)
|
||||
proxy_set_header X-Auth-User $auth_user;
|
||||
proxy_set_header X-Auth-Email $auth_email;
|
||||
proxy_set_header X-Auth-Groups $auth_groups;
|
||||
proxy_set_header X-Auth-Sub $auth_sub;
|
||||
proxy_set_header X-Auth-Token $auth_token;
|
||||
}
|
||||
|
||||
# / 及其子路径:挂 sso_iap 强制 sso_sid
|
||||
@@ -106,6 +113,13 @@ location /proxy/app-crm/ {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
# sso_iap 只设 $auth_* 变量, 不会自动加 X-Auth-* 头给下游
|
||||
# (2026-10-12 v0.7.22 实测踩, 缺这 5 行 demo app 读 X-Auth-User 拿到空字符串)
|
||||
proxy_set_header X-Auth-User $auth_user;
|
||||
proxy_set_header X-Auth-Email $auth_email;
|
||||
proxy_set_header X-Auth-Groups $auth_groups;
|
||||
proxy_set_header X-Auth-Sub $auth_sub;
|
||||
proxy_set_header X-Auth-Token $auth_token;
|
||||
}
|
||||
|
||||
# 401 兜底:跳企微登录, redirect 保留原 URL (named location 必须在 server 块内)
|
||||
@@ -382,6 +396,7 @@ curl -s -o /dev/null -D - http://127.0.0.1:28889/proxy/app-crm/callback | head -
|
||||
- [ ] `deploy/nginx.conf` 加 4 段 location(upstream / callback / iap-loc / 401-namied-location)
|
||||
- [ ] 每段 IAP location 的 `proxy_redirect` 都用**正则** `~^(https?://[^/]+)?(/.*)$ /proxy/<app-name>$2`
|
||||
- [ ] iap-loc 显式 `ipass_api off;` + `sso_iap on;` + `error_page 401 = @iap_oauth_login`
|
||||
- [ ] **每段 IAP location 显式 5 行 `proxy_set_header X-Auth-* $auth_*`**(v0.7.22 实测踩:sso_iap 只设 nginx 变量不自动注头;漏一行 → demo app 读 X-Auth-User 拿空字符串)
|
||||
- [ ] /callback 显式 `ipass_api off;` + `proxy_pass http://<upstream>/callback`(**具体子路径**)
|
||||
- [ ] 企微工作台应用主页 URL = `https://<idp-host>/proxy/<app-name>/`(**IAP 路径**)
|
||||
|
||||
@@ -406,6 +421,7 @@ curl -s -o /dev/null -D - http://127.0.0.1:28889/proxy/app-crm/callback | head -
|
||||
| 落在 `/proxy/app-crm/proxy/app-crm/`(双前缀) | demo app 自己也加了 BASE 到 `redirect()`, IAP 又加一次 | demo app `redirect()` 还原成 `/X` 形式 |
|
||||
| `invalid_grant: redirect_uri 不匹配` | demo app 写的 REDIRECT_URI 与 oauth_clients.json 注册的不一致 | env 改一致, 都用公网 IAP 路径 |
|
||||
| iPhone 一直转圈 | demo app 监听 127.0.0.1, 容器连不上 | `app.run(host="0.0.0.0", port=PORT)` |
|
||||
| demo app 收不到 X-Auth-User(拿空字符串) | sso_iap 只设 nginx 变量不自动注头 | 每段 IAP location 显式 `proxy_set_header X-Auth-User $auth_user` 等 5 行 |
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in new issue
Block a user