From 9c64a0e38f4afbbda60daf789c03adc5842e5b66 Mon Sep 17 00:00:00 2001 From: mcll Date: Thu, 12 Sep 2024 15:39:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dcluster=20manager?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E6=B1=A0=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/actions/nodegroup/get.go | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/bcs-services/bcs-cluster-manager/internal/actions/nodegroup/get.go b/bcs-services/bcs-cluster-manager/internal/actions/nodegroup/get.go index 88eeb47280..bfc9fd03fb 100644 --- a/bcs-services/bcs-cluster-manager/internal/actions/nodegroup/get.go +++ b/bcs-services/bcs-cluster-manager/internal/actions/nodegroup/get.go @@ -75,13 +75,33 @@ func (ga *GetAction) Handle( } func removeSensitiveInfo(group *cmproto.NodeGroup) *cmproto.NodeGroup { + shield := func(key string) string { + keyBytes := []byte(key) + if len(keyBytes) <= 4 { + return string(keyBytes) + } + size := len(keyBytes) + + resultKeys := make([]byte, 0) + for i := range keyBytes { + if i < 2 || i >= (size-2) { + resultKeys = append(resultKeys, keyBytes[i]) + continue + } + + resultKeys = append(resultKeys, '*') + } + + return string(resultKeys) + } + if group != nil && group.LaunchTemplate != nil { if group.LaunchTemplate.InitLoginPassword != "" { - group.LaunchTemplate.InitLoginPassword = utils.RandomString(8) + group.LaunchTemplate.InitLoginPassword = shield(group.LaunchTemplate.InitLoginPassword) } if group.LaunchTemplate.KeyPair != nil { if group.LaunchTemplate.KeyPair.KeyPublic != "" { - group.LaunchTemplate.KeyPair.KeyPublic = utils.RandomString(8) + group.LaunchTemplate.KeyPair.KeyPublic = shield(group.LaunchTemplate.KeyPair.KeyPublic) } group.LaunchTemplate.KeyPair.KeySecret = "" }