Merge pull request #18275 from ioito/hotfix/qx-webconsole-sshkeypair

fix(region): use project sshkeypair to ssh vm
This commit is contained in:
Zexi Li
2023-10-12 14:59:35 +08:00
committed by GitHub
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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()