Skip to content

Commit

Permalink
Support inlined sshd host key
Browse files Browse the repository at this point in the history
  • Loading branch information
ccat3z committed Dec 26, 2023
1 parent 3a22181 commit 9ce1c0c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,19 @@ func configSSH(l *logrus.Logger, ssh *sshd.SSHServer, c *config.C) (func(), erro
}

//TODO: no good way to reload this right now
hostKeyFile := c.GetString("sshd.host_key", "")
if hostKeyFile == "" {
hostKeyPathOrKey := c.GetString("sshd.host_key", "")
if hostKeyPathOrKey == "" {
return nil, fmt.Errorf("sshd.host_key must be provided")
}

hostKeyBytes, err := os.ReadFile(hostKeyFile)
if err != nil {
return nil, fmt.Errorf("error while loading sshd.host_key file: %s", err)
var hostKeyBytes []byte
if strings.Contains(hostKeyPathOrKey, "-----BEGIN") {
hostKeyBytes = []byte(hostKeyPathOrKey)
} else {
hostKeyBytes, err = os.ReadFile(hostKeyPathOrKey)
if err != nil {
return nil, fmt.Errorf("error while loading sshd.host_key file: %s", err)
}
}

err = ssh.SetHostKey(hostKeyBytes)
Expand Down

0 comments on commit 9ce1c0c

Please sign in to comment.