当前位置:网站首页>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
边栏推荐
- Rdkit II: use rdkit screening to screen 2D pharmacophores of chemical small molecules
- Mathematical modeling -- analytic hierarchy process model
- xxxxx
- Shardingsphere's level table practice (III)
- (2022杭电多校三)1011-Link is as bear(思维+线性基)
- Reproduce 20 character short domain name bypass and XSS related knowledge points
- C language programming | exchange binary odd and even bits (macro Implementation)
- Shortcut key for adjusting terminal size in ROS
- ROS-Errror:Did you forget to specify generate_ messages(DEPENDENCIES ...)?
- Kubernetes-1.24.x feature
猜你喜欢

Whole process record of yolov3 target detection

MySQL流程控制之while、repeat、loop循环实例分析

Bingbing learning notes: operator overloading -- implementation of date class

实例搭建Flask服务(简易版)

for_ Example of each usage

Example analysis of while, repeat and loop loops in MySQL process control

Violence recursion to dynamic programming 01 (robot movement)

Summary of basic knowledge points of C language

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

ROS - create workspace
随机推荐
容斥原理
最新二开版漫画小说听书三合一完整源码/整合免签接口/搭建教程/带采集接口
向日葵资深产品总监技术分享:“国民远控”如何在AD域环境下应用
Sleuth+Zipkin 来进行分布式服务链路的追踪
Practical application cases of digital Twins - smart energy
Flutter 启动白屏
Easy to use remote sensing data set download website~~~
Rongyun IM & RTC capabilities on new sites
(2022杭电多校三)1011-Link is as bear(思维+线性基)
Tencent cloud logs in with PEM
Sanzi chess (player + computer)
Web uploader cannot upload multiple files
Kubernetes-1.24.x feature
Introduction to JVM foundation I (memory structure)
3D advanced renderer: artlandis studio 2021.2 Chinese version
Multi level wavelet CNN for image restoration
How to realize multi line annotation in MATLAB
How to realize shortcut keys for interface scaling by vscade
向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输
再学EXKMP(EXKMP模板)