Skip to content

Commit dae64a7

Browse files
author
Masahiro Fujiwara
authored
Merge pull request #172 from axsh/executor-hostkey
Changing the timing of key generation from run time to installation time
2 parents 26b2eb2 + a6ee8de commit dae64a7

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

.idea/libraries/GOPATH__openvdc_.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ Environment Variables:
186186
// Build main binaries
187187
cmd("go", "build", "-i", "./vendor/...")
188188
cmd("go", "build", "-ldflags", LDFLAGS, "-v", "./cmd/openvdc")
189-
cmd("go", "build", "-ldflags", LDFLAGS+"-X 'main.DefaultConfPath=/etc/openvdc/executor.toml'", "-v", "./cmd/openvdc-executor")
189+
cmd("go", "build", "-ldflags", LDFLAGS+
190+
" -X 'main.HostRsaKeyPath=/etc/openvdc/ssh/host_rsa_key'" +
191+
" -X 'main.HostEcdsaKeyPath=/etc/openvdc/ssh/host_ecdsa_key'" +
192+
" -X 'main.HostEd25519KeyPath=/etc/openvdc/ssh/host_ed25519_key'" +
193+
" -X 'main.DefaultConfPath=/etc/openvdc/executor.toml'", "-v", "./cmd/openvdc-executor")
190194
cmd("go", "build", "-ldflags", LDFLAGS+"-X 'main.DefaultConfPath=/etc/openvdc/scheduler.toml'", "-v", "./cmd/openvdc-scheduler")
191195

192196
//Build lxc-template

cmd/openvdc-executor/sshd.go

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@ package main
22

33
import (
44
"crypto"
5-
"crypto/ecdsa"
6-
"crypto/elliptic"
7-
"crypto/rand"
8-
"crypto/rsa"
95
"fmt"
106
"io"
117
"net"
12-
138
log "github.com/Sirupsen/logrus"
149
"github.com/axsh/openvdc/hypervisor"
1510
"github.com/axsh/openvdc/model"
1611
"github.com/pkg/errors"
17-
"golang.org/x/crypto/ed25519"
1812
"golang.org/x/crypto/ssh"
13+
"io/ioutil"
1914
"golang.org/x/net/context"
2015
)
2116

@@ -40,31 +35,29 @@ func NewSSHServer(provider hypervisor.HypervisorProvider, ctx context.Context) *
4035

4136
type HostKeyGen func(rand io.Reader) (crypto.Signer, error)
4237

43-
var KeyGenList = []HostKeyGen{
44-
func(rand io.Reader) (crypto.Signer, error) {
45-
_, priv, err := ed25519.GenerateKey(rand)
46-
return priv, err
47-
},
48-
func(rand io.Reader) (crypto.Signer, error) {
49-
return ecdsa.GenerateKey(elliptic.P521(), rand)
50-
},
51-
func(rand io.Reader) (crypto.Signer, error) {
52-
return rsa.GenerateKey(rand, 2048)
53-
},
54-
}
38+
var HostRsaKeyPath string
39+
var HostEcdsaKeyPath string
40+
var HostEd25519KeyPath string
5541

42+
var KeyGenPathList = []string{
43+
HostRsaKeyPath,
44+
HostEcdsaKeyPath,
45+
HostEd25519KeyPath,
46+
}
5647
func (sshd *SSHServer) Setup() error {
5748
if model.GetBackendCtx(sshd.ctx) == nil {
5849
return errors.New("Context does not have model connection")
5950
}
60-
for _, gen := range KeyGenList {
61-
priv, err := gen(rand.Reader)
51+
for _, path := range KeyGenPathList {
52+
// Reading key file
53+
buf, err := ioutil.ReadFile(path)
6254
if err != nil {
63-
return errors.Wrap(err, "Failed to generate host key")
55+
return errors.Wrap(err, path + " doesn't exist")
6456
}
65-
sshSigner, err := ssh.NewSignerFromSigner(priv)
57+
// Check integrity of pem file
58+
sshSigner, err := ssh.ParsePrivateKey(buf)
6659
if err != nil {
67-
return errors.Wrap(err, "Failed to convert to ssh.Signer")
60+
return errors.Wrap(err, path + " is not a valid pem file")
6861
}
6962
sshd.config.AddHostKey(sshSigner)
7063
}

pkg/rhel/openvdc.spec

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ mkdir -p "$RPM_BUILD_ROOT"/opt/axsh/openvdc/bin
5050
mkdir -p "$RPM_BUILD_ROOT"%{_unitdir}
5151
mkdir -p "$RPM_BUILD_ROOT"/etc/openvdc
5252
mkdir -p "$RPM_BUILD_ROOT"/etc/openvdc/scripts
53+
mkdir -p "$RPM_BUILD_ROOT"/etc/openvdc/ssh
5354
mkdir -p "$RPM_BUILD_ROOT"/usr/bin
5455
ln -sf /opt/axsh/openvdc/bin/openvdc "$RPM_BUILD_ROOT"/usr/bin
5556
cp openvdc "$RPM_BUILD_ROOT"/opt/axsh/openvdc/bin
@@ -93,6 +94,12 @@ OpenVDC executor common package.
9394
/opt/axsh/openvdc/share/mesos-slave/attributes.lxc
9495
/opt/axsh/openvdc/share/lxc-templates/lxc-openvdc
9596
%dir /etc/openvdc
97+
%dir /etc/openvdc/ssh
98+
99+
%post executor
100+
test ! -f /etc/openvdc/ssh/host_rsa_key && /usr/bin/ssh-keygen -q -t rsa -f /etc/openvdc/ssh/host_rsa_key -b 4096 -C '' -N '' >&/dev/null;
101+
test ! -f /etc/openvdc/ssh/host_ecdsa_key && /usr/bin/ssh-keygen -q -t ecdsa -f /etc/openvdc/ssh/host_ecdsa_key -C '' -N '' >&/dev/null;
102+
test ! -f /etc/openvdc/ssh/host_ed25519_key && /usr/bin/ssh-keygen -q -t ed25519 -f /etc/openvdc/ssh/host_ed25519_key -C '' -N '' >&/dev/null;
96103

97104
%package executor-null
98105
Summary: OpenVDC executor (null driver)

0 commit comments

Comments
 (0)