mirror of https://github.com/docker/docs.git
use separate dir for client certs so docker client can use them
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
74f9bcebc7
commit
b0e329b53e
|
@ -208,7 +208,6 @@ func cmdCreate(c *cli.Context) {
|
|||
}
|
||||
|
||||
func cmdConfig(c *cli.Context) {
|
||||
|
||||
name := c.Args().First()
|
||||
if name == "" {
|
||||
cli.ShowCommandHelp(c, "config")
|
||||
|
@ -222,9 +221,9 @@ func cmdConfig(c *cli.Context) {
|
|||
log.Fatalf("Error loading machine config: %s", err)
|
||||
}
|
||||
|
||||
caCert := filepath.Join(utils.GetMachineDir(), "ca.pem")
|
||||
clientCert := filepath.Join(utils.GetMachineDir(), "client.pem")
|
||||
clientKey := filepath.Join(utils.GetMachineDir(), "client-key.pem")
|
||||
caCert := filepath.Join(utils.GetMachineClientCertDir(), "ca.pem")
|
||||
clientCert := filepath.Join(utils.GetMachineClientCertDir(), "cert.pem")
|
||||
clientKey := filepath.Join(utils.GetMachineClientCertDir(), "key.pem")
|
||||
machineUrl, err := host.GetURL()
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting machine url: %s", err)
|
||||
|
|
33
main.go
33
main.go
|
@ -19,8 +19,18 @@ func before(c *cli.Context) error {
|
|||
org := "docker"
|
||||
bits := 2048
|
||||
|
||||
if _, err := os.Stat(utils.GetMachineDir()); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if err := os.Mkdir(utils.GetMachineDir(), 0700); err != nil {
|
||||
log.Fatalf("Error creating machine config dir: %s", err)
|
||||
}
|
||||
} else {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat(caCertPath); os.IsNotExist(err) {
|
||||
log.Debugf("Creating CA: %s", caCertPath)
|
||||
log.Infof("Creating CA: %s", caCertPath)
|
||||
|
||||
// check if the key path exists; if so, error
|
||||
if _, err := os.Stat(caKeyPath); err == nil {
|
||||
|
@ -28,13 +38,23 @@ func before(c *cli.Context) error {
|
|||
}
|
||||
|
||||
if err := utils.GenerateCACertificate(caCertPath, caKeyPath, org, bits); err != nil {
|
||||
log.Fatalf("Error generating CA certificate: %s", err)
|
||||
log.Infof("Error generating CA certificate: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat(clientCertPath); os.IsNotExist(err) {
|
||||
log.Debugf("Creating client certificate: %s", clientCertPath)
|
||||
|
||||
if _, err := os.Stat(utils.GetMachineClientCertDir()); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if err := os.Mkdir(utils.GetMachineClientCertDir(), 0700); err != nil {
|
||||
log.Fatalf("Error creating machine client cert dir: %s", err)
|
||||
}
|
||||
} else {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check if the key path exists; if so, error
|
||||
if _, err := os.Stat(clientKeyPath); err == nil {
|
||||
log.Fatalf("The client key already exists. Please remove it or specify a different key/cert.")
|
||||
|
@ -43,6 +63,11 @@ func before(c *cli.Context) error {
|
|||
if err := utils.GenerateCert([]string{""}, clientCertPath, clientKeyPath, caCertPath, caKeyPath, org, bits); err != nil {
|
||||
log.Fatalf("Error generating client certificate: %s", err)
|
||||
}
|
||||
|
||||
// copy ca.pem to client cert dir for docker client
|
||||
if err := utils.CopyFile(caCertPath, filepath.Join(utils.GetMachineClientCertDir(), "ca.pem")); err != nil {
|
||||
log.Fatalf("Error copying ca.pem to client cert dir: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -90,13 +115,13 @@ func main() {
|
|||
EnvVar: "MACHINE_TLS_CLIENT_CERT",
|
||||
Name: "tls-client-cert",
|
||||
Usage: "Client cert to use for TLS",
|
||||
Value: filepath.Join(utils.GetMachineDir(), "client.pem"),
|
||||
Value: filepath.Join(utils.GetMachineClientCertDir(), "cert.pem"),
|
||||
},
|
||||
cli.StringFlag{
|
||||
EnvVar: "MACHINE_TLS_CLIENT_KEY",
|
||||
Name: "tls-client-key",
|
||||
Usage: "Private key used in client TLS auth",
|
||||
Value: filepath.Join(utils.GetMachineDir(), "client-key.pem"),
|
||||
Value: filepath.Join(utils.GetMachineClientCertDir(), "key.pem"),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
4
store.go
4
store.go
|
@ -5,6 +5,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/docker/machine/drivers"
|
||||
|
@ -94,7 +95,8 @@ func (s *Store) List() ([]Host, error) {
|
|||
hosts := []Host{}
|
||||
|
||||
for _, file := range dir {
|
||||
if file.IsDir() {
|
||||
// don't load hidden dirs; used for configs
|
||||
if file.IsDir() && strings.Index(file.Name(), ".") != 0 {
|
||||
host, err := s.Load(file.Name())
|
||||
if err != nil {
|
||||
log.Errorf("error loading host %q: %s", file.Name(), err)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -16,11 +15,15 @@ func GetHomeDir() string {
|
|||
}
|
||||
|
||||
func GetDockerDir() string {
|
||||
return fmt.Sprintf(filepath.Join(GetHomeDir(), ".docker"))
|
||||
return filepath.Join(GetHomeDir(), ".docker")
|
||||
}
|
||||
|
||||
func GetMachineDir() string {
|
||||
return fmt.Sprintf(filepath.Join(GetDockerDir(), "machines"))
|
||||
return filepath.Join(GetDockerDir(), "machines")
|
||||
}
|
||||
|
||||
func GetMachineClientCertDir() string {
|
||||
return filepath.Join(GetMachineDir(), ".client")
|
||||
}
|
||||
|
||||
func CopyFile(src, dst string) error {
|
||||
|
|
Loading…
Reference in New Issue