fix: workspace manage permission

Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
hongming
2019-04-29 17:37:07 +08:00
committed by zryfish
parent 8268c969ba
commit ed5e1c53e9
2 changed files with 8 additions and 19 deletions

View File

@@ -481,10 +481,13 @@ func GetUserWorkspaceSimpleRules(workspace, username string) ([]models.SimpleRul
return nil, err
}
if workspacesManager, err := policy.GetClusterAction("workspaces", "edit"); err == nil {
if rulesMatchesAction(clusterRules, workspacesManager) {
return GetWorkspaceRoleSimpleRules(workspace, constants.WorkspaceAdmin), nil
}
// workspace manager
if RulesMatchesRequired(clusterRules, rbacv1.PolicyRule{
Verbs: []string{"*"},
APIGroups: []string{"*"},
Resources: []string{"workspaces", "workspaces/*"},
}) {
return GetWorkspaceRoleSimpleRules(workspace, constants.WorkspaceAdmin), nil
}
workspaceRole, err := GetUserWorkspaceRole(workspace, username)

View File

@@ -20,7 +20,6 @@ package policy
import (
"encoding/json"
"fmt"
"io/ioutil"
"kubesphere.io/kubesphere/pkg/models"
@@ -60,7 +59,7 @@ var (
{Name: "workspaces",
Actions: []models.Action{
{
Name: "manager",
Name: "manage",
Rules: []v1.PolicyRule{
{
Verbs: []string{"*"},
@@ -1084,16 +1083,3 @@ var (
},
}
)
func GetClusterAction(module, action string) (models.Action, error) {
for _, rule := range ClusterRoleRuleMapping {
if rule.Name == module {
for _, act := range rule.Actions {
if act.Name == action {
return act, nil
}
}
}
}
return models.Action{}, fmt.Errorf("not found")
}