Proposal: 租户隔离、认证与权限模型
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
- Domain
- authentication, authorization, backend
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
背景
总体方案见 #1,数据模型见 #2。多租户是平台红线:任何跨租户数据读写都是最高级缺陷。本文约定隔离机制、认证与权限矩阵。
隔离方案
单库共享 + tenant_id 行级隔离(自部署开源场景最友好,不做 schema / 库级隔离):
- JWT 携带
sub(user id)、tenant(tenant id)、role;租户身份由 token 绑定,接口不接受任何形式的租户自选参数; - auth 中间件解析 token → 注入 request context(
tenant_id、user_id、role); - repository 层统一
scope(ctx):所有查询自动拼tenant_id = ?,handler 禁止拼裸 SQL; - 一人多租户:登录响应返回可加入租户列表,
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 不留半成品接口。
测试要求(评审重点)
- 多租户隔离集成测试:租户 A 的 token 访问租户 B 的工单 / 类型 / 成员 / 附件 / 通知,一律
404 NOT_FOUND(不是 403,避免存在性泄露); - 权限矩阵逐格测试(上表每个 ✗ 都有用例);
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from LinuxSuRen/tick-flow
-
项目门面:logo、README 与仓库 AboutPossibly taken @linuxsuren-fs claimed this 9 days ago. Opendocumentation good first issue help wanted P0
Difficulty 4/5 3-5 days Newbie friendliness 20/100
LinuxSuRen/tick-flow#20 ·
-
编写四个内置种子模板包Possibly taken @linuxsuren-fs claimed this 9 days ago. Opengood first issue help wanted P0
Difficulty 4/5 3-5 days Newbie friendliness 35/100
LinuxSuRen/tick-flow#19 ·
-
实现处理工作台前端:列表、详情与处理动作Possibly taken @linuxsuren-fs claimed this 9 days ago. Openhelp wanted P0
Difficulty 5/5 Over a week Newbie friendliness 25/100
LinuxSuRen/tick-flow#18 ·
-
实现提交门户前端:表单渲染器与我的工单Possibly taken @linuxsuren-fs claimed this 9 days ago. Openhelp wanted P0
Difficulty 4/5 3-5 days Newbie friendliness 25/100
LinuxSuRen/tick-flow#17 ·
-
实现站内通知与邮件通知Possibly taken @linuxsuren-fs claimed this 9 days ago. Openhelp wanted P0
Difficulty 4/5 3-5 days Newbie friendliness 25/100
LinuxSuRen/tick-flow#16 ·
All issues in LinuxSuRen/tick-flow
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
bug security-alert
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
spectrayan/carefold#391 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Pennyw0rth/NetExec#1544 ·
Maintainers usually reply within 1 day
-
security: set top-level least-privilege permissions in five workflowsPossibly taken @JonathanTSilva claimed this today. Openpriority: p2 size: xs type: security
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
JonathanTSilva/jts-website#150 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
router-for-me/CLIProxyAPI#7968 ·
Maintainers usually reply within 1 day