Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Condition Role Manager can support pattern domain For user -> role link #1354

Open
ll9160 opened this issue Jan 14, 2024 · 3 comments

Comments

@ll9160
Copy link

ll9160 commented Jan 14, 2024

Want to prioritize this issue? Try:

issuehunt-to-marktext


What's your scenario? What do you want to achieve?
I have temporary role and assign it some domain that I will use pattern to replace, below model
and policy will failure to enforce, if i change pattern domain to static domain, it will pass, I have
no idea, can you help me to solve it?

Your model:

[request_definition]
r = sub, dom, obj, act

[policy_definition]
p = sub, dom, obj, act, eft

[role_definition]
g = _, _, _, (_, _)

[policy_effect]
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))

[matchers]
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && (r.obj == p.obj || p.obj == '*') && (r.act == p.act || p.act == '*')

Your policy:

p, data2_admin, domain1, data2, read, allow
p, data2_admin, domain2, data2, write, allow

g, alice, data2_admin, *, _, _

Your request(s):

alice, domain1, data2, read ---> false (expected: true)
@casbin-bot
Copy link
Member

@tangyang9464 @JalinWang

@hsluoyz
Copy link
Member

hsluoyz commented Jan 14, 2024

@ll9160 what do you do, what did you expect, what did you get

@ll9160
Copy link
Author

ll9160 commented Jan 14, 2024

Here is my implementation:

gormadapter.TurnOffAutoMigrate(db)
a, err := gormadapter.NewAdapterByDBWithCustomTable(db, &model.CasbinRule{}, "casbin_rule")
if err != nil {
    log.Panicf("new adapter error: %+v", err)
}
m, err := casbin_model.NewModelFromString(`
[request_definition]
r = sub, dom, obj, act

[policy_definition]
p = sub, dom, obj, act, eft

[role_definition]
g = _, _, _, (_, _)

[policy_effect]
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))

[matchers]
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && (r.obj == p.obj || p.obj == '*') && (r.act == p.act || p.act == '*')
`)
if err != nil {
    log.Panicf("new model error: %+v", err)
}
e, err := casbin.NewEnforcer(m, a)
if err != nil {
    log.Panicf("new enforcer error: %+v", err)
}
e.AddNamedDomainMatchingFunc("g", "keyMatch2", util.KeyMatch2)
e.AddNamedDomainLinkConditionFunc("g", "alice", "data2_admin", "domain1", util.TimeMatchFunc)
ok, err := e.Enforce("alice", "domain1", "/", "GET")
if err != nil {
    log.Panicf("enforce error: %+v", err)
}
fmt.Println("result: ", ok)

The policy is define from first comment and there should be true, i always get false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants