Skip to content

Commit

Permalink
fix: empty matched policies list for roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiu Jian committed May 22, 2020
1 parent 575f1c2 commit 728524f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/cloudcommon/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,10 @@ func (manager *SPolicyManager) AllPolicies() map[string][]string {
}

func (manager *SPolicyManager) RoleMatchPolicies(roleName string) []string {
ident := rbacutils.NewRbacIdentity("", "", []string{roleName})
ret := make([]string, 0)
for _, policies := range manager.policies {
for i := range policies {
ident := rbacutils.NewRbacIdentity("", "", []string{roleName})
if matched, _ := policies[i].Policy.Match(ident); matched {
ret = append(ret, policies[i].Name)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/rbacutils/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (policy *SRbacPolicy) IsSystemWidePolicy() bool {
}

func (policy *SRbacPolicy) MatchDomain(domainId string) bool {
if len(policy.DomainId) == 0 {
if len(domainId) == 0 {
return true
}
if policy.DomainId == domainId {
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/rbacutils/rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,15 @@ func TestSRbacPolicyMatch(t *testing.T) {
},
true,
},
{
SRbacPolicy{
Projects: []string{},
Roles: []string{"admin"},
Auth: true,
},
NewRbacIdentity("", "", []string{"admin"}),
true,
},
}
for i, c := range cases {
got, _ := c.policy.Match(c.userCred)
Expand Down

0 comments on commit 728524f

Please sign in to comment.