# iPass 统一网关 —— Cargo workspace # # 结构: # crates/ipass-core 网关内核:共享内存状态、users.json 的唯一读写者、账号与 Key # crates/plugin-sso 身份插件:OAuth2/OIDC 签发与校验、IAP 身份注入 # crates/plugin-domain 域名插件:内核之上「新增一个能力插件」的完整示例 # gateway 装配层:module 壳 + 插件注册表 → 产出单个 .so # # 为什么是「单 .so + crate 级插件」而不是「多 .so 运行时插件」: # nginx 动态模块没有稳定 ABI,Rust 侧更是如此(每个 cdylib 各链一份 std)。 # 跨 .so 共享状态要自己造 C ABI 契约,且 zone tag / 同名变量都会冲突 # (详见 docs/plugin-architecture-analysis.md)。 # # ⚠️ vendor/ngx-rust 本身是 workspace 根,必须 exclude,否则 cargo 报歧义。 [workspace] members = ["crates/ipass-core", "crates/plugin-sso", "crates/plugin-domain", "gateway"] exclude = ["vendor/ngx-rust"] [workspace.package] version = "1.0.0" edition = "2021" publish = false # --------------------------------------------------------------------------- # ⚠️ 依赖必须用 vendored 源码,不能走 crates.io,也不能走 git: # # 1) `ngx = "0.5"`(crates.io 0.5.1)只发布了配置阶段接口(HttpModule), # 请求阶段 API(add_phase_handler / HttpPhase / HttpRequestHandler)尚未发版, # 实测直接编译失败:unresolved imports `ngx::http::HttpPhase` # # 2) git 依赖会永久挂起:ngx-rust 挂了一个指向完整 nginx 仓库的 submodule # [submodule "nginx-src/nginx"] url = https://github.com/nginx/nginx.git # cargo 解析 git 依赖时会 update_submodules,去克隆几十 MB 的 nginx 仓库, # 国内网络下卡死(实测 cargo 5 分钟 0% CPU,调用栈停在 # GitSource::block_until_ready -> GitCheckout::update_submodules -> fetch -> wait4)。 # # 因此 vendor 到 vendor/ngx-rust/,用 path 依赖:离线可编译、无子模块、版本锁定。 # --------------------------------------------------------------------------- [workspace.dependencies] ngx = { path = "vendor/ngx-rust" } nginx-sys = { path = "vendor/ngx-rust/nginx-sys" } ipass-core = { path = "crates/ipass-core" } plugin-sso = { path = "crates/plugin-sso" } plugin-domain = { path = "crates/plugin-domain" } # 业务层依赖:全部是纯 Rust 实现,不引入任何系统库或常驻依赖 serde = { version = "1", features = ["derive"] } serde_json = "1" # 空 Vec / Vec 天然序列化为 [] / {},前后端契约简单 sha2 = "0.10" # 口令哈希 + JWT 的 HMAC-SHA256 + PKCE S256 getrandom = "0.2" # 会话 token / 授权码 / 客户端密钥;不可退化成可预测伪随机 libc = "0.2" # 仅用于 localtime_r / time / strftime [profile.release] opt-level = 3 lto = true codegen-units = 1 # 模块被加载进 nginx 这个 C 进程,panic 绝不能跨 FFI 边界展开 panic = "abort" strip = true