Skip to content

Commit 514d0e3

Browse files
author
Matthew Fisher
committed
Merge pull request #302 from bacongobbler/store-private-keys-in-secret
feat(pkg/sshd): Store private keys in kubernetes secret
2 parents 1c37d86 + f948d68 commit 514d0e3

3 files changed

Lines changed: 5 additions & 33 deletions

File tree

pkg/routes.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ func routes(reg *cookoo.Registry) {
2020
Help: "Boot the builder",
2121
Does: []cookoo.Task{
2222

23-
// SSHD: Create and configure host keys.
24-
cookoo.Cmd{
25-
Name: "installSshHostKeys",
26-
Fn: sshd.GenSSHKeys,
27-
},
23+
// SSHD: Configure host keys.
2824
cookoo.Cmd{
2925
Name: sshd.HostKeys,
3026
Fn: sshd.ParseHostKeys,

pkg/sshd/sshd.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package sshd
33
import (
44
"fmt"
55
"io/ioutil"
6-
"os/exec"
76

87
"golang.org/x/crypto/ssh"
98

@@ -31,7 +30,7 @@ const (
3130
func ParseHostKeys(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
3231
log.Debugf(c, "Parsing ssh host keys")
3332
hostKeyTypes := p.Get("keytypes", []string{"rsa", "dsa", "ecdsa"}).([]string)
34-
pathTpl := p.Get("path", "/etc/ssh/ssh_host_%s_key").(string)
33+
pathTpl := p.Get("path", "/var/run/secrets/deis/builder/ssh/ssh-host-%s-key").(string)
3534
hostKeys := make([]ssh.Signer, 0, len(hostKeyTypes))
3635
for _, t := range hostKeyTypes {
3736
path := fmt.Sprintf(pathTpl, t)
@@ -45,17 +44,6 @@ func ParseHostKeys(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Inte
4544
}
4645
}
4746
}
48-
if c.Get("enableV1", false).(bool) {
49-
path := "/etc/ssh/ssh_host_key"
50-
if key, err := ioutil.ReadFile(path); err != nil {
51-
log.Errf(c, "Failed to read ssh_host_key")
52-
} else if hk, err := ssh.ParsePrivateKey(key); err == nil {
53-
log.Infof(c, "Parsed host key %s.", path)
54-
hostKeys = append(hostKeys, hk)
55-
} else {
56-
log.Errf(c, "Failed to parse host key %s: %s", path, err)
57-
}
58-
}
5947
return hostKeys, nil
6048
}
6149

@@ -115,15 +103,3 @@ func Configure(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrup
115103

116104
return cfg, nil
117105
}
118-
119-
// GenSSHKeys generates the default set of SSH host keys.
120-
func GenSSHKeys(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
121-
log.Debugf(c, "Generating ssh keys for sshd")
122-
// Generate a new key
123-
out, err := exec.Command("ssh-keygen", "-A").CombinedOutput()
124-
if err != nil {
125-
log.Infof(c, "ssh-keygen: %s", out)
126-
return nil, err
127-
}
128-
return nil, nil
129-
}

rootfs/etc/ssh/sshd_config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Port 2223
22
Protocol 2
3-
HostKey /etc/ssh/ssh_host_rsa_key
4-
HostKey /etc/ssh/ssh_host_dsa_key
5-
HostKey /etc/ssh/ssh_host_ecdsa_key
3+
HostKey /var/run/secrets/deis/builder/ssh/ssh-host-rsa-key
4+
HostKey /var/run/secrets/deis/builder/ssh/ssh-host-dsa-key
5+
HostKey /var/run/secrets/deis/builder/ssh/ssh-host-ecdsa-key
66
UsePrivilegeSeparation yes
77
KeyRegenerationInterval 3600
88
ServerKeyBits 768

0 commit comments

Comments
 (0)