**影响**:新建独立仓 ipass-sso 作为 ipass-all 的 SSO-only 精简发行版—— 剔除了 domain / llm / apix / cache / waf 5 个插件及对应的 nginx location 与 LLM/域名数据面 server,PLUGINS 数组只剩 sso + core,单 .so 体积与编 译时间同步下降。镜像名沿用 ssw188/nginx(同 repo 加 tag),新 tag `ipass-sso-v0.6.0`,K8s 部署在 wuguirong ns NodePort 30082,与生产 ipass-all-v0.5.2 (30083/30084/30085) 并存互不干扰。 **改动**: - `rust/Cargo.toml` + `rust/gateway/Cargo.toml`:删 5 个 plugin path 依赖, package/lib 重命名为 `ipass-sso-gateway` / `libipass_sso_gateway` - `rust/gateway/src/lib.rs`:PLUGINS 只剩 `&SsoPlugin` + `&CorePlugin`; GatewayExt 4 个方法改为 no-op / 返回默认值(无 domain/llm 装饰); ModuleConfig 只剩 api + iap 两个开关;NGX_HTTP_COMMANDS 数组 11→4 条; init_process / exit_process 删 llm audit / stats persist 调用; state_zone_init 删 domain/upstreams/apix 的预装载 - `rust/gateway/src/api.rs`:删除(h_admin_trend 依赖 llm + apix) - `deploy/nginx.conf`:删 server 498 (LLM) + server 565 (域名); 主 server 删 `/apix/` `/apixp/` `/_apix_probe/` 等 7 个 location; 删 6 条 `proxy_cache_path` 与 8 个 cache location;删 `ipass_audit_dir` 指令 - `deploy/Dockerfile`:删 5 个 plugin named context 的 COPY 块; .so 文件名改 `libipass_sso_gateway.so` - `deploy/build.sh`:TAG 默认 `ipass-sso-v0.6.0`; 5 个 plugin build-context 删除;删 collect-legacy.sh 调用 - `data-seed/plugin-config.json`:只保留 `sso` 一个 plugin - `scripts/collect-plugin-dist.sh`:PLUGINS 默认值改 `sso` - `scripts/container-entrypoint.sh`:删 cache/audit 目录预创建 - `deploy/legacy/` `tests/` `docs/` `deploy/custom/` `deploy/compose.yml`: 精简版不需要,删除 - `deploy/k8s/ipass-sso.yaml`:新建精简版 K8s manifest (NodePort 30082 单端口;replicas=1;同 10106 准入 + nginx-data PVC sso/ subPath; 探针用 `/admin/` try_files 兜底,与 ipass-all 同款止血方案) **设计**:保留 ipass-core("core 是网关身份底座,永不跳过")+ ipass-plugin-sso, 其余插件整链剥离;不再维护 ssow/ssw 时代的多插件装配文档。剔除 ipass_audit_dir 是因为精简版没有 LLM 对话审计,剔除 proxy_cache_path 同理。K8s 部署沿用 nginx-data PVC + subPath 隔离模式(sso/ 与 ipass-all/ 互不干扰)。 **已知约束**:精简版仍是单进程共享内存,pod 重启使所有管理员/用户会话失效 (与 ipass-all 同款代价)。精简版不带单元/E2E 测试,老管理台 iframe 集成 也未引入。 Co-Authored-By: Claude Code <[email protected]>
172 lines
6.8 KiB
Bash
Executable File
172 lines
6.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
# ============================================================================
|
||
# 物化运行时数据目录:data-seed/ -> data/
|
||
#
|
||
# 为什么需要这一步
|
||
# data/ 是**运行时**目录(可写、含真实口令散列),不进版本库;
|
||
# data-seed/ 是**种子模板**(只放演示客户端与示例账号),进版本库。
|
||
# 本脚本把两者接起来,并顺便把示例里的占位符换成真实值。
|
||
#
|
||
# 做的事:
|
||
# 1. data/oauth_clients.json <- data-seed/oauth_clients.json
|
||
# 2. data/users.json <- 由本脚本生成(admin / alice 两个账号)
|
||
# 3. data/users.json.example <- 同步一份示例(占位符,不含真实散列)
|
||
#
|
||
# 幂等:users.json 已存在时**默认不动**(避免覆盖你手工改过的账号),要重建加 --force。
|
||
#
|
||
# 用法:
|
||
# bash scripts/seed-data.sh # 缺什么补什么
|
||
# bash scripts/seed-data.sh --force # 重建 users.json(会丢已有账号)
|
||
# DATA_DIR=/path ADMIN_PASSWORD=xxx bash scripts/seed-data.sh
|
||
#
|
||
# 口令来源:ADMIN_PASSWORD(默认 123456)、ALICE_PASSWORD(默认 alice123)。
|
||
# 这两个默认值只用于**本机/CI 演示**,生产部署必须覆盖。
|
||
# ============================================================================
|
||
set -euo pipefail
|
||
|
||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
ROOT="$(cd "$HERE/.." && pwd)"
|
||
SEED_DIR="${SEED_DIR:-$ROOT/data-seed}"
|
||
DATA_DIR="${DATA_DIR:-$ROOT/data}"
|
||
|
||
ADMIN_PASSWORD="${ADMIN_PASSWORD:-123456}"
|
||
ALICE_PASSWORD="${ALICE_PASSWORD:-alice123}"
|
||
|
||
FORCE=0
|
||
for a in "$@"; do [ "$a" = "--force" ] && FORCE=1; done
|
||
|
||
PYTHON="${PYTHON:-python3}"
|
||
|
||
[ -d "$SEED_DIR" ] || { echo "!! 种子目录缺失:$SEED_DIR" >&2; exit 1; }
|
||
mkdir -p "$DATA_DIR"
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 1. OAuth 接入方注册表:直接拷贝(没有则视为空表)
|
||
# ---------------------------------------------------------------------------
|
||
if [ -f "$SEED_DIR/oauth_clients.json" ]; then
|
||
if [ ! -f "$DATA_DIR/oauth_clients.json" ] || [ "$FORCE" = "1" ]; then
|
||
cp "$SEED_DIR/oauth_clients.json" "$DATA_DIR/oauth_clients.json"
|
||
echo " [seed] oauth_clients.json 已写入 $DATA_DIR/oauth_clients.json"
|
||
else
|
||
echo " [seed] oauth_clients.json 已存在,跳过"
|
||
fi
|
||
else
|
||
echo " [seed] 警告:$SEED_DIR/oauth_clients.json 不存在,注册表留空"
|
||
fi
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 1.5 插件启停注册表(R19):拷种子(缺省语义是「未列出 = 启用」,但显式
|
||
# 注册表让管理台/运维一眼看清装配了哪些插件,禁用也只改这一个文件)
|
||
# ---------------------------------------------------------------------------
|
||
if [ -f "$SEED_DIR/plugin-config.json" ]; then
|
||
if [ ! -f "$DATA_DIR/plugin-config.json" ] || [ "$FORCE" = "1" ]; then
|
||
cp "$SEED_DIR/plugin-config.json" "$DATA_DIR/plugin-config.json"
|
||
echo " [seed] plugin-config.json 已写入 $DATA_DIR/plugin-config.json"
|
||
else
|
||
echo " [seed] plugin-config.json 已存在,跳过"
|
||
fi
|
||
fi
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 2. 账号表:生成真实散列。
|
||
#
|
||
# ⚠️ 散列算法必须与 rust/src/util.rs::hash_password 逐位一致,
|
||
# 否则生成的账号永远登录不上:
|
||
# x = sha256("salt:password") ← 注意中间是冒号
|
||
# 重复 HASH_ROUNDS(=1000,见 config.rs) 次:x = sha256(x + salt)
|
||
# 改了拼接顺序或轮数,存量 users.json 会全部失效。
|
||
# ---------------------------------------------------------------------------
|
||
if [ -f "$DATA_DIR/users.json" ] && [ "$FORCE" != "1" ]; then
|
||
echo " [seed] users.json 已存在,跳过(要重建加 --force)"
|
||
else
|
||
ADMIN_PASSWORD="$ADMIN_PASSWORD" ALICE_PASSWORD="$ALICE_PASSWORD" \
|
||
OUT="$DATA_DIR/users.json" USERS_EXAMPLE="$SEED_DIR/users.json.example" \
|
||
"$PYTHON" - <<'PYEOF'
|
||
import hashlib, json, os, secrets
|
||
|
||
HASH_ROUNDS = 1000 # 必须与 rust/src/config.rs 的 HASH_ROUNDS 一致
|
||
|
||
def pwd_hash(salt, password):
|
||
x = hashlib.sha256(("%s:%s" % (salt, password)).encode()).hexdigest()
|
||
for _ in range(HASH_ROUNDS):
|
||
x = hashlib.sha256((x + salt).encode()).hexdigest()
|
||
return x
|
||
|
||
def entry(username, display_name, password, role, email, department, groups,
|
||
api_key, created_at=1768000000):
|
||
salt = secrets.token_hex(16) # 32 位 hex
|
||
return {
|
||
"username": username,
|
||
"display_name": display_name,
|
||
"role": role,
|
||
"salt": salt,
|
||
"pwd_hash": pwd_hash(salt, password),
|
||
"api_key": api_key,
|
||
"email": email,
|
||
"department": department,
|
||
"groups": groups,
|
||
"created_at": created_at,
|
||
}
|
||
|
||
users = {
|
||
"admin": entry(
|
||
"admin", "管理员", os.environ["ADMIN_PASSWORD"], "admin",
|
||
"[email protected]", "平台", ["admin"],
|
||
"sk_" + secrets.token_hex(20),
|
||
),
|
||
"alice": entry(
|
||
"alice", "爱丽丝", os.environ["ALICE_PASSWORD"], "user",
|
||
"[email protected]", "研发部", ["rd", "eng"],
|
||
"sk_" + secrets.token_hex(20),
|
||
),
|
||
}
|
||
|
||
out = os.environ["OUT"]
|
||
with open(out, "w", encoding="utf-8") as f:
|
||
json.dump(users, f, ensure_ascii=False, indent=2)
|
||
f.write("\n")
|
||
|
||
# 同步一份「占位符版」示例回种子目录,让后来人一眼看懂字段含义
|
||
HASH_NOTE = "sha256('<salt>:<password>') 后迭代 1000 轮 sha256(x + salt)"
|
||
example = {
|
||
"admin": {
|
||
"username": "admin",
|
||
"display_name": "管理员",
|
||
"role": "admin",
|
||
"salt": "<openssl rand -hex 16>",
|
||
"pwd_hash": "<%s>" % HASH_NOTE,
|
||
"api_key": "sk_<随机>",
|
||
"email": "[email protected]",
|
||
"department": "平台",
|
||
"groups": ["admin"],
|
||
"created_at": 0,
|
||
},
|
||
"alice": {
|
||
"username": "alice",
|
||
"display_name": "爱丽丝",
|
||
"role": "user",
|
||
"salt": "<openssl rand -hex 16>",
|
||
"pwd_hash": "<%s>" % HASH_NOTE,
|
||
"api_key": "sk_<随机>",
|
||
"email": "[email protected]",
|
||
"department": "研发部",
|
||
"groups": ["rd", "eng"],
|
||
"created_at": 0,
|
||
},
|
||
}
|
||
# 回写占位符示例只对「仓库内 host 流程」有意义(容器里种子目录在只读镜像层,
|
||
# 写不进也不该写——10106 非 root 跑会在这里 PermissionError 打断整个 seed)
|
||
example_path = os.environ["USERS_EXAMPLE"]
|
||
if os.access(example_path, os.W_OK):
|
||
with open(example_path, "w", encoding="utf-8") as f:
|
||
json.dump(example, f, ensure_ascii=False, indent=2)
|
||
f.write("\n")
|
||
else:
|
||
print(" [seed] 种子目录不可写(容器镜像层),跳过示例回写:%s" % example_path)
|
||
|
||
print(" [seed] users.json 已生成 %s(admin + alice)" % out)
|
||
PYEOF
|
||
fi
|
||
|
||
echo " [seed] 数据目录就绪:$DATA_DIR"
|