Files
sso/scripts/local-serve.sh
T
ssw 4a780a4ce7 feat(sso): MaxKey 迁移 P1/P2 —— SCIM/CAS/LDAP/同步连接器/自助密码重置/归属地
- 新增 plugin-sso 模块(零新增 crate):scim.rs(SCIM 2.0)、cas.rs(CAS 1.0/2.0)、

  ldap.rs(LDAP/AD,手写 BER/ASN.1 Simple Bind)、sync.rs(钉钉/企微/飞书手动触发同步)、

  reset.rs(自助密码重置)、geo.rs(登录 IP 归属地)

- api.rs 兜底路由按 scim→cas→reset→sync 分发兄弟模块;h_login 集成 LDAP(未启用零行为变化)

- 修 http::redirect 空 body 触发 NGX_ERROR(CAS 302 无 Location 的根因)

- nginx.conf / nginx.test.conf 补 env SYNC_* / PASSWORD_RESET_*(worker 可见)

- 新增第 7 套 e2e tests/maxkey-p1p2-e2e.sh(21 项),harness 接入 [7/7];七套全绿 rc=0

- 修脚本 $var 紧跟全角字符被并入变量名的 shell 坑(tests + scripts)

- 文档同步:maxkey-migration-analysis(P1/P2 状态) / roadmap(v4) / CLAUDE.md / README.md
2026-09-14 18:51:37 +08:00

82 lines
3.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# ============================================================================
# 本地起停 SSO 网关(手工联调用,与 scripts/run-local-e2e.sh 同一套配置)
#
# 与 run-local-e2e.sh 的区别:那个跑完就停进程,这个是常驻,
# 用来开着浏览器点管理台、或者手工 curl 端点。
#
# 用法:
# bash scripts/local-serve.sh start # 起(默认)
# bash scripts/local-serve.sh stop # 停
# bash scripts/local-serve.sh restart
#
# 所有凭据来自项目根 .env(不进 git),命令行里不出现任何密钥。
# ============================================================================
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd "$HERE/.." && pwd)"
# shellcheck source=scripts/load-env.sh
. "$HERE/load-env.sh"
NGINX_SRC="${NGINX_SRC:-/tmp/sso-build/src/nginx-1.30.4}"
NGINX_BIN="${NGINX_BIN:-$NGINX_SRC/objs/nginx}"
MODULE_DIR="$ROOT/source/rust/target/release"
if [ -f "$MODULE_DIR/libsso_gateway.dylib" ]; then
MODULE="$MODULE_DIR/libsso_gateway.dylib"
else
MODULE="$MODULE_DIR/libsso_gateway.so"
fi
CONF="/tmp/sso-nginx-test.conf"
PID="/tmp/sso-nginx.pid"
SHELL_PID="/tmp/sso-nginx-shell.pid"
ERR_LOG="/tmp/sso-nginx-error.log"
# 签名密钥 / issuer:缺省值兜底,正常情况都由 .env 提供
export OAUTH_SIGNING_SECRET="${OAUTH_SIGNING_SECRET:-$(openssl rand -hex 32)}"
export OAUTH_ISSUER="${OAUTH_ISSUER:-http://127.0.0.1:18098}"
if [ -n "${OAUTH_COOKIE_DOMAIN:-}" ]; then export OAUTH_COOKIE_DOMAIN; fi
stop() {
[ -f "$PID" ] && kill "$(cat "$PID")" 2>/dev/null || true
[ -f "$SHELL_PID" ] && kill "$(cat "$SHELL_PID")" 2>/dev/null || true
rm -f "$PID" "$SHELL_PID"
echo "stopped"
}
case "${1:-start}" in
stop) stop; exit 0 ;;
restart) stop; sleep 0.5 ;;
start) ;;
*) echo "用法: bash $0 [start|stop|restart]" >&2; exit 2 ;;
esac
[ -x "$NGINX_BIN" ] || { echo "!! nginx 二进制缺失:$NGINX_BIN" >&2; exit 1; }
[ -f "$MODULE" ] || { echo "!! Rust 模块缺失:${MODULE}(先 cargo build --release)" >&2; exit 1; }
[ -f "$CONF" ] || {
# 没现成配置就复用 run-local-e2e.sh 的生成逻辑(它会连带物化种子数据)
echo "## 没有 ${CONF},先跑一次 run-local-e2e.sh 生成配置 ..."
bash "$HERE/run-local-e2e.sh" --keep > /dev/null 2>&1 || true
if [ -f "$PID" ]; then kill "$(cat "$PID")" 2>/dev/null || true; fi
pkill -f "demo-system/app.py" 2>/dev/null || true
[ -f "$CONF" ] || { echo "!! 配置生成失败" >&2; exit 1; }
}
"$NGINX_BIN" -c "$CONF" -g 'daemon off;' -e "$ERR_LOG" > /tmp/sso-nginx-stdout.log 2>&1 &
echo $! > "$SHELL_PID"
for i in $(seq 1 20); do
code="$(curl -s -o /dev/null -w '%{http_code}' "${OAUTH_ISSUER}/.well-known/openid-configuration" || true)"
[ "$code" = "200" ] && break
sleep 0.5
done
code="$(curl -s -o /dev/null -w '%{http_code}' "${OAUTH_ISSUER}/.well-known/openid-configuration" || true)"
if [ "$code" != "200" ]; then
echo "!! 网关未就绪(HTTP ${code}),日志:" >&2; tail -30 "$ERR_LOG" >&2; exit 1
fi
echo "started: $OAUTH_ISSUER (discovery=$code)"
echo " admin: ${ADMIN_USER:-admin} / (口令见 .env 的 ADMIN_PASSWORD)"
echo " 停止: bash $0 stop"