From 4c2a4d0fb2d754dfe640893047ed71eac14a60f6 Mon Sep 17 00:00:00 2001 From: ioito Date: Thu, 12 Oct 2023 14:23:17 +0800 Subject: [PATCH] fix(region): use project sshkeypair to ssh vm --- pkg/compute/sshkeys/handler.go | 2 +- pkg/webconsole/helper/helper.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/compute/sshkeys/handler.go b/pkg/compute/sshkeys/handler.go index 89a54673eb..18de7f01c0 100644 --- a/pkg/compute/sshkeys/handler.go +++ b/pkg/compute/sshkeys/handler.go @@ -83,7 +83,7 @@ func sshKeysHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) func sendSshKey(ctx context.Context, w http.ResponseWriter, userCred mcclient.TokenCredential, projectId string, isAdmin bool, publicOnly bool) { var privKey, pubKey string - if isAdmin && userCred.IsAllow(rbacscope.ScopeSystem, consts.GetServiceType(), "sshkeypairs", policy.PolicyActionGet).Result.IsAllow() { + if isAdmin && len(projectId) == 0 && userCred.IsAllow(rbacscope.ScopeSystem, consts.GetServiceType(), "sshkeypairs", policy.PolicyActionGet).Result.IsAllow() { privKey, pubKey, _ = GetSshAdminKeypair(ctx) } else { privKey, pubKey, _ = GetSshProjectKeypair(ctx, projectId) diff --git a/pkg/webconsole/helper/helper.go b/pkg/webconsole/helper/helper.go index 01a6c5e499..c5bfd2dd17 100644 --- a/pkg/webconsole/helper/helper.go +++ b/pkg/webconsole/helper/helper.go @@ -39,7 +39,7 @@ func GetValidPrivateKey(host string, port int64, username string, projectId stri if projectId == "" { return nil, errors.Error("project_id is empty") } - key, err := compute.Sshkeypairs.GetById(admin, projectId, jsonutils.Marshal(map[string]bool{"admin": true})) + key, err := compute.Sshkeypairs.GetById(admin, projectId, jsonutils.Marshal(map[string]string{})) if err != nil { return nil, errors.Wrapf(err, "Sshkeypairs.GetById(%s)", projectId) } @@ -85,7 +85,7 @@ func GetValidPrivateKey(host string, port int64, username string, projectId stri addr := fmt.Sprintf("%s:%d", host, port) client, err := ssh.Dial("tcp", addr, config) if err != nil { - errs = append(errs, errors.Wrapf(err, "dial %s", addr)) + errs = append(errs, errors.Wrapf(err, "dial %s by %s", addr, username)) continue } defer client.Close()