Skip to content

Commit

Permalink
Update user home directory resolution on ssh key fetching.
Browse files Browse the repository at this point in the history
  • Loading branch information
dougnd committed Jul 26, 2024
1 parent 0a580fe commit 05901b9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pbs/pbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log/slog"
"os"
"os/exec"
"os/user"
"path"
"strings"

Expand Down Expand Up @@ -155,8 +156,14 @@ func (s *nodeStatsSession) Close() error {

func connectToNode(host string, username string) (*ssh.Client, error) {

// TODO: better home folder resolution: spack and root don't use /home/username.
keyFile := fmt.Sprintf("/home/%s/.ssh/id_rsa", username)
user, err := user.Lookup(username)
if err != nil {
return nil, fmt.Errorf("failed to fetch user info for user %s: %w", username, err)
}
if user.HomeDir == "" {
return nil, fmt.Errorf("user %s is missing home directory", username)
}
keyFile := fmt.Sprintf("%s/.ssh/id_rsa", user.HomeDir)
key, err := os.ReadFile(keyFile)
if err != nil {
return nil, fmt.Errorf("failed to read private key %s: %w", keyFile, err)
Expand Down

0 comments on commit 05901b9

Please sign in to comment.