mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #18275 from ioito/hotfix/qx-webconsole-sshkeypair
fix(region): use project sshkeypair to ssh vm
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user