Skip to content

Commit

Permalink
fix: use random string for ssh agent sock file name
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed May 30, 2024
1 parent 8e74c5e commit 5bd0ef5
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions db/AccessKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"math/big"
"os"
"path"
"strconv"
"time"

"github.com/ansible-semaphore/semaphore/pkg/random"
"github.com/ansible-semaphore/semaphore/pkg/ssh"
"github.com/ansible-semaphore/semaphore/pkg/task_logger"
"github.com/ansible-semaphore/semaphore/util"
"io"
"math/big"
"path"
)

type AccessKeyType string
Expand Down Expand Up @@ -76,18 +73,7 @@ func (key AccessKeyInstallation) Destroy() error {
if key.SSHAgent != nil {
return key.SSHAgent.Close()
}

installPath := key.GetPath()
_, err := os.Stat(installPath)
if os.IsNotExist(err) {
return nil
}
return os.Remove(installPath)
}

// GetPath returns the location of the access key once written to disk
func (key AccessKeyInstallation) GetPath() string {
return util.Config.TmpPath + "/access_key_" + strconv.FormatInt(key.InstallationKey, 10)
return nil
}

func (key *AccessKey) startSSHAgent(logger task_logger.Logger) (ssh.Agent, error) {
Expand All @@ -99,7 +85,7 @@ func (key *AccessKey) startSSHAgent(logger task_logger.Logger) (ssh.Agent, error
Passphrase: []byte(key.SshKey.Passphrase),
},
},
SocketFile: path.Join(util.Config.TmpPath, fmt.Sprintf("ssh-agent-%d-%d.sock", key.ID, time.Now().Unix())),
SocketFile: path.Join(util.Config.TmpPath, fmt.Sprintf("ssh-agent-%d-%s.sock", key.ID, random.String(10))),
}

return sshAgent, sshAgent.Listen()
Expand Down

0 comments on commit 5bd0ef5

Please sign in to comment.