Skip to content

Commit

Permalink
Merge pull request #23585 from ashley-cui/sshkeygen
Browse files Browse the repository at this point in the history
pkg/machine: Read stderr from ssh-keygen correctly
  • Loading branch information
openshift-merge-bot[bot] authored Aug 13, 2024
2 parents c3111c2 + 0177f74 commit d4ecd57
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions pkg/machine/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
package machine

import (
"bytes"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -71,22 +71,18 @@ func CreateSSHKeysPrefix(identityPath string, passThru bool, skipExisting bool,
func generatekeys(writeLocation string) error {
args := append(append([]string{}, sshCommand[1:]...), writeLocation)
cmd := exec.Command(sshCommand[0], args...)
stdErr, err := cmd.StderrPipe()
if err != nil {
return err
}
stdErr := &bytes.Buffer{}
cmd.Stderr = stdErr

if err := cmd.Start(); err != nil {
return err
}
waitErr := cmd.Wait()
if waitErr == nil {
return nil
if waitErr != nil {
return fmt.Errorf("failed to generate keys: %s: %w", strings.TrimSpace(stdErr.String()), waitErr)
}
errMsg, err := io.ReadAll(stdErr)
if err != nil {
return fmt.Errorf("key generation failed, unable to read from stderr: %w", waitErr)
}
return fmt.Errorf("failed to generate keys: %s: %w", string(errMsg), waitErr)

return nil
}

// generatekeys creates an ed25519 set of keys
Expand Down

0 comments on commit d4ecd57

Please sign in to comment.