From 1f83d1758d0a2705d97a151ee51e247470ba1068 Mon Sep 17 00:00:00 2001 From: Lingfeng Zhang Date: Tue, 23 Jan 2024 02:58:44 +0800 Subject: [PATCH] Support inlined sshd host key (#1054) --- ssh.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ssh.go b/ssh.go index 8e48fc48f..e99205ca2 100644 --- a/ssh.go +++ b/ssh.go @@ -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)