Skip to content

Commit f7d26da

Browse files
authored
feat: k8s api 鉴权支持放开共享集群特定集群域资源的权限 (#3824)
* feat: k8s api 鉴权支持放开共享集群特定集群域资源的权限 * feat: golangci-lint 修复
1 parent 29f1b3e commit f7d26da

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

bcs-services/bcs-cluster-manager/internal/actions/nodegroup/list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ package nodegroup
1515
import (
1616
"context"
1717
"fmt"
18-
v1 "k8s.io/api/core/v1"
1918
"sort"
2019

2120
"github.com/Tencent/bk-bcs/bcs-common/common/blog"
2221
"github.com/Tencent/bk-bcs/bcs-common/pkg/odm/operator"
22+
v1 "k8s.io/api/core/v1"
2323

2424
cmproto "github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/api/clustermanager"
2525
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/actions"
@@ -200,6 +200,7 @@ func (la *ListAction) listOpt() *storeopt.ListOption {
200200
}
201201

202202
const (
203+
// nolint:unused
203204
nodegroupListDefaultLimit = 100
204205
)
205206

bcs-services/bcs-user-manager/app/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func parseConfig(op *options.UserManagerOptions) (*config.UserMgrConfig, error)
106106
userMgrConfig.BcsAPI = &op.BcsAPI
107107
userMgrConfig.Encrypt = op.Encrypt
108108
userMgrConfig.Activity = op.Activity
109+
userMgrConfig.SharedCluster = op.SharedCluster
109110
userMgrConfig.EnableTokenSync = op.EnableTokenSync
110111
userMgrConfig.SlowSQLLatency = op.SlowSQLLatency
111112

bcs-services/bcs-user-manager/app/user-manager/v1http/permission/verify.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/Tencent/bk-bcs/bcs-services/bcs-user-manager/app/pkg/utils"
3333
"github.com/Tencent/bk-bcs/bcs-services/bcs-user-manager/app/user-manager/models"
3434
"github.com/Tencent/bk-bcs/bcs-services/bcs-user-manager/app/user-manager/storages/sqlstore"
35+
"github.com/Tencent/bk-bcs/bcs-services/bcs-user-manager/config"
3536
)
3637

3738
var (
@@ -533,6 +534,10 @@ func (cli *PermVerifyClient) verifyUserClusterScopedPermission(ctx context.Conte
533534
actionID := ""
534535
clusterType := returnClusterType(resource)
535536
if clusterType == Shared {
537+
// 共享集群特定资源跳过权限校验
538+
if skipSpecificResources(action, resource) {
539+
return true, nil
540+
}
536541
return false, fmt.Errorf("shared cluster[%s] not support %s permission", resource.ClusterID, clusterScopedType)
537542
}
538543

@@ -586,6 +591,20 @@ func (cli *PermVerifyClient) verifyUserClusterScopedPermission(ctx context.Conte
586591
return allow, nil
587592
}
588593

594+
// skipSpecificResources check if the resource is in the skip list
595+
func skipSpecificResources(action string, resource ClusterResource) bool {
596+
// 仅支持查看权限跳过
597+
if action != http.MethodGet {
598+
return false
599+
}
600+
for _, skipRes := range config.GetGlobalConfig().SharedCluster.SkipResources {
601+
if skipRes == resource.ResourceType {
602+
return true
603+
}
604+
}
605+
return false
606+
}
607+
589608
// getK8sRequestAPIInfo
590609
func getK8sRequestAPIInfo(method, url string) (*parser.RequestInfo, error) {
591610
resolver := parser.NewRequestInfoResolver()

bcs-services/bcs-user-manager/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ type UserMgrConfig struct {
119119

120120
// 操作记录清理
121121
Activity options.Activity
122+
// 共享集群权限配置
123+
SharedCluster options.SharedCluster
122124
}
123125

124126
var (

bcs-services/bcs-user-manager/options/options.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ type UserManagerOptions struct {
4646
// token notify feature
4747
TokenNotify TokenNotifyOptions `json:"token_notify"`
4848

49-
IAMConfig IAMConfig `json:"iam_config"`
50-
PermissionSwitch bool `json:"permission_switch"`
51-
Cmdb CmdbConfig `json:"cmdb"`
52-
CommunityEdition bool `json:"community_edition"`
53-
TracingConf TracingConf `json:"tracing_conf"`
54-
BcsAPI BcsAPI `json:"bcs_api"`
55-
Encrypt Encrypt `json:"encrypt" yaml:"encrypt"`
56-
Activity Activity `json:"activity" yaml:"activity"`
49+
IAMConfig IAMConfig `json:"iam_config"`
50+
PermissionSwitch bool `json:"permission_switch"`
51+
Cmdb CmdbConfig `json:"cmdb"`
52+
CommunityEdition bool `json:"community_edition"`
53+
TracingConf TracingConf `json:"tracing_conf"`
54+
BcsAPI BcsAPI `json:"bcs_api"`
55+
Encrypt Encrypt `json:"encrypt" yaml:"encrypt"`
56+
Activity Activity `json:"activity" yaml:"activity"`
57+
SharedCluster SharedCluster `json:"shared_cluster" yaml:"shared_cluster"`
5758
}
5859

5960
// TracingConf tracing config
@@ -176,3 +177,8 @@ type RedisConfig struct {
176177
MinIdleConns int `json:"min_idle_conns" usage:"Redis min connect" mapstructure:"min_idle_conns" yaml:"min_idle_conns"`
177178
IdleTimeout int `json:"idle_timeout" usage:"Redis idle timeout" mapstructure:"idle_timeout" yaml:"idle_timeout"`
178179
}
180+
181+
// SharedCluster 共享集群配置
182+
type SharedCluster struct {
183+
SkipResources []string `json:"skip_resources" yaml:"skip_resources"`
184+
}

0 commit comments

Comments
 (0)