Skip to content

Commit

Permalink
fix: Multiple choice option for namespace in Kubernetes resource perm…
Browse files Browse the repository at this point in the history
…ission (#5293)

* fix: multiple namespaces permission group

* chore: rename namespaceObject to namespaceInArray to avoid misunderstanding two diff variables

* chore: main merge
  • Loading branch information
komalreddy3 authored Jun 14, 2024
1 parent f0d6fee commit 1c7b816
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/external-app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/devtron-labs/devtron

go 1.21

//toolchain go1.21.8
toolchain go1.21.8

require (
github.com/Masterminds/semver v1.5.0
Expand Down
19 changes: 11 additions & 8 deletions pkg/auth/user/UserCommonService.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,16 @@ func (impl UserCommonServiceImpl) CheckRbacForClusterEntity(cluster, namespace,
resourceObj = "*"
}

rbacResource := fmt.Sprintf("%s/%s/%s", strings.ToLower(cluster), strings.ToLower(namespaceObj), casbin.ResourceUser)
resourcesArray := strings.Split(resourceObj, ",")
for _, resourceVal := range resourcesArray {
rbacObject := fmt.Sprintf("%s/%s/%s", groupObj, kindObj, resourceVal)
allowed := managerAuth(rbacResource, token, rbacObject)
if !allowed {
return false
namespacesArray := strings.Split(namespaceObj, ",")
for _, namespaceInArray := range namespacesArray {
rbacResource := fmt.Sprintf("%s/%s/%s", strings.ToLower(cluster), strings.ToLower(namespaceInArray), casbin.ResourceUser)
for _, resourceVal := range resourcesArray {
rbacObject := fmt.Sprintf("%s/%s/%s", groupObj, kindObj, resourceVal)
allowed := managerAuth(rbacResource, token, rbacObject)
if !allowed {
return false
}
}
}
return true
Expand Down Expand Up @@ -690,8 +693,8 @@ func (impl UserCommonServiceImpl) GetUniqueKeyForAllEntity(role repository.RoleM
key = fmt.Sprintf("%s_%s_%s_%s", role.Team, role.Action, role.AccessType, role.Entity)
} else if len(role.Entity) > 0 {
if role.Entity == bean.CLUSTER_ENTITIY {
key = fmt.Sprintf("%s_%s_%s_%s_%s_%s", role.Entity, role.Action, role.Cluster,
role.Namespace, role.Group, role.Kind)
key = fmt.Sprintf("%s_%s_%s_%s_%s", role.Entity, role.Action, role.Cluster,
role.Group, role.Kind)
} else {
key = fmt.Sprintf("%s_%s", role.Entity, role.Action)
}
Expand Down
2 changes: 1 addition & 1 deletion wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1c7b816

Please sign in to comment.