From 1adf93d9a6263e1a150751df0c1031560ed288ed Mon Sep 17 00:00:00 2001 From: wilhelmguo Date: Wed, 13 Mar 2019 18:04:47 +0800 Subject: [PATCH 1/8] backend: add kubernetes resource permission --- src/backend/controllers/base/api.go | 4 +- .../kubernetes/deployment/deployment.go | 4 +- .../controllers/kubernetes/proxy/proxy.go | 22 ++- src/backend/database/initial/data.go | 176 +++++++++++++----- src/backend/models/permission.go | 76 +++++--- 5 files changed, 205 insertions(+), 77 deletions(-) diff --git a/src/backend/controllers/base/api.go b/src/backend/controllers/base/api.go index b499eb59f..c89c379ce 100644 --- a/src/backend/controllers/base/api.go +++ b/src/backend/controllers/base/api.go @@ -62,7 +62,7 @@ func (c *APIController) CheckPermission(perType string, perAction string) { return } else if err != nil && err != orm.ErrNoRows { logs.Info("Check app permission error.%v", err) - c.AbortInternalServerError("Check app permission error.") + c.AbortForbidden("Check app permission error.") } } @@ -73,7 +73,7 @@ func (c *APIController) CheckPermission(perType string, perAction string) { return } else { logs.Info("Check namespace permission error.%v", err) - c.AbortInternalServerError("Check namespace permission error.") + c.AbortForbidden("Check namespace permission error.") } } diff --git a/src/backend/controllers/kubernetes/deployment/deployment.go b/src/backend/controllers/kubernetes/deployment/deployment.go index 17d6af6b1..57a427738 100644 --- a/src/backend/controllers/kubernetes/deployment/deployment.go +++ b/src/backend/controllers/kubernetes/deployment/deployment.go @@ -41,7 +41,7 @@ func (c *KubeDeploymentController) Prepare() { perAction := "" _, method := c.GetControllerAndAction() switch method { - case "Get": + case "Get", "GetDetail": perAction = models.PermissionRead case "Deploy": perAction = models.PermissionDeploy @@ -49,7 +49,7 @@ func (c *KubeDeploymentController) Prepare() { perAction = models.PermissionOffline } if perAction != "" { - c.CheckPermission(models.PermissionTypeDeployment, perAction) + c.CheckPermission(models.PermissionTypeKubeDeployment, perAction) } } diff --git a/src/backend/controllers/kubernetes/proxy/proxy.go b/src/backend/controllers/kubernetes/proxy/proxy.go index 2d2db18f5..6708c2979 100644 --- a/src/backend/controllers/kubernetes/proxy/proxy.go +++ b/src/backend/controllers/kubernetes/proxy/proxy.go @@ -2,11 +2,14 @@ package proxy import ( "encoding/json" + "fmt" "strconv" + "strings" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "github.com/Qihoo360/wayne/src/backend/client/api" "github.com/Qihoo360/wayne/src/backend/controllers/base" "github.com/Qihoo360/wayne/src/backend/models" "github.com/Qihoo360/wayne/src/backend/resources/proxy" @@ -35,13 +38,21 @@ func (c *KubeProxyController) Prepare() { switch method { case "Get", "List", "GetNames": perAction = models.PermissionRead - case "Create", "Update": - perAction = models.PermissionDeploy + case "Create": + perAction = models.PermissionCreate + case "Update": + perAction = models.PermissionUpdate case "Delete": - perAction = models.PermissionOffline + perAction = models.PermissionDelete } + kind := c.Ctx.Input.Param(":kind") + resourceMap, ok := api.KindToResourceMap[kind] + if !ok { + c.AbortBadRequest(fmt.Sprintf("Request resource kind (%s) not supported!", kind)) + } + if perAction != "" { - c.CheckPermission(models.PermissionTypeDeployment, perAction) + c.CheckPermission(fmt.Sprintf("KUBE%s", strings.ToUpper(resourceMap.GroupVersionResourceKind.Kind)), perAction) } } @@ -72,6 +83,9 @@ func (c *KubeProxyController) Get() { // @Title Get all resource names // @Description get all names +// @Param cluster path string true "the cluster name" +// @Param namespace path string true "the namespace name" +// @Param kind path string true "the resource kind" // @Success 200 {object} []response.NamesObject success // @router /names [get] func (c *KubeProxyController) GetNames() { diff --git a/src/backend/database/initial/data.go b/src/backend/database/initial/data.go index efe23189d..f47a4eb24 100644 --- a/src/backend/database/initial/data.go +++ b/src/backend/database/initial/data.go @@ -22,17 +22,17 @@ var InitialData = []string{ `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('55', 'DEPLOYMENT_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('56', 'DEPLOYMENT_READ', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('57', 'DEPLOYMENT_DELETE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('58', 'DEPLOYMENT_DEPLOY', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('59', 'SERVICE_CREATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('60', 'SERVICE_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('61', 'SERVICE_READ', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('62', 'SERVICE_DELETE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('63', 'SERVICE_DEPLOY', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('64', 'CONFIGMAP_CREATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('65', 'CONFIGMAP_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('66', 'CONFIGMAP_READ', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('67', 'CONFIGMAP_DELETE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('68', 'CONFIGMAP_DEPLOY', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('69', 'PVC_CREATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('70', 'PVC_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('71', 'PVC_READ', '', now(), now());`, @@ -45,23 +45,22 @@ var InitialData = []string{ `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('80', 'SECRET_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('81', 'SECRET_READ', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('82', 'SECRET_DELETE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('83', 'SECRET_DEPLOY', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('84', 'NAMESPACE_CREATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('85', 'NAMESPACE_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('86', 'NAMESPACE_READ', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('87', 'NAMESPACE_DELETE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('88', 'APP_DEPLOY', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('89', 'PVC_DEPLOY', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('90', 'CRONJOB_CREATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('91', 'CRONJOB_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('92', 'CRONJOB_READ', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('93', 'CRONJOB_DELETE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('94', 'CRONJOB_DEPLOY', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('95', 'WEBHOOK_CREATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('96', 'WEBHOOK_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('97', 'WEBHOOK_READ', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('98', 'WEBHOOK_DELETE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('99', 'WEBHOOK_DEPLOY', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('100', 'APIKEY_READ', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('101', 'APIKEY_CREATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('102', 'APIKEY_UPDATE', '', now(), now());`, @@ -70,30 +69,119 @@ var InitialData = []string{ `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('105', 'STATEFULSET_CREATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('106', 'STATEFULSET_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('107', 'STATEFULSET_DELETE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('108', 'STATEFULSET_DEPLOY', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('109', 'DAEMONSET_READ', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('110', 'DAEMONSET_CREATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('111', 'DAEMONSET_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('112', 'DAEMONSET_DELETE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('113', 'DAEMONSET_DEPLOY', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('114', 'DEPLOYMENT_OFFLINE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('115', 'DAEMONSET_OFFLINE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('116', 'CRONJOB_OFFLINE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('117', 'STATEFULSET_OFFLINE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('118', 'SERVICE_OFFLINE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('119', 'CONFIGMAP_OFFLINE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('120', 'SECRET_OFFLINE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('121', 'PVC_OFFLINE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('122', 'INGRESS_CREATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('123', 'INGRESS_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('124', 'INGRESS_READ', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('125', 'INGRESS_DELETE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('126', 'INGRESS_DEPLOY', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('127', 'HPA_CREATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('128', 'HPA_UPDATE', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('129', 'HPA_READ', '', now(), now());`, `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('130', 'HPA_DELETE', '', now(), now());`, - `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('131', 'HPA_DEPLOY', '', now(), now());`, + + // Kubernetes resource permission + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('132', 'KUBECONFIGMAP_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('133', 'KUBECONFIGMAP_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('134', 'KUBECONFIGMAP_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('135', 'KUBECONFIGMAP_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('136', 'KUBEDAEMONSET_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('137', 'KUBEDAEMONSET_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('138', 'KUBEDAEMONSET_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('139', 'KUBEDAEMONSET_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('140', 'KUBEDEPLOYMENT_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('141', 'KUBEDEPLOYMENT_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('142', 'KUBEDEPLOYMENT_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('143', 'KUBEDEPLOYMENT_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('144', 'KUBEEVENT_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('145', 'KUBEEVENT_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('146', 'KUBEEVENT_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('147', 'KUBEEVENT_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('148', 'KUBEHORIZONTALPODAUTOSCALER_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('149', 'KUBEHORIZONTALPODAUTOSCALER_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('150', 'KUBEHORIZONTALPODAUTOSCALER_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('151', 'KUBEHORIZONTALPODAUTOSCALER_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('152', 'KUBEINGRESS_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('153', 'KUBEINGRESS_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('154', 'KUBEINGRESS_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('155', 'KUBEINGRESS_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('156', 'KUBEJOB_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('157', 'KUBEJOB_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('158', 'KUBEJOB_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('159', 'KUBEJOB_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('160', 'KUBECRONJOB_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('161', 'KUBECRONJOB_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('162', 'KUBECRONJOB_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('163', 'KUBECRONJOB_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('164', 'KUBENAMESPACE_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('165', 'KUBENAMESPACE_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('166', 'KUBENAMESPACE_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('167', 'KUBENAMESPACE_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('168', 'KUBENODE_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('169', 'KUBENODE_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('170', 'KUBENODE_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('171', 'KUBENODE_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('172', 'KUBEPERSISTENTVOLUMECLAIM_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('173', 'KUBEPERSISTENTVOLUMECLAIM_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('174', 'KUBEPERSISTENTVOLUMECLAIM_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('175', 'KUBEPERSISTENTVOLUMECLAIM_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('176', 'KUBEPERSISTENTVOLUME_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('177', 'KUBEPERSISTENTVOLUME_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('178', 'KUBEPERSISTENTVOLUME_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('179', 'KUBEPERSISTENTVOLUME_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('180', 'KUBEPOD_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('181', 'KUBEPOD_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('182', 'KUBEPOD_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('183', 'KUBEPOD_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('184', 'KUBEREPLICASET_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('185', 'KUBEREPLICASET_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('186', 'KUBEREPLICASET_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('187', 'KUBEREPLICASET_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('188', 'KUBESECRET_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('189', 'KUBESECRET_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('190', 'KUBESECRET_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('191', 'KUBESECRET_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('192', 'KUBESERVICE_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('193', 'KUBESERVICE_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('194', 'KUBESERVICE_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('195', 'KUBESERVICE_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('196', 'KUBESTATEFULSET_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('197', 'KUBESTATEFULSET_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('198', 'KUBESTATEFULSET_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('199', 'KUBESTATEFULSET_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('200', 'KUBEENDPOINTS_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('201', 'KUBEENDPOINTS_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('202', 'KUBEENDPOINTS_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('203', 'KUBEENDPOINTS_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('204', 'KUBESTORAGECLASS_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('205', 'KUBESTORAGECLASS_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('206', 'KUBESTORAGECLASS_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('207', 'KUBESTORAGECLASS_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('208', 'KUBEROLE_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('209', 'KUBEROLE_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('210', 'KUBEROLE_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('211', 'KUBEROLE_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('212', 'KUBEROLEBINDING_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('213', 'KUBEROLEBINDING_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('214', 'KUBEROLEBINDING_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('215', 'KUBEROLEBINDING_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('216', 'KUBECLUSTERROLE_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('217', 'KUBECLUSTERROLE_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('218', 'KUBECLUSTERROLE_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('219', 'KUBECLUSTERROLE_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('220', 'KUBECLUSTERROLEBINDING_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('221', 'KUBECLUSTERROLEBINDING_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('222', 'KUBECLUSTERROLEBINDING_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('223', 'KUBECLUSTERROLEBINDING_DELETE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('224', 'KUBESERVICEACCOUNT_CREATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('225', 'KUBESERVICEACCOUNT_UPDATE', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('226', 'KUBESERVICEACCOUNT_READ', '', now(), now());`, + `INSERT INTO permission ( id, name, comment, create_time, update_time ) VALUES ('227', 'KUBESERVICEACCOUNT_DELETE', '', now(), now());`, // -- group // group 名称前加点可以解决group与mysql内置对象重名的问题 @@ -116,33 +204,32 @@ var InitialData = []string{ `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '55');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '56');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '57');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '58');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '140');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '59');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '60');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '61');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '62');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '63');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '192');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '64');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '65');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '66');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '67');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '68');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '132');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '71');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '79');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '80');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '81');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '82');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '83');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '188');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '90');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '91');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '92');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '93');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '94');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '160');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '95');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '96');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '97');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '98');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '99');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '100');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '101');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '102');`, @@ -151,24 +238,25 @@ var InitialData = []string{ `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '123');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '124');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '125');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '126');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '152');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '127');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '128');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '129');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '130');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '131');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '148');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('10', '172');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '54');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '55');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '56');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '58');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '140');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '59');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '60');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '61');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '63');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '192');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '64');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '65');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '66');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '68');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '132');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '69');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '70');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '71');`, @@ -178,44 +266,42 @@ var InitialData = []string{ `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '79');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '80');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '81');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '83');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '188');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '84');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '85');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '86');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '89');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '172');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '91');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '92');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '94');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '160');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '96');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '97');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '99');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '100');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '123');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '124');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '126');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '152');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '128');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '129');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '131');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('11', '148');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '48');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '54');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '56');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '58');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '140');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '61');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '63');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '192');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '66');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '68');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '132');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '71');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '76');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '81');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '83');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '188');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '92');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '94');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '160');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '124');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '126');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '152');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '129');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '131');`, + `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('12', '148');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('20', '92');`, - `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('20', '94');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('1', '56');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('1', '61');`, `INSERT INTO group_permissions ( group_id, permission_id ) VALUES ('1', '66');`, diff --git a/src/backend/models/permission.go b/src/backend/models/permission.go index 2d1671f19..8148c9a2f 100644 --- a/src/backend/models/permission.go +++ b/src/backend/models/permission.go @@ -35,6 +35,32 @@ const ( PermissionTypeIngress = "INGRESS" PermissionTypeHPA = "HPA" PermissionBlank = "_" + + // Kubernetes resource permission + PermissionTypeKubeConfigMap = "KUBECONFIGMAP" + PermissionTypeKubeDaemonSet = "KUBEDAEMONSET" + PermissionTypeKubeDeployment = "KUBEDEPLOYMENT" + PermissionTypeKubeEvent = "KUBEEVENT" + PermissionTypeKubeHorizontalPodAutoscaler = "KUBEHORIZONTALPODAUTOSCALER" + PermissionTypeKubeIngress = "KUBEINGRESS" + PermissionTypeKubeJob = "KUBEJOB" + PermissionTypeKubeCronJob = "KUBECRONJOB" + PermissionTypeKubeNamespace = "KUBENAMESPACE" + PermissionTypeKubeNode = "KUBENODE" + PermissionTypeKubePersistentVolumeClaim = "KUBEPERSISTENTVOLUMECLAIM" + PermissionTypeKubePersistentVolume = "KUBEPERSISTENTVOLUME" + PermissionTypeKubePod = "KUBEPOD" + PermissionTypeKubeReplicaSet = "KUBEREPLICASET" + PermissionTypeKubeSecret = "KUBESECRET" + PermissionTypeKubeService = "KUBESERVICE" + PermissionTypeKubeStatefulSet = "KUBESTATEFULSET" + PermissionTypeKubeEndpoint = "KUBEENDPOINTS" + PermissionTypeKubeStorageClass = "KUBESTORAGECLASS" + PermissionTypeKubeRole = "KUBEROLE" + PermissionTypeKubeRoleBinding = "KUBEROLEBINDING" + PermissionTypeKubeClusterRole = "KUBECLUSTERROLE" + PermissionTypeKubeClusterRoleBinding = "KUBECLUSTERROLEBINDING" + PermissionTypeKubeServiceAccount = "KUBESERVICEACCOUNT" ) type permissionModel struct{} @@ -68,6 +94,32 @@ type TypePermission struct { PermissionTypeBILL ActionPermission `json:"bill" mapstructure:"BILL"` PermissionIngress ActionPermission `json:"ingress" mapstructure:"INGRESS"` PermissionHPA ActionPermission `json:"hpa" mapstructure:"HPA"` + + // Kubernetes resource permission + PermissionTypeKubeConfigMap ActionPermission `json:"kubeConfigMap" mapstructure:"KUBECONFIGMAP"` + PermissionTypeKubeDaemonSet ActionPermission `json:"kubeDaemonSet" mapstructure:"KUBEDAEMONSET"` + PermissionTypeKubeDeployment ActionPermission `json:"kubeDeployment" mapstructure:"KUBEDEPLOYMENT"` + PermissionTypeKubeEvent ActionPermission `json:"kubeEvent" mapstructure:"KUBEEVENT"` + PermissionTypeKubeHorizontalPodAutoscaler ActionPermission `json:"kubeHorizontalPodAutoscaler" mapstructure:"KUBEHORIZONTALPODAUTOSCALER"` + PermissionTypeKubeIngress ActionPermission `json:"kubeIngress" mapstructure:"KUBEINGRESS"` + PermissionTypeKubeJob ActionPermission `json:"kubeJob" mapstructure:"KUBEJOB"` + PermissionTypeKubeCronJob ActionPermission `json:"kubeCronJob" mapstructure:"KUBECRONJOB"` + PermissionTypeKubeNamespace ActionPermission `json:"kubeNamespace" mapstructure:"KUBENAMESPACE"` + PermissionTypeKubeNode ActionPermission `json:"kubeNode" mapstructure:"KUBENODE"` + PermissionTypeKubePersistentVolumeClaim ActionPermission `json:"kubePersistentVolumeClaim" mapstructure:"KUBEPERSISTENTVOLUMECLAIM"` + PermissionTypeKubePersistentVolume ActionPermission `json:"kubePersistentVolume" mapstructure:"KUBEPERSISTENTVOLUME"` + PermissionTypeKubePod ActionPermission `json:"kubePod" mapstructure:"KUBEPOD"` + PermissionTypeKubeReplicaSet ActionPermission `json:"kubeReplicaSet" mapstructure:"KUBEREPLICASET"` + PermissionTypeKubeSecret ActionPermission `json:"kubeSecret" mapstructure:"KUBESECRET"` + PermissionTypeKubeService ActionPermission `json:"kubeService" mapstructure:"KUBESERVICE"` + PermissionTypeKubeStatefulSet ActionPermission `json:"kubeStatefulSet" mapstructure:"KUBESTATEFULSET"` + PermissionTypeKubeEndpoint ActionPermission `json:"kubeEndpoints" mapstructure:"KUBEENDPOINTS"` + PermissionTypeKubeStorageClass ActionPermission `json:"kubeStorageClass" mapstructure:"KUBESTORAGECLASS"` + PermissionTypeKubeRole ActionPermission `json:"kubeRole" mapstructure:"KUBEROLE"` + PermissionTypeKubeRoleBinding ActionPermission `json:"kubeRoleBinding" mapstructure:"KUBEROLEBINDING"` + PermissionTypeKubeClusterRole ActionPermission `json:"kubeClusterRole" mapstructure:"KUBECLUSTERROLE"` + PermissionTypeKubeClusterRoleBinding ActionPermission `json:"kubeClusterRoleBinding" mapstructure:"KUBECLUSTERROLEBINDING"` + PermissionTypeKubeServiceAccount ActionPermission `json:"kubeServiceAccount" mapstructure:"KUBESERVICEACCOUNT"` } type ActionPermission struct { @@ -139,27 +191,3 @@ func (*permissionModel) MergeName(perType string, perAction string) (perName str perName = perType + PermissionBlank + perAction return perName } - -/* - * 根据publishType获取权限类别 - */ -func (*permissionModel) GetPermissionTypeByPublishType(pType PublishType) (perType string) { - perType = "" - switch pType { - case PublishTypeDeployment: - perType = PermissionTypeDeployment - case PublishTypeService: - perType = PermissionTypeService - case PublishTypeConfigMap: - perType = PermissionTypeConfigMap - case PublishTypeSecret: - perType = PermissionTypeSecret - case PublishTypePersistentVolumeClaim: - perType = PermissionTypePersistentVolumeClaim - case PublishTypeCronJob: - perType = PermissionTypeCronjob - case PublishTypeIngress: - perType = PermissionTypeIngress - } - return perType -} From d8a5648614cfc4185b04157ab1e5085290c823b4 Mon Sep 17 00:00:00 2001 From: wilhelmguo Date: Wed, 13 Mar 2019 18:05:29 +0800 Subject: [PATCH 2/8] frontend: add kubernetes resource permission --- .../portal/autoscale/autoscale.component.html | 10 +-- .../list-autoscale.component.html | 10 +-- .../app/portal/sidenav/sidenav.component.html | 4 +- .../src/app/shared/auth/auth.service.ts | 4 +- .../src/app/shared/model/v1/permission.ts | 76 ++++++++++--------- 5 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/frontend/src/app/portal/autoscale/autoscale.component.html b/src/frontend/src/app/portal/autoscale/autoscale.component.html index 1a6123ba6..1d5b3826e 100644 --- a/src/frontend/src/app/portal/autoscale/autoscale.component.html +++ b/src/frontend/src/app/portal/autoscale/autoscale.component.html @@ -1,4 +1,4 @@ - @@ -16,19 +16,19 @@