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

Enforcer passes silently a non-existent policy file #163

Closed
anton-khodak opened this issue Nov 19, 2018 · 7 comments
Closed

Enforcer passes silently a non-existent policy file #163

anton-khodak opened this issue Nov 19, 2018 · 7 comments
Assignees
Labels

Comments

@anton-khodak
Copy link

anton-khodak commented Nov 19, 2018

https://github.com/casbin/casbin/blob/master/examples/rbac_with_domains_model.conf
https://github.com/casbin/casbin/blob/master/examples/rbac_with_domains_policy.csv

main.go

package main

import "github.com/casbin/casbin"

func main() {
	e := casbin.NewEnforcer("models/rbac_with_domains_model.conf", "models/rbac_with_domains_model.csv")
	e.Enforce("alice","domain1", "data1", "read")
	e.Enforce("admin", "domain1", "data1", "read")
	e.Enforce("alice","domain1", "data1", "write")
	e.Enforce("alice","domain2", "data2", "write")
	e.Enforce("bob", "domain2", "data2", "write")
}

go build main.go output:

2018/11/19 09:15:43 Model:
2018/11/19 09:15:43 e.e: some(where (p_eft == allow))
2018/11/19 09:15:43 m.m: g(r_sub, p_sub, r_dom) && r_dom == p_dom && r_obj == p_obj && r_act == p_act
2018/11/19 09:15:43 g.g: _, _, _
2018/11/19 09:15:43 r.r: sub, dom, obj, act
2018/11/19 09:15:43 p.p: sub, dom, obj, act
2018/11/19 09:15:43 Request: alice, domain1, data1, read ---> false
2018/11/19 09:15:43 Request: admin, domain1, data1, read ---> false
2018/11/19 09:15:43 Request: alice, domain1, data1, write ---> false
2018/11/19 09:15:43 Request: alice, domain2, data2, write ---> false
2018/11/19 09:15:43 Request: bob, domain2, data2, write ---> false
@hsluoyz
Copy link
Member

hsluoyz commented Nov 19, 2018

The following test has passed in Travis.

casbin/model_test.go

Lines 149 to 160 in 02f3171

func TestRBACModelWithDomains(t *testing.T) {
e := NewEnforcer("examples/rbac_with_domains_model.conf", "examples/rbac_with_domains_policy.csv")
testDomainEnforce(t, e, "alice", "domain1", "data1", "read", true)
testDomainEnforce(t, e, "alice", "domain1", "data1", "write", true)
testDomainEnforce(t, e, "alice", "domain1", "data2", "read", false)
testDomainEnforce(t, e, "alice", "domain1", "data2", "write", false)
testDomainEnforce(t, e, "bob", "domain2", "data1", "read", false)
testDomainEnforce(t, e, "bob", "domain2", "data1", "write", false)
testDomainEnforce(t, e, "bob", "domain2", "data2", "read", true)
testDomainEnforce(t, e, "bob", "domain2", "data2", "write", true)
}

@anton-khodak
Copy link
Author

Can you please try running the code above? For some reason, it works OK when paths are absolute, but gives "falses" if paths are relative.

@hsluoyz
Copy link
Member

hsluoyz commented Nov 19, 2018

I can't reproduce your error. You need to provide a runnable Git repository, which clearly shows the error.

@anton-khodak
Copy link
Author

Oh, the error was that I passed a non-existent file models/rbac_with_domains_model.csv as a policy file. Probably, the enforcer should fail explicitly in this case.

@hsluoyz
Copy link
Member

hsluoyz commented Nov 19, 2018

I already encountered the panic, didn't you see it?

C:\GoPath\src\github.com\casbin\casbin\main>go run main.go
panic: open examples/rbac_with_domains_model.conf: The system cannot find the path specified.

goroutine 1 [running]:
github.com/casbin/casbin/model.Model.LoadModel(0xc00006c720, 0x577528, 0x25)
        C:/GoPath/src/github.com/casbin/casbin/model/model.go:96 +0x18e
github.com/casbin/casbin.NewModel(0xc00007dd28, 0x2, 0x2, 0x40bedf)
        C:/GoPath/src/github.com/casbin/casbin/enforcer.go:147 +0x70
github.com/casbin/casbin.(*Enforcer).InitWithAdapter(0xc0000a2000, 0x577528, 0x25, 0x593720, 0xc00004c470)
        C:/GoPath/src/github.com/casbin/casbin/enforcer.go:109 +0x74
github.com/casbin/casbin.(*Enforcer).InitWithFile(0xc0000a2000, 0x577528, 0x25, 0x5771e6, 0x24)
        C:/GoPath/src/github.com/casbin/casbin/enforcer.go:104 +0x8a
github.com/casbin/casbin.NewEnforcer(0xc00007de28, 0x2, 0x2, 0x110)
        C:/GoPath/src/github.com/casbin/casbin/enforcer.go:73 +0x181
main.main()
        C:/GoPath/src/github.com/casbin/casbin/main/main.go:6 +0x8f
exit status 2

@anton-khodak
Copy link
Author

It panics on the non-existent model file and passes silently on the non-existent policy file.

@hsluoyz
Copy link
Member

hsluoyz commented Nov 19, 2018

This issue is fixed in: 287dc51

@hsluoyz hsluoyz self-assigned this Nov 19, 2018
@hsluoyz hsluoyz added the bug label Nov 19, 2018
@anton-khodak anton-khodak changed the title RBAC with domains model returns false for all enforcements Enforcer passes silently a non-existent policy file Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants