Skip to content

fix: Multiple choice option for namespace in Kubernetes resource permission #5293

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

Merged
merged 9 commits into from
Jun 14, 2024
Merged
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.

Loading