refactor(paths): 拆 source/ 包层,顶层与 ipass/ipass 对齐
- source/rust → rust/ - source/conf → conf/ - source/www → www/ - source/data-seed → data-seed/ - source/data → data/ - scripts/ 保留(语义不对应 ipass deploy/) - /build/ 加入 .gitignore(本机 nginx 源码树) - README.md 目录树同步 + build 路径 /tmp/sso-build → ./build - Cargo.toml path 依赖 '../../deps/ipass' → '../deps/ipass' - CLAUDE.md 同步路径示例 cargo check 通过(52s);release build 通过(1m26s),产物 libsso_gateway.dylib
This commit is contained in:
1 parent
f9c2324c47
commit
1e2b117218
50 files changed
+138
-136
No files matched your search
+29
-29
@@ -85,7 +85,7 @@
|
||||
|
||||
---
|
||||
|
||||
## 5. 客户端模型(`source/data/oauth_clients.json`)
|
||||
## 5. 客户端模型(`data/oauth_clients.json`)
|
||||
|
||||
顶层是 `OAuthClient` 数组(与 `users.json` / `domains.json` 同构:文件是唯一真源,启动时全量装载进共享内存 `ocl:` 前缀,热路径只读内存)。
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
|
||||
---
|
||||
|
||||
## 6. 用户模型(`source/data/users.json` 新增身份字段)
|
||||
## 6. 用户模型(`data/users.json` 新增身份字段)
|
||||
|
||||
在既有用户结构基础上,`User` 新增三个 `#[serde(default)]` 字段,支撑 token 声明与 IAP 注入:
|
||||
|
||||
@@ -297,23 +297,23 @@ server {
|
||||
|
||||
| 文件 | 改动 |
|
||||
| --- | --- |
|
||||
| `source/rust/src/oauth.rs` | **新增**:OAuth2 AS 全部逻辑(client/code/token 模型、HS256 JWT 签名/验签、PKCE、端点 handler、IAP 身份解析) |
|
||||
| `source/rust/src/oauth_clients.rs` | **新增**:客户端注册表模块(`reload_shm` / `get` / `all` / `upsert` / `delete` / `view`) |
|
||||
| `source/rust/src/api.rs` | `route()` 增加 `/oauth/authorize`、`/oauth/token`、`/oauth/userinfo`、`/oauth/introspect`、`.well-known`、`/oauth/jwks`、`/login`、`/oauth/logout`,转发到 `oauth::*` |
|
||||
| `source/rust/src/lib.rs` | 新增 `sso_iap` 指令 + `IapHandler`(access 阶段门禁 + 写 `$auth_*` 变量);`AUTH_VAR_INDEX[5]` + `AUTH_VAR_NAMES`;`register_auth_vars()`(`add_variable` 挂 `auth_var_get` + `get_variable_index`)在 preconfiguration 注册;`state_zone_init` 调 `oauth_clients::reload_shm()` |
|
||||
| `source/rust/src/config.rs` | 新增 OAuth 常量区(`KEY_OAUTH_*` 前缀、TTL、cookie、env 名、scopes、challenge 方法) |
|
||||
| `source/rust/src/models.rs` | `User` 增 `email`/`department`/`groups` + `oauth_claims()`;新增 `OAuthClient` + `OAuthClientTable`(`allows_scope/allows_redirect/allows_grant`) |
|
||||
| `source/rust/src/state.rs` | 新增 `oauth_session` / `oauth_code` / `oauth_client` 共享内存封装;`split_value` 改用 `rposition` |
|
||||
| `source/rust/src/store.rs` | 新增 `oauth_clients_path` / `read/write/update_oauth_clients` |
|
||||
| `source/rust/src/util.rs` | 新增 `url_encode`/`html_escape`;`HEX` 常量提升为模块级 |
|
||||
| `rust/src/oauth.rs` | **新增**:OAuth2 AS 全部逻辑(client/code/token 模型、HS256 JWT 签名/验签、PKCE、端点 handler、IAP 身份解析) |
|
||||
| `rust/src/oauth_clients.rs` | **新增**:客户端注册表模块(`reload_shm` / `get` / `all` / `upsert` / `delete` / `view`) |
|
||||
| `rust/src/api.rs` | `route()` 增加 `/oauth/authorize`、`/oauth/token`、`/oauth/userinfo`、`/oauth/introspect`、`.well-known`、`/oauth/jwks`、`/login`、`/oauth/logout`,转发到 `oauth::*` |
|
||||
| `rust/src/lib.rs` | 新增 `sso_iap` 指令 + `IapHandler`(access 阶段门禁 + 写 `$auth_*` 变量);`AUTH_VAR_INDEX[5]` + `AUTH_VAR_NAMES`;`register_auth_vars()`(`add_variable` 挂 `auth_var_get` + `get_variable_index`)在 preconfiguration 注册;`state_zone_init` 调 `oauth_clients::reload_shm()` |
|
||||
| `rust/src/config.rs` | 新增 OAuth 常量区(`KEY_OAUTH_*` 前缀、TTL、cookie、env 名、scopes、challenge 方法) |
|
||||
| `rust/src/models.rs` | `User` 增 `email`/`department`/`groups` + `oauth_claims()`;新增 `OAuthClient` + `OAuthClientTable`(`allows_scope/allows_redirect/allows_grant`) |
|
||||
| `rust/src/state.rs` | 新增 `oauth_session` / `oauth_code` / `oauth_client` 共享内存封装;`split_value` 改用 `rposition` |
|
||||
| `rust/src/store.rs` | 新增 `oauth_clients_path` / `read/write/update_oauth_clients` |
|
||||
| `rust/src/util.rs` | 新增 `url_encode`/`html_escape`;`HEX` 常量提升为模块级 |
|
||||
| `conf/nginx.conf` | 新增 IdP server(18098)+ IAP 代理 server(18099) |
|
||||
| `source/conf/nginx.test.conf` | **新增**:本地最小验证配置(IdP 18098 + IAP 18099 + 回显后端 18097) |
|
||||
| `conf/nginx.test.conf` | **新增**:本地最小验证配置(IdP 18098 + IAP 18099 + 回显后端 18097) |
|
||||
| `tests/oauth2-e2e.sh` | **新增**:14 项端到端断言(客户端密钥运行时从种子读取,不硬编码) |
|
||||
| `scripts/run-local-e2e.sh` | **新增**:macOS 本机 nginx + 模块一键起停并跑 e2e |
|
||||
| `source/data/users.json` | 种子用户补充 `email`/`department`/`groups`(数组) |
|
||||
| `source/data/oauth_clients.json`(及 `source/data-seed/`) | 新增 OAuth 客户端注册表(grafana / spa-demo / machine) |
|
||||
| `data/users.json` | 种子用户补充 `email`/`department`/`groups`(数组) |
|
||||
| `data/oauth_clients.json`(及 `data-seed/`) | 新增 OAuth 客户端注册表(grafana / spa-demo / machine) |
|
||||
| `deps/ipass/rust/vendor/ngx-rust/nginx-sys/build/` | **补回**:`main.rs` + `wrapper.h`(官方 0.5.0 crate 的 bindgen 构建脚本,原被子模块内 `.gitignore` 的 `build/` 规则吞掉) |
|
||||
| `.gitignore` | 子模块内加 `!rust/vendor/ngx-rust/nginx-sys/build/` 例外,本仓库放行 `source/data/oauth_clients.json` |
|
||||
| `.gitignore` | 子模块内加 `!rust/vendor/ngx-rust/nginx-sys/build/` 例外,本仓库放行 `data/oauth_clients.json` |
|
||||
|
||||
---
|
||||
|
||||
@@ -332,21 +332,21 @@ curl -fsSL https://nginx.org/download/nginx-1.30.4.tar.gz -o nginx.tar.gz && tar
|
||||
curl -fsSL https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.44/pcre2-10.44.tar.gz -o pcre2.tar.gz && tar xzf pcre2.tar.gz
|
||||
|
||||
# ② 编 nginx(须含 rewrite 模块,`return` 指令来自它)
|
||||
cd nginx-1.30.4 && ./configure --prefix=/tmp/sso-build/nginx \
|
||||
--with-pcre=/tmp/sso-build/src/pcre2-10.44 --with-http_realip_module \
|
||||
cd nginx-1.30.4 && ./configure --prefix=./build/nginx \
|
||||
--with-pcre=./build/src/pcre2-10.44 --with-http_realip_module \
|
||||
--without-http_gzip_module --without-http_ssi_module --without-http_userid_module \
|
||||
--without-http_autoindex_module --without-http_geo_module \
|
||||
--without-http_split_clients_module --without-http_referer_module \
|
||||
--without-http_uwsgi_module --without-http_scgi_module --without-http_grpc_module \
|
||||
&& make -j"$(sysctl -n hw.ncpu)"
|
||||
# 建 prefix 临时目录(没跑 make install 时 nginx 起不来)
|
||||
mkdir -p /tmp/sso-build/nginx/{client_body_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp,logs,conf}
|
||||
mkdir -p ./build/nginx/{client_body_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp,logs,conf}
|
||||
|
||||
# ③ 编 Rust 模块(输出 source/rust/target/release/libsso_gateway.dylib)
|
||||
cd source/rust
|
||||
# ③ 编 Rust 模块(输出 rust/target/release/libsso_gateway.dylib)
|
||||
cd rust
|
||||
export LIBCLANG_PATH=/Library/Developer/CommandLineTools/usr/lib
|
||||
export NGINX_SOURCE_DIR=/tmp/sso-build/src/nginx-1.30.4
|
||||
export NGINX_BUILD_DIR=/tmp/sso-build/src/nginx-1.30.4/objs
|
||||
export NGINX_SOURCE_DIR=./build/src/nginx-1.30.4
|
||||
export NGINX_BUILD_DIR=./build/src/nginx-1.30.4/objs
|
||||
cargo build --release
|
||||
```
|
||||
|
||||
@@ -368,7 +368,7 @@ bash tests/oauth2-maxkey-e2e.sh http://127.0.0.1:18098 http://127.0.0.1:180
|
||||
bash tests/admin-oauth-clients-e2e.sh http://127.0.0.1:18098
|
||||
```
|
||||
|
||||
脚本自动完成:`scripts/seed-data.sh` 物化 `source/data/`(生成 admin/alice 口令散列)、
|
||||
脚本自动完成:`scripts/seed-data.sh` 物化 `data/`(生成 admin/alice 口令散列)、
|
||||
生成 macOS 本机配置(替换 `load_module` / `mime.types` / `ipass_data_dir` / `pid` /
|
||||
`error_log`,注释掉 TLS include,regex `server_name` 降级为 `_`)、注入
|
||||
`OAUTH_SIGNING_SECRET` + `OAUTH_ISSUER`(可选 `OAUTH_COOKIE_DOMAIN`)、
|
||||
@@ -416,7 +416,7 @@ bash scripts/run-local-e2e.sh # 起服务 + 三套 e2e + 关服务
|
||||
bash scripts/run-local-e2e.sh --keep # 保留进程手工排查
|
||||
```
|
||||
|
||||
生产部署见 `source/conf/nginx.conf` + `source/conf/tls/README.md`。
|
||||
生产部署见 `conf/nginx.conf` + `conf/tls/README.md`。
|
||||
|
||||
---
|
||||
|
||||
@@ -537,10 +537,10 @@ location / { ipass_api on; }
|
||||
|
||||
| 文件 | 改动 |
|
||||
| --- | --- |
|
||||
| `source/rust/src/api.rs` | 别名路由表 + `MAXKEY_CONTEXT_PREFIXES` / `strip_maxkey_ctx`,`dispatch` 在 miss 后归一化重试 |
|
||||
| `source/rust/src/oauth.rs` | `access_token_of`(Bearer → `access_token` 参数回退);`userinfo_v20`(MaxKey 扁平字段);`token_v20` + `send_token_body(bare)`;`mint_access_token` 声明语义修正 |
|
||||
| `conf/nginx.conf`、`source/conf/nginx.test.conf` | IdP server 整站 `location / { ipass_api on; }` |
|
||||
| `source/data/oauth_clients.json`、`source/data-seed/` | 新增 `demo-system`(机密)、`demo-spa`(公开 + PKCE) |
|
||||
| `rust/src/api.rs` | 别名路由表 + `MAXKEY_CONTEXT_PREFIXES` / `strip_maxkey_ctx`,`dispatch` 在 miss 后归一化重试 |
|
||||
| `rust/src/oauth.rs` | `access_token_of`(Bearer → `access_token` 参数回退);`userinfo_v20`(MaxKey 扁平字段);`token_v20` + `send_token_body(bare)`;`mint_access_token` 声明语义修正 |
|
||||
| `conf/nginx.conf`、`conf/nginx.test.conf` | IdP server 整站 `location / { ipass_api on; }` |
|
||||
| `data/oauth_clients.json`、`data-seed/` | 新增 `demo-system`(机密)、`demo-spa`(公开 + PKCE) |
|
||||
|
||||
---
|
||||
|
||||
@@ -670,7 +670,7 @@ DEMO_STYLE=standard DEMO_CLIENT_ID=demo-spa DEMO_PORT=18096 python3 examples/dem
|
||||
列表类字段(`redirect_uris` / `grant_types` / `scopes`)**传字符串**即可:逗号、顿号、
|
||||
分号、空格、换行都是分隔符——前端 textarea 一行一个回调地址的自然写法直接可用。
|
||||
之所以不传 JSON 数组:`http::params` 解析 JSON body 时只收 String/Number/Bool,
|
||||
数组会被跳过(见 `source/rust/src/http.rs`)。
|
||||
数组会被跳过(见 `rust/src/http.rs`)。
|
||||
|
||||
### 17.3 校验规则(写死在 `oauth_clients::upsert`)
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ MaxKey 的 44 张表里,对本项目最有参考价值的三组设计:
|
||||
| 同步连接器 | `plugin-sso/src/sync.rs` | `POST /api/admin/sync/{dingtalk,workwechat,feishu}`(管理员,手动触发);标准库 TcpStream 拉取,归一化 `{users:[...]}` → upsert | §D(钉钉 mock) |
|
||||
| 自助密码重置 | `plugin-sso/src/reset.rs` | `POST /api/public/forgot-password`、`/reset-password`;token 共享内存、单次有效、防账号枚举;发信可配置(日志 / `PASSWORD_RESET_TOKEN_SINK` 文件 / 生产 SMTP-webhook) | §C |
|
||||
| ip2location | `plugin-sso/src/geo.rs` | 内嵌代表性 CN IPv4 CIDR 表 + 内网/保留段判定,零依赖粗判「内网/中国/海外」 | 审计日志 / 管理台「会话·审计」页 |
|
||||
| **管理台界面** | `source/www/admin.html` | 新增「身份同步」(钉钉/企微/飞书手动触发 + 结果)、「会话 / 审计」(在线会话 + 踢下线 + 审计含归属地)两个页签;账号行加「双因子」;接入指南补 CAS / SCIM / LDAP 三段 | `tests/maxkey-p1p2-e2e.sh` §F |
|
||||
| **管理台界面** | `www/admin.html` | 新增「身份同步」(钉钉/企微/飞书手动触发 + 结果)、「会话 / 审计」(在线会话 + 踢下线 + 审计含归属地)两个页签;账号行加「双因子」;接入指南补 CAS / SCIM / LDAP 三段 | `tests/maxkey-p1p2-e2e.sh` §F |
|
||||
| **终端用户页面** | `plugin-sso/src/reset.rs`(`GET /forgot`、`GET /reset?token=`)+ `oauth.rs` 登录页入口 | 自助密码重置的可点开入口;`send_reset` 的重置链接改为指向页面 URL(原来指向 POST 端点,点开必然失败) | §F |
|
||||
| **应用管理增强** | `oauth_state.rs` / `oauth_clients.rs` / `admin.html` | 接入方新增 **协议类型**(oauth2/cas)、**访问地址**、**描述**、**图标**、**可见范围**(角色/部门/用户组,三项全空=全员);管理台表单与列表同步(`#[serde(default)]` 向后兼容存量注册表) | §G |
|
||||
| **CAS service 白名单** | `cas.rs` + `oauth_clients::allows_cas_service` | `service` 必须命中已登记回调地址(精确或忽略 query),否则 login → 403、serviceValidate → `INVALID_SERVICE`。**修复开放重定向 + 票据外泄**:原先任意 service 都会被 302 带票据 | §B |
|
||||
|
||||
@@ -56,7 +56,7 @@ if (tag != shm_zone[i].tag) {
|
||||
而两边现在传的都是**自己模块的 `ngx_module_t` 地址**:
|
||||
|
||||
```rust
|
||||
// source/rust/src/lib.rs:451
|
||||
// rust/src/lib.rs:451
|
||||
ngx_shared_memory_add(cf, &raw mut name, size, (&raw mut ngx_http_sso_module).cast())
|
||||
// refs/ipass/rust/src/lib.rs:824
|
||||
ngx_shared_memory_add(cf, &raw mut name, size, (&raw mut ngx_http_ipass_module).cast())
|
||||
@@ -100,7 +100,7 @@ unsafe { (*var).get_handler = Some(auth_var_get); } // 覆盖
|
||||
> `deps/ipass` git 子模块(`ipass/ipass`)提供,不再内置。
|
||||
|
||||
```
|
||||
source/rust/ # 本仓库的 Cargo workspace
|
||||
rust/ # 本仓库的 Cargo workspace
|
||||
├── Cargo.toml # members = [crates/plugin-sso, gateway];ipass-core/ngx-rust 走 deps/ipass 的 path 依赖
|
||||
├── crates/
|
||||
│ └── plugin-sso/ # 身份插件:OAuth2/OIDC + IAP 注入(本仓库唯一业务 crate)
|
||||
@@ -188,8 +188,8 @@ pub trait Plugin {
|
||||
| --- | --- |
|
||||
| zone tag 不同 → EMERG 启动失败 | `src/core/ngx_cycle.c` → `ngx_shared_memory_add` |
|
||||
| 同名 + CHANGEABLE → 返回已有变量而非新建 | `src/http/ngx_http_variables.c` → `ngx_http_add_variable` |
|
||||
| sso 的 zone tag = `&ngx_http_sso_module` | `source/rust/src/lib.rs:451` |
|
||||
| sso 的 zone tag = `&ngx_http_sso_module` | `rust/src/lib.rs:451` |
|
||||
| ipass 的 zone tag = `&ngx_http_ipass_module` | `refs/ipass/rust/src/lib.rs:824` |
|
||||
| 两边注册同名 `$auth_*` 且覆盖 get_handler | `source/rust/src/lib.rs:254-262`、`refs/ipass/rust/src/lib.rs:89` |
|
||||
| 两边注册同名 `$auth_*` 且覆盖 get_handler | `rust/src/lib.rs:254-262`、`refs/ipass/rust/src/lib.rs:89` |
|
||||
| 键前缀全景 | `refs/ipass/rust/src/config.rs:66-101` |
|
||||
| 代码重复量(oauth 425 / users 525 / models 234 / state 150 行差异) | 两仓库同名文件 diff |
|
||||
+2
-2
@@ -8,7 +8,7 @@
|
||||
## v1(已完成)
|
||||
|
||||
- [x] 从内部网关项目剥离出独立 SSO 服务(去掉动态域名转发 / LLM 上游代理 / 用量计费)
|
||||
- [x] 目录重组:`docs/` `source/` `tests/` `scripts/`
|
||||
- [x] 目录重组:`docs/` `rust/` `conf/` `www/` `data/` `data-seed/` `tests/` `scripts/`
|
||||
- [x] 自包含 IdP:四种 grant + PKCE + discovery + introspect + userinfo
|
||||
- [x] IAP 身份注入:`X-Auth-*` 五头,客户端伪造同名头被覆盖
|
||||
- [x] MaxKey 端点别名与 context-path 归一化
|
||||
@@ -209,7 +209,7 @@
|
||||
- [x] **ip2location 登录 IP 归属地**(`geo.rs`):内嵌 CN CIDR 精简版,审计记录归属地
|
||||
- [x] 新增第 7 套 e2e `tests/maxkey-p1p2-e2e.sh`(SCIM / CAS / 密码重置 / 同步 / LDAP 禁用回归,21 项);
|
||||
**七套全绿 rc=0**
|
||||
- [x] **管理台界面补齐**(`source/www/admin.html`):新增「身份同步」页签(钉钉/企微/飞书手动触发 + 结果表)、
|
||||
- [x] **管理台界面补齐**(`www/admin.html`):新增「身份同步」页签(钉钉/企微/飞书手动触发 + 结果表)、
|
||||
「会话 / 审计」页签(在线会话列表 + 踢下线、审计日志含 IP 归属地);账号行加「双因子」按钮;
|
||||
接入指南补 CAS 1.0/2.0、SCIM 2.0、LDAP/AD 三段端点与配置说明。接入方/Session/审计均复用既有 API,后端零改动。
|
||||
- [x] **自助密码重置的终端用户页面**:新增 `GET /forgot`(找回)与 `GET /reset?token=…`(设新口令)两个 HTML 页,
|
||||
|
||||
Reference in new issue
Block a user