-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.conf
More file actions
44 lines (39 loc) · 1.74 KB
/
model.conf
File metadata and controls
44 lines (39 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Casbin 权限模型配置(支持多租户、临时授权、数据范围)
# =============================================
# 说明:
# - sub: 主体(用户/角色)
# - obj: 资源对象(如 order、contract)
# - act: 操作(如 read、write、delete)
# - tenant: 租户ID,实现多租户隔离
# - org: 组织/部门,用于组织权限
# - data_id: 数据实例ID,实现实例级权限
# - data_filter: 数据范围过滤条件(结构化JSON,见文档)
# - expire_at: 策略有效期,支持临时授权
[request_definition]
# 请求定义,包含所有权限判定所需的上下文参数
r = sub, obj, act, tenant, org, data_id, data_filter
[policy_definition]
# 策略定义,字段顺序需与请求定义一致,额外包含 expire_at
p = sub, obj, act, tenant, org, data_id, data_filter, expire_at
[role_definition]
# 角色继承关系,支持多租户(第三个参数为 tenant)
g = _, _, _ # 用户-角色-租户
# 组织归属关系,支持多租户
g2 = _, _, _ # 用户-组织-租户
[policy_effect]
# 策略效果,只要有一条 allow 策略即允许
e = some(where (p.eft == allow))
[matchers]
# 匹配规则:
# - 用户与角色/组织的多级分组
# - 资源、操作、租户、组织、数据实例的精确或通配符匹配
# - data_filter 支持结构化 JSON 过滤(需在业务代码中解析)
# - expire_at 支持临时授权有效期
m = (g(r.sub, p.sub, r.tenant) || r.sub == p.sub) &&
r.obj == p.obj &&
r.act == p.act &&
r.tenant == p.tenant &&
(g2(r.sub, p.org, r.tenant) || r.org == p.org || p.org == "*") &&
(r.data_id == p.data_id || p.data_id == "*") &&
(p.data_filter == "*" || eval(p.data_filter)) &&
(p.expire_at == "*" || now() < parse_time(p.expire_at))