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 return nil, err
} }
if workspacesManager, err := policy.GetClusterAction("workspaces", "edit"); err == nil { // workspace manager
if rulesMatchesAction(clusterRules, workspacesManager) { if RulesMatchesRequired(clusterRules, rbacv1.PolicyRule{
return GetWorkspaceRoleSimpleRules(workspace, constants.WorkspaceAdmin), nil Verbs: []string{"*"},
} APIGroups: []string{"*"},
Resources: []string{"workspaces", "workspaces/*"},
}) {
return GetWorkspaceRoleSimpleRules(workspace, constants.WorkspaceAdmin), nil
} }
workspaceRole, err := GetUserWorkspaceRole(workspace, username) workspaceRole, err := GetUserWorkspaceRole(workspace, username)

View File

@@ -20,7 +20,6 @@ package policy
import ( import (
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"kubesphere.io/kubesphere/pkg/models" "kubesphere.io/kubesphere/pkg/models"
@@ -60,7 +59,7 @@ var (
{Name: "workspaces", {Name: "workspaces",
Actions: []models.Action{ Actions: []models.Action{
{ {
Name: "manager", Name: "manage",
Rules: []v1.PolicyRule{ Rules: []v1.PolicyRule{
{ {
Verbs: []string{"*"}, 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")
}