tls for openstack/rackspace

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett 2015-01-15 10:36:29 -05:00
parent d1ece77684
commit 3212d0c509
5 changed files with 74 additions and 32 deletions

View File

@ -176,7 +176,7 @@ func (driver *Driver) Create() error {
return err return err
} }
log.Infof("Creating Azure machine...") log.Info("Creating Azure machine...")
vmConfig, err := vmClient.CreateAzureVMConfiguration(driver.MachineName, driver.Size, driver.Image, driver.Location) vmConfig, err := vmClient.CreateAzureVMConfiguration(driver.MachineName, driver.Size, driver.Image, driver.Location)
if err != nil { if err != nil {
return err return err
@ -203,7 +203,7 @@ func (driver *Driver) Create() error {
return err return err
} }
log.Infof("Waiting for SSH...") log.Info("Waiting for SSH...")
log.Debugf("Host: %s SSH Port: %d", driver.getHostname(), driver.SSHPort) log.Debugf("Host: %s SSH Port: %d", driver.getHostname(), driver.SSHPort)
if err := ssh.WaitForTCP(fmt.Sprintf("%s:%d", driver.getHostname(), driver.SSHPort)); err != nil { if err := ssh.WaitForTCP(fmt.Sprintf("%s:%d", driver.getHostname(), driver.SSHPort)); err != nil {

View File

@ -17,6 +17,10 @@ import (
"github.com/docker/machine/state" "github.com/docker/machine/state"
) )
const (
dockerConfigDir = "/etc/docker"
)
type Driver struct { type Driver struct {
AuthUrl string AuthUrl string
Username string Username string
@ -41,6 +45,8 @@ type Driver struct {
SSHPort int SSHPort int
Ip string Ip string
EnableDockerInstall bool EnableDockerInstall bool
CaCertPath string
PrivateKeyPath string
storePath string storePath string
client Client client Client
} }
@ -176,20 +182,24 @@ func GetCreateFlags() []cli.Flag {
} }
} }
func NewDriver(machineName string, storePath string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"machineName": machineName, "machineName": machineName,
"storePath": storePath, "storePath": storePath,
"caCert": caCert,
"privateKey": privateKey,
}).Debug("Instantiating OpenStack driver...") }).Debug("Instantiating OpenStack driver...")
return NewDerivedDriver(machineName, storePath, &GenericClient{}) return NewDerivedDriver(machineName, storePath, &GenericClient{}, caCert, privateKey)
} }
func NewDerivedDriver(machineName string, storePath string, client Client) (*Driver, error) { func NewDerivedDriver(machineName string, storePath string, client Client, caCert string, privateKey string) (*Driver, error) {
return &Driver{ return &Driver{
MachineName: machineName, MachineName: machineName,
storePath: storePath, storePath: storePath,
client: client, client: client,
CaCertPath: caCert,
PrivateKeyPath: privateKey,
}, nil }, nil
} }
@ -397,6 +407,38 @@ func (d *Driver) Upgrade() error {
return fmt.Errorf("unable to upgrade as we are using the custom docker binary with identity auth") return fmt.Errorf("unable to upgrade as we are using the custom docker binary with identity auth")
} }
func (d *Driver) StartDocker() error {
log.Debug("Starting Docker...")
cmd, err := d.GetSSHCommand("sudo service docker start")
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
return nil
}
func (d *Driver) StopDocker() error {
log.Debug("Stopping Docker...")
cmd, err := d.GetSSHCommand("sudo service docker stop")
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
return nil
}
func (d *Driver) GetDockerConfigDir() string {
return dockerConfigDir
}
func (d *Driver) GetSSHCommand(args ...string) (*exec.Cmd, error) { func (d *Driver) GetSSHCommand(args ...string) (*exec.Cmd, error) {
ip, err := d.GetIP() ip, err := d.GetIP()
if err != nil { if err != nil {
@ -694,21 +736,11 @@ func (d *Driver) waitForInstanceToStart() error {
} }
func (d *Driver) installDocker() error { func (d *Driver) installDocker() error {
log.WithField("MachineId", d.MachineId).Debug("Adding key to authorized-keys.d...")
if err := drivers.AddPublicKeyToAuthorizedHosts(d, "/.docker/authorized-keys.d"); err != nil {
return err
}
log.WithField("MachineId", d.MachineId).Debug("Installing docker daemon on the machine") log.WithField("MachineId", d.MachineId).Debug("Installing docker daemon on the machine")
if err := d.sshExec([]string{ if err := d.sshExec([]string{
`apt-get install -y curl`, `apt-get install -y curl`,
`curl -sSL https://get.docker.com | /bin/sh >/var/log/docker-install.log 2>&1`, `curl -sSL https://get.docker.com | /bin/sh >/var/log/docker-install.log 2>&1`,
`service docker stop`,
`curl -sSL https://ehazlett.s3.amazonaws.com/public/docker/linux/docker-1.4.1-136b351e-identity -o /usr/bin/docker`,
`echo "export DOCKER_OPTS=\"--auth=identity --host=tcp://0.0.0.0:2376\"" >> /etc/default/docker`,
`service docker start`,
}); err != nil { }); err != nil {
log.Error("The docker installation failed.") log.Error("The docker installation failed.")
log.Error( log.Error(

View File

@ -9,6 +9,10 @@ import (
"github.com/docker/machine/drivers/openstack" "github.com/docker/machine/drivers/openstack"
) )
const (
dockerConfigDir = "/etc/docker"
)
// Driver is a machine driver for Rackspace. It's a specialization of the generic OpenStack one. // Driver is a machine driver for Rackspace. It's a specialization of the generic OpenStack one.
type Driver struct { type Driver struct {
*openstack.Driver *openstack.Driver
@ -18,15 +22,17 @@ type Driver struct {
// CreateFlags stores the command-line arguments given to "machine create". // CreateFlags stores the command-line arguments given to "machine create".
type CreateFlags struct { type CreateFlags struct {
Username *string Username *string
APIKey *string APIKey *string
Region *string Region *string
MachineName *string MachineName *string
EndpointType *string EndpointType *string
ImageID *string ImageID *string
FlavorID *string FlavorID *string
SSHUser *string SSHUser *string
SSHPort *int SSHPort *int
CaCertPath string
PrivateKeyPath string
} }
func init() { func init() {
@ -93,14 +99,16 @@ func GetCreateFlags() []cli.Flag {
} }
// NewDriver instantiates a Rackspace driver. // NewDriver instantiates a Rackspace driver.
func NewDriver(machineName string, storePath string) (drivers.Driver, error) { func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"machineName": machineName, "machineName": machineName,
"storePath": storePath, "storePath": storePath,
"caCert": caCert,
"privateKey": privateKey,
}).Debug("Instantiating Rackspace driver.") }).Debug("Instantiating Rackspace driver.")
client := &Client{} client := &Client{}
inner, err := openstack.NewDerivedDriver(machineName, storePath, client) inner, err := openstack.NewDerivedDriver(machineName, storePath, client, caCert, privateKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -115,6 +123,10 @@ func (d *Driver) DriverName() string {
return "rackspace" return "rackspace"
} }
func (d *Driver) GetDockerConfigDir() string {
return dockerConfigDir
}
func missingEnvOrOption(setting, envVar, opt string) error { func missingEnvOrOption(setting, envVar, opt string) error {
return fmt.Errorf( return fmt.Errorf(
"%s must be specified either using the environment variable %s or the CLI option %s", "%s must be specified either using the environment variable %s or the CLI option %s",

View File

@ -293,8 +293,6 @@ func (d *Driver) StartDocker() error {
func (d *Driver) StopDocker() error { func (d *Driver) StopDocker() error {
log.Debug("Stopping Docker...") log.Debug("Stopping Docker...")
// TODO @ehazlett - should we add this exit to make sure it doesn't
// break if the daemon isn't running or add an arg?
cmd, err := d.GetSSHCommand("if [ -e /var/run/docker.pid ]; then sudo /etc/init.d/docker stop ; fi") cmd, err := d.GetSSHCommand("if [ -e /var/run/docker.pid ]; then sudo /etc/init.d/docker stop ; fi")
if err != nil { if err != nil {
return err return err

View File

@ -15,7 +15,7 @@ import (
func newCertificate(org string) (*x509.Certificate, error) { func newCertificate(org string) (*x509.Certificate, error) {
now := time.Now() now := time.Now()
// need to set notBefore slightly in the past in to account for time // need to set notBefore slightly in the past to account for time
// skew in the VMs otherwise the certs sometimes are not yet valid // skew in the VMs otherwise the certs sometimes are not yet valid
notBefore := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute()-5, 0, 0, time.Local) notBefore := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute()-5, 0, 0, time.Local)
notAfter := notBefore.Add(time.Hour * 24 * 1080) notAfter := notBefore.Add(time.Hour * 24 * 1080)