diff --git a/internal/web/actions/default/clusters/grants/grant.go b/internal/web/actions/default/clusters/grants/grant.go index f917902e..55725b82 100644 --- a/internal/web/actions/default/clusters/grants/grant.go +++ b/internal/web/actions/default/clusters/grants/grant.go @@ -31,7 +31,14 @@ func (this *GrantAction) RunGet(params struct { // TODO 处理节点专用的认证 - grant := grantResp.NodeGrant + var grant = grantResp.NodeGrant + + var privateKey = grant.PrivateKey + const maskLength = 64 + if len(privateKey) > maskLength+32 { + privateKey = privateKey[:maskLength] + strings.Repeat("*", len(privateKey)-maskLength) + } + this.Data["grant"] = maps.Map{ "id": grant.Id, "name": grant.Name, @@ -39,7 +46,7 @@ func (this *GrantAction) RunGet(params struct { "methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()), "username": grant.Username, "password": strings.Repeat("*", len(grant.Password)), - "privateKey": grant.PrivateKey, + "privateKey": privateKey, "passphrase": strings.Repeat("*", len(grant.Passphrase)), "description": grant.Description, "su": grant.Su, diff --git a/internal/web/actions/default/clusters/grants/index.go b/internal/web/actions/default/clusters/grants/index.go index c3ca6406..c750917d 100644 --- a/internal/web/actions/default/clusters/grants/index.go +++ b/internal/web/actions/default/clusters/grants/index.go @@ -27,7 +27,7 @@ func (this *IndexAction) RunGet(params struct { this.ErrorPage(err) return } - page := this.NewPage(countResp.Count) + var page = this.NewPage(countResp.Count) this.Data["page"] = page.AsHTML() grantsResp, err := this.RPC().NodeGrantRPC().ListEnabledNodeGrants(this.AdminContext(), &pb.ListEnabledNodeGrantsRequest{ @@ -39,7 +39,7 @@ func (this *IndexAction) RunGet(params struct { this.ErrorPage(err) return } - grantMaps := []maps.Map{} + var grantMaps = []maps.Map{} for _, grant := range grantsResp.NodeGrants { // 集群数 countClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithNodeGrantId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithNodeGrantIdRequest{NodeGrantId: grant.Id}) @@ -47,7 +47,7 @@ func (this *IndexAction) RunGet(params struct { this.ErrorPage(err) return } - countClusters := countClustersResp.Count + var countClusters = countClustersResp.Count // 节点数 countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesWithNodeGrantId(this.AdminContext(), &pb.CountAllEnabledNodesWithNodeGrantIdRequest{NodeGrantId: grant.Id}) @@ -55,7 +55,7 @@ func (this *IndexAction) RunGet(params struct { this.ErrorPage(err) return } - countNodes := countNodesResp.Count + var countNodes = countNodesResp.Count grantMaps = append(grantMaps, maps.Map{ "id": grant.Id, diff --git a/internal/web/actions/default/clusters/grants/update.go b/internal/web/actions/default/clusters/grants/update.go index 1f609070..8ca0c997 100644 --- a/internal/web/actions/default/clusters/grants/update.go +++ b/internal/web/actions/default/clusters/grants/update.go @@ -1,12 +1,14 @@ package grants -import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" "golang.org/x/crypto/ssh" + "strings" ) type UpdateAction struct { @@ -34,15 +36,23 @@ func (this *UpdateAction) RunGet(params struct { // TODO 处理节点专用的认证 - grant := grantResp.NodeGrant + var grant = grantResp.NodeGrant + + // private key + var privateKey = grant.PrivateKey + const maskLength = 64 + if len(privateKey) > maskLength+32 { + privateKey = privateKey[:maskLength] + strings.Repeat("*", len(privateKey)-maskLength) + } + this.Data["grant"] = maps.Map{ "id": grant.Id, "name": grant.Name, "method": grant.Method, "methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()), "username": grant.Username, - "password": grant.Password, - "privateKey": grant.PrivateKey, + "password": strings.Repeat("*", len(grant.Password)), + "privateKey": privateKey, "passphrase": grant.Passphrase, "description": grant.Description, "su": grant.Su, @@ -85,15 +95,17 @@ func (this *UpdateAction) RunPost(params struct { } // 验证私钥 - var err error - if len(params.Passphrase) > 0 { - _, err = ssh.ParsePrivateKeyWithPassphrase([]byte(params.PrivateKey), []byte(params.Passphrase)) - } else { - _, err = ssh.ParsePrivateKey([]byte(params.PrivateKey)) - } - if err != nil { - this.Fail("私钥验证失败,请检查格式:" + err.Error()) - return + if !strings.HasSuffix(params.PrivateKey, "******") /* 非掩码 */ { + var err error + if len(params.Passphrase) > 0 { + _, err = ssh.ParsePrivateKeyWithPassphrase([]byte(params.PrivateKey), []byte(params.Passphrase)) + } else { + _, err = ssh.ParsePrivateKey([]byte(params.PrivateKey)) + } + if err != nil { + this.Fail("私钥验证失败,请检查格式:" + err.Error()) + return + } } default: this.Fail("请选择正确的认证方式") diff --git a/web/views/@default/clusters/grants/create.html b/web/views/@default/clusters/grants/create.html index fd48f397..4b02a415 100644 --- a/web/views/@default/clusters/grants/create.html +++ b/web/views/@default/clusters/grants/create.html @@ -33,7 +33,7 @@
SSH登录用户密码。
SSH登录用户密码。
用来生成登录SSH公钥的私钥。
+用来生成登录SSH公钥的私钥。
SSH登录用户密码。
SSH登录用户密码。
用来生成登录SSH公钥的私钥
+用来生成登录SSH公钥的私钥。