Proposal: 租户隔离、认证与权限模型

Open
#6 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active

Research direction

Read the linked proposals #1 and #2 for the overall design and data model, then review #8 for the middleware and tenant scope work and #11 for authentication and membership. This issue defines requirements and security tests across tenant isolation, authentication, permissions, and workflow; done means those mechanisms and the specified isolation and permission tests are implemented in the linked work.

Written by the indexing model from the issue text.

Description

proposal

背景

总体方案见 #1,数据模型见 #2。多租户是平台红线:任何跨租户数据读写都是最高级缺陷。本文约定隔离机制、认证与权限矩阵。

隔离方案

单库共享 + tenant_id 行级隔离(自部署开源场景最友好,不做 schema / 库级隔离):

  1. JWT 携带 sub(user id)、tenant(tenant id)、role;租户身份由 token 绑定,接口不接受任何形式的租户自选参数;
  2. auth 中间件解析 token → 注入 request context(tenant_id、user_id、role);
  3. repository 层统一 scope(ctx):所有查询自动拼 tenant_id = ?,handler 禁止拼裸 SQL;
  4. 一人多租户:登录响应返回可加入租户列表,POST /api/auth/select-tenant 换发目标租户 token(P0 支持选择即可,不需要并发多租户会话)。

认证

  • 邮箱 + 密码(bcrypt);禁止任何硬编码默认账号或默认密码;
  • 首次启动 POST /api/auth/setup 创建首个租户与管理员;系统已有数据时该端点返回 404;
  • 成员邀请:tenant_admin 提供邮箱 + 角色,系统创建账号并生成一次性设置密码邀请(token 单次有效、有过期时间);无 SMTP 配置时邀请链接输出到服务端日志,由管理员转交;
  • token 有效期 24h;刷新机制 P1 再做。

角色与权限矩阵

能力 requester agent tenant_admin
创建工单 ✓ ✓ ✓
查看工单 仅自己创建的 全租户 全租户
对外回复 ✓(自己的工单) ✓ ✓
内部备注 ✗ ✓ ✓
状态流转 按 workflow(creator 相对角色) 按 workflow 按 workflow
分派 / 转交 ✗ ✓ ✓
成员管理 ✗ ✗ ✓
工单类型管理 ✗ ✗ ✓
租户品牌设置 ✗ ✗ ✓
  • 中间件链:RequireAuth → RequireRole(...);每个新增 / 修改接口的 PR 必须说明其角色约束(权限与安全随接口同步设计);
  • workflow roles(含 creator 相对角色)在状态机校验时与上表取交集;
  • 平台级超管(跨租户运营)属 P2,P0 不留半成品接口。

测试要求(评审重点)

  1. 多租户隔离集成测试:租户 A 的 token 访问租户 B 的工单 / 类型 / 成员 / 附件 / 通知,一律 404 NOT_FOUND(不是 403,避免存在性泄露);
  2. 权限矩阵逐格测试(上表每个 ✗ 都有用例);
  3. repository scope 单测:漏拼 tenant_id 的查询在测试中直接失败。

Expect

  • 中间件与 scope 机制随 #8 建立;#11 完成认证与成员逻辑。
Dominant language
No language data
Stars
0
Forks
1
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LinuxSuRen/tick-flow

All issues in LinuxSuRen/tick-flow

Similar issues

More Security issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.