feat(server): tenant RLS 中间件 — SET app.current_tenant_id
- 新增 tenant_rls_middleware:JWT 解析后 SET 租户 ID,请求结束 RESET - 挂载到 protected router 的 JWT 层之后 - SET 失败仅 warn 不阻断(RLS 是安全网,主隔离在应用层) - RESET 防止连接池复用时租户上下文泄漏
This commit is contained in:
@@ -556,6 +556,14 @@ async fn main() -> anyhow::Result<()> {
|
||||
async move { jwt_auth_middleware_fn(secret, Some(db), req, next).await }
|
||||
})
|
||||
})
|
||||
// Tenant RLS — 在 JWT 之后执行,SET app.current_tenant_id
|
||||
.layer({
|
||||
let db = state.db.clone();
|
||||
axum_middleware::from_fn(move |req, next| {
|
||||
let db = db.clone();
|
||||
async move { middleware::tenant_rls::tenant_rls_middleware(db, req, next).await }
|
||||
})
|
||||
})
|
||||
.with_state(state.clone());
|
||||
|
||||
// Merge public + protected into the final application router
|
||||
|
||||
Reference in New Issue
Block a user