当前位置:网站首页>Getting started with caspin
Getting started with caspin
2022-07-29 03:37:00 【Nanyidao street】
List of articles
PERM Metamodel
Policy Strategy
constitute
subject(sub Accessed entities )
object( Resources accessed )
action(act Access method )
eft( Strategy results , It is generally empty , If it is empty, it means allow The situation of )(eft There are only two cases ,allow perhaps deny)
The way of writing
[policy_definition]
p = sub,obj,act,( optional eft)
Request Request rules
constitute
- subject(sub Accessed entities )
- object( Resources accessed )
- action(act Access method )
The way of writing :
[request_definition]
r = sub, obj, act
// and policy similar , Just less eft
Matchers Matching rules
effect :Request and Policy Matching rules of
The way of writing :
[matchers]
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
// Meeting the matching conditions eft Will be returned to effect Expression neutralization effect Expression , Look, what comes back is true still false
Effect influence
Writing rules :
Fixed as the following
| Policy effect | significance | Example |
|---|---|---|
| some(where (p.eft == allow)) | allow-override | ACL, RBAC, etc. |
| !some(where (p.eft == deny)) | deny-override | Deny-override |
| some(where (p.eft == allow)) && !some(where (p.eft == deny)) | allow-and-deny | Allow-and-deny |
| priority(p.eft) || deny | priority | Priority |
| subjectPriority(p.eft) | Role based priority | Topic priority |
role_definition Role domain
g = _,_ Role based
g = _,_,_ Domain based
[role definition]
g = _,_ // first _ On behalf of the user , the second _ Representative role
g = user , role
The user model
stay RBAC In the model , Use g Two related roles , They become universal
Like Guo g relation alice and data2_admin, Can be in policy Of sub Write alice/data2_admin This will pass

Multi tenant model
[role_definition] g = _,_,_
Domain matching rules :g It will receive three parameters
[matchers] m = g(r.sub,p.sub,r.dom)&&r.dom==p.dom&&r.obj==p.obj&&r.act==p.act
[request_definition]
r = sub, dom, obj, act
[policy_definition]
p = sub, dom, obj, act
[role_definition]
g = _, _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && r.act == p.act
Policy
p, admin, domain1, data1, read
p, admin, domain1, data1, write
p, admin, domain1, data2, read
p, admin, domain2, data2, read
p, admin, domain2, data2, write
g, alice, admin, domain1
g, bob, admin, domain2
Request
alice, domain1, data2, read
Result
true

Instance flow :
According to rules r.sub and r.dom Will look for p.sub, We are Policy According to the
gfind alice,admin,domain1 Medium admin in other words alice and admin It is equivalent. , Then we check policy In the rules , We found that According to the following matching rules data2 = data2 ,read = read2 You can exportp,admin,domain1,data2,read This record , Is there , So back true
Actual operation
Save the configuration rules to the database
go get github.com/casbin/gorm-adapter/v3
func main() {
a, _ := gormadapter.NewAdapter("mysql", "root:[email protected](127.0.0.1:3306)/casbin", true) // Your driver and data source.
e, _ := casbin.NewEnforcer("./model.conf", a)
sub := "alice" // Users who want to access resources
obj := "data1" // Resources to be accessed
act := "read" // Operations performed by users on resources
added, err := e.AddPolicy("alice", "data1", "read")
fmt.Println(added)
fmt.Println(err)
ok, err := e.Enforce(sub, obj, act)
if err != nil {
fmt.Println(" Do you eat oil cake ")
fmt.Printf("%s", err)
return
}
if ok == true {
fmt.Println(" litchi ")
} else {
fmt.Println(" Susan ")
}
}
Yes Policy Addition, deletion and modification of
filterPolicy := e.GetFilteredPolicy(0, "alice")// Inquire about index by 0 in , The name is alice The elements of
fmt.Println(filterPolicy)
//[[alice data1 read] [alice data2 read]]
// litchi
add to RBAC Mapping
policy.csv
[role_definition]
g = _,_
[matchers]
m = g(r.sub,p.sub) && r.obj == p.obj && r.act == p.act
// You need to add... To the matching group g(r.sub, p.sub) The relationship between
main.go
边栏推荐
- Use of leak scanning (vulnerability scanning) tool burpsuite or burp Suite (with installation and installation package download of burpsuite+1.7.26)
- 1.5 nn. Module neural network (III)
- 3D advanced renderer: artlandis studio 2021.2 Chinese version
- Sleuth+Zipkin 来进行分布式服务链路的追踪
- 数字孪生实际应用案例-智慧能源篇
- Makefile details
- RTP send and receive h265
- Sleuth+zipkin to track distributed service links
- How to judge stun protocol
- "The programming is not standardized, and my colleagues are in tears!"
猜你喜欢

(codeforce547)C-Mike and Foam(质因子+容斥原理)

Exness: dove resolution helped gold rebound, and the focus turned to U.S. GDP

Ten thousand words detailed Google play online application standard package format AAB
![LeetCode 1331 数组序号转换[Map] HERODING的LeetCode之路](/img/be/d429d0c437dc5ed7cb4448e223a83a.png)
LeetCode 1331 数组序号转换[Map] HERODING的LeetCode之路

Rongyun real-time community solution

Redis之sentinel哨兵集群怎么部署

向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输

暴力递归到动态规划 01 (机器人移动)

Understanding of p-type problems, NP problems, NPC problems, and NP hard problems in natural computing

Configure vscade to realize ROS writing
随机推荐
Military product development process - transition phase
Whole process record of yolov3 target detection
Matlab learning - accumulation of small knowledge points
Web uploader cannot upload multiple files
Set functions in kotlin
Excel splicing database statement
Install the packet capturing certificate
暴力递归到动态规划 01 (机器人移动)
Idea configuration web container and war packaging
Anti vulnerability · benefit from uncertainty --- management?
In depth C language (4) -- definition and use of switch
Numpy acceleration -- > cupy installation
Division of data link layer, protocols used in data link layer and detailed introduction
Leetcode 1331 array sequence number conversion [map] the leetcode path of heroding
LeetCode 1331 数组序号转换[Map] HERODING的LeetCode之路
Bingbing learning notes: operator overloading -- implementation of date class
3.1 common neural network layer (I) image correlation layer
3D advanced renderer: artlandis studio 2021.2 Chinese version
Exness: dove resolution helped gold rebound, and the focus turned to U.S. GDP
Environment configuration stepping pit during colab use