push 的请求体带全量 salt + pwd_hash + api_key,不该出集群。nginx 层 allow/deny 与 SyncToken 头是两道独立的门,任一道漏了另一道还在。 同时补 env 白名单:sync.rs 在 worker 里读 std::env::var,nginx 默认清空 worker 环境变量,不声明这三条则 token/side/peer 恒空——push 恒 401、 export 恒 400、从不推送,且不报任何错。 Co-Authored-By: Claude Code <[email protected]>
286 lines
14 KiB
Nginx Configuration File
286 lines
14 KiB
Nginx Configuration File
# ============================================================================
|
||
# ipass-sso 容器运行配置(精简版:身份/IdP + 管理台)
|
||
#
|
||
# 从 ipass-all/deploy/nginx.conf 派生的 SSO-only 版(2026-09-30 拍板):
|
||
# 剔除了 domain / llm / apix / cache / waf 5 个插件对应的 location 与
|
||
# 整个 LLM 数据面 server、动态域名 server;只保留身份 / 管理台 / API 端点。
|
||
#
|
||
# 指令清单 = 本仓 gateway 注册的 4 条:
|
||
# main : ipass_state / ipass_data_dir
|
||
# loc : ipass_api / sso_iap
|
||
#
|
||
# 非 root 适配(k8s 租户准入强制 runAsUser=10106):
|
||
# pid/lock/temp 全部挪 /tmp
|
||
# ============================================================================
|
||
|
||
worker_processes auto;
|
||
error_log /usr/local/nginx/logs/error.log info;
|
||
pid /tmp/nginx/nginx.pid;
|
||
lock_file /tmp/nginx/nginx.lock;
|
||
|
||
load_module /usr/local/nginx/modules/libipass_sso_gateway.so;
|
||
|
||
# 模块读取的 env 白名单(nginx 默认剥离全部环境变量;漏一条 = worker 里恒空)
|
||
env ADMIN_INIT_PASSWORD;
|
||
env OAUTH_SIGNING_SECRET;
|
||
env OAUTH_ISSUER;
|
||
env OAUTH_COOKIE_DOMAIN;
|
||
env SYNC_DINGTALK_URL;
|
||
env SYNC_WORKWECHAT_URL;
|
||
env SYNC_FEISHU_URL;
|
||
env PASSWORD_RESET_TOKEN_SINK;
|
||
env PASSWORD_RESET_TTL;
|
||
# 企微 OAuth 集成(2026-10-09 v0.7.0)—— 工作台「用企微登录」入口
|
||
env WXWORK_ENABLED;
|
||
env WXWORK_CORP_ID;
|
||
env WXWORK_AGENT_ID;
|
||
env WXWORK_SECRET;
|
||
env WXWORK_REDIRECT;
|
||
# 集群内账号同步(ipass-all ↔ ipass-sso)—— 不声明则 worker 里恒空,
|
||
# 表现为 push 恒 401 / export 恒 400 / 从不推送,且没有任何报错
|
||
env IPASS_SYNC_SIDE;
|
||
env IPASS_SYNC_PEER;
|
||
env IPASS_SYNC_TOKEN;
|
||
|
||
events {
|
||
worker_connections 2048;
|
||
}
|
||
|
||
http {
|
||
include /usr/local/nginx/conf/mime.types;
|
||
default_type application/json; # 业务侧默认 JSON,静态页在对应 location 覆盖
|
||
sendfile on;
|
||
keepalive_timeout 65;
|
||
|
||
# ------------------------------------------------------------------
|
||
# 非 root 适配:临时目录默认在编译前缀下(root 属主),10106 建不了
|
||
# ------------------------------------------------------------------
|
||
client_body_temp_path /tmp/nginx/client_body;
|
||
proxy_temp_path /tmp/nginx/proxy;
|
||
fastcgi_temp_path /tmp/nginx/fastcgi;
|
||
|
||
# ------------------------------------------------------------------
|
||
# 日志:带身份维度(WAF/缓存/域名等插件字段在精简版省略),排障不翻模块日志
|
||
# ------------------------------------------------------------------
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||
'$status $body_bytes_sent "$http_referer" "$http_user_agent" '
|
||
'"$upstream_addr" "$upstream_status" "$upstream_response_time" '
|
||
'auth_user=$auth_user';
|
||
access_log /usr/local/nginx/logs/access.log main;
|
||
|
||
# ------------------------------------------------------------------
|
||
# 内核:共享内存 + 数据目录(必须显式,理由见文件头)
|
||
# ------------------------------------------------------------------
|
||
ipass_state state 16m; # 身份会话+账号 Key(精简版无域名/用量/缓存/WAF)
|
||
ipass_data_dir /usr/local/nginx/data;
|
||
|
||
# ------------------------------------------------------------------
|
||
# IAP 反代:demo app 跑在 K8s 集群内 (deploy/k8s/iap-demo.yaml)。
|
||
# 2026-10-12 从 Mac 127.0.0.1 搬上 K8s, 用 ClusterIP Service
|
||
# app-crm-svc / app-mobile-svc (ns wuguirong, port 8000).
|
||
# 之前 Mac 时代用 host.docker.internal (OrbStack 0.250.250.254) 走通,
|
||
# K8s pod 内 host.docker.internal 占位 127.0.0.1 (hostAliases), IAP 路径 502.
|
||
# 搬 K8s 后: 同 ns 集群 DNS 直接解析, 不再需要 hostAliases 占位.
|
||
# ------------------------------------------------------------------
|
||
upstream app_crm_backend { server app-crm-svc:8000; keepalive 16; }
|
||
upstream app_mobile_backend { server app-mobile-svc:8000; keepalive 16; }
|
||
|
||
# ==================================================================
|
||
# 主 server(NodePort 30089):管理台 + IdP 全部端点
|
||
# ==================================================================
|
||
# ⚠️ 本次部署为明文 HTTP(2026-09-30 临时方案,TLS 后续接入)。
|
||
# 历史:本想用 K8s ConfigMap 把 self-signed cert 注入到
|
||
# /usr/local/nginx/data/tls/,但本 SA 在当前受限会话里没有
|
||
# 创建 ConfigMap 的工具调用授权。先用 18098 明文把 SSO + OIDC
|
||
# discovery 链路跑通,证书走 PVC sso/tls/ + 外部流程接入时再切回
|
||
# `listen 18098 ssl default_server` + 三条 ssl_certificate 指令。
|
||
server {
|
||
listen 18098 default_server; # 明文(NodePort 30089)
|
||
server_name _;
|
||
|
||
absolute_redirect off;
|
||
port_in_redirect off;
|
||
|
||
# 管理台核心壳(ipass-core www dist)+ sso 管理页
|
||
root /usr/local/nginx/www;
|
||
index index.html;
|
||
|
||
client_max_body_size 10m;
|
||
client_body_buffer_size 1m;
|
||
|
||
# ---- 集群内账号同步(ipass-all ↔ ipass-sso)----
|
||
# 只接受集群内来源:pod CIDR + Service CIDR 双保险。
|
||
# 理由——sync/push 的请求体带全量 salt + pwd_hash + api_key,
|
||
# 绝不能出集群。nginx 层与 SyncToken 头是两道独立的门。
|
||
location /api/admin/sync/ {
|
||
allow 10.244.0.0/16; # pod CIDR
|
||
allow 10.96.0.0/12; # Service CIDR(实测 ClusterIP 10.96–10.110)
|
||
deny all;
|
||
ipass_api on;
|
||
}
|
||
|
||
# ---- 管理/身份 API(content 阶段读体后按 PLUGINS 顺序分发)----
|
||
# 认领方:sso(身份端点/OIDC/SCIM/CAS/门户)+ core(账号/插件启停注册表)
|
||
location /api/ {
|
||
ipass_api on;
|
||
}
|
||
|
||
# OIDC/身份协议端点挂在根路径(/oauth/* /login /logout /userinfo
|
||
# /.well-known/* /apps /reset /cas/*),由 sso 插件认领
|
||
location / {
|
||
ipass_api on;
|
||
}
|
||
|
||
# ---- 管理台静态资源(这些 location 不开 ipass_api:静态文件走 nginx)----
|
||
location = / {
|
||
return 302 /admin/;
|
||
}
|
||
location = /admin {
|
||
return 302 /admin/;
|
||
}
|
||
location = /index.html {
|
||
add_header Cache-Control "no-store" always;
|
||
}
|
||
location /admin/ {
|
||
try_files $uri $uri/ /index.html; # SPA history 深链兜底
|
||
add_header Cache-Control "no-store" always;
|
||
}
|
||
# 插件面板路由(/plugin-<name>)走壳 SPA:直链/刷新时回 index.html
|
||
location /plugin- {
|
||
try_files $uri /index.html;
|
||
add_header Cache-Control "no-store" always;
|
||
}
|
||
# 壳内置面板路由(/manage/*,网关管理三页)同上
|
||
location /manage/ {
|
||
try_files $uri /index.html;
|
||
add_header Cache-Control "no-store" always;
|
||
}
|
||
location /assets/ {
|
||
add_header Cache-Control "no-store" always;
|
||
}
|
||
|
||
# 插件管理页 UMD 产物(壳按 /static/plugins/<name>/dist/<name>-admin.umd.js 拉取)
|
||
location /static/plugins/ {
|
||
alias /usr/local/nginx/static-plugins/;
|
||
add_header Cache-Control "no-store" always;
|
||
}
|
||
# 装配层自定义页清单(精简版不挂自定义页,无 /static/custom/)
|
||
# 老管理台 sso 五 tab 单页(精简版只挂 sso.html 一张;自包含,零外部资产)
|
||
# 默认 api=false 即可:merge_loc_conf 已不继承父 location / 的 ipass_api on
|
||
# (见 gateway/src/lib.rs::Merge 注释),无需显式 `ipass_api off;`
|
||
location /legacy/ {
|
||
alias /usr/local/nginx/legacy/;
|
||
add_header Cache-Control "no-store" always;
|
||
}
|
||
|
||
# ---- 企微域名校验文件(v0.7.0+)----
|
||
# 文件在 PVC 的 verify/ 目录(/usr/local/nginx/data/verify/WW_verify_*.txt),
|
||
# 部署时由 scripts/seed-verify.sh 从 data-seed/verify/ 复制过去。
|
||
# 留空内容即可命中(Content-Type 显式给 text/plain)。
|
||
location ~* ^/WW_verify_[A-Za-z0-9_-]+\.txt$ {
|
||
root /usr/local/nginx/data/verify;
|
||
add_header Content-Type "text/plain; charset=utf-8" always;
|
||
}
|
||
|
||
# ---- IAP 反代 demo app(v0.7.12+,出站代理模式)----
|
||
# /callback 子路径单独挂:不走 sso_iap(IdP 来的回调无 JWT/cookie,
|
||
# 否则 IAP 会 401 → 跳登录 → 死循环)。其它路径挂 sso_iap 强制 sso_sid,
|
||
# sso_sid 由 WeChat Work 登录或 /login 流程写入,缺失时跳企微登录。
|
||
#
|
||
# proxy_redirect 必须写正则 ~^/:demo app 内部 redirect("/") 返的
|
||
# 是相对路径,浏览器按当前请求 Host(公网域)解析 → 跳到 IdP 根
|
||
# → /admin/,不是 demo app。把所有以 / 开头的 Location 重写回 IAP
|
||
# 路径,覆盖 redirect("/")/redirect("/me")/redirect("/logout") 等
|
||
# 全部 demo app 内部跳转。绝对 URL(含 http://app_crm_backend/)
|
||
# 也一并覆盖 → 公网/IAP 场景下不会泄漏 backend 地址。
|
||
#
|
||
# sub_filter 重写 demo app HTML 里的根相对路径:demo app 渲染的
|
||
# href="/customers" / href="/opportunities" 等在它自己域名是绝对
|
||
# 路径,但在 IAP 路径前缀下错位 → 浏览器跳到公网 /customers(落
|
||
# 到 IdP 兜底 404)。把所有 demo app 内部路径加 /proxy/<app>/ 前缀。
|
||
# 不重写 /api/(demo app 的 /api/customers 是 IdP 数据源)。
|
||
location /proxy/app-crm/callback {
|
||
ipass_api off; # 防 merge_loc_conf 漏父级 ipass_api on
|
||
proxy_pass http://app_crm_backend/callback;
|
||
proxy_redirect ~^(https?://[^/]+)?(/.*)$ /proxy/app-crm$2;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
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
|
||
sso_iap on;
|
||
error_page 401 = @iap_oauth_login;
|
||
proxy_pass http://app_crm_backend/;
|
||
proxy_redirect ~^(https?://[^/]+)?(/.*)$ /proxy/app-crm$2;
|
||
# 注:demo app 自身会用 env BASE=/proxy/app-crm 拼 HTML 里的
|
||
# href/action/script src=路径,nginx 侧不重写(sub_filter 是
|
||
# 固定串匹配,'/customers' 会误伤 /api/customers 这类 IdP 端点)。
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
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;
|
||
proxy_pass http://app_mobile_backend/callback;
|
||
proxy_redirect ~^(https?://[^/]+)?(/.*)$ /proxy/app-mobile$2;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
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;
|
||
sso_iap on;
|
||
error_page 401 = @iap_oauth_login;
|
||
proxy_pass http://app_mobile_backend/;
|
||
proxy_redirect ~^(https?://[^/]+)?(/.*)$ /proxy/app-mobile$2;
|
||
# 注:demo app 自身会用 env BASE=/proxy/app-mobile 拼 HTML 里的
|
||
# href/action/script src=路径,nginx 侧不重写。
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
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 ----
|
||
# 必须放在 server 块内(named location 不能在 http {} 顶层)
|
||
location @iap_oauth_login {
|
||
return 302 "/portal/wxwork/login?redirect=$request_uri";
|
||
}
|
||
}
|
||
} |