mirror of
https://github.com/rancher/os.git
synced 2025-09-04 16:21:07 +00:00
move tlsconf to rancherctl
This commit is contained in:
@@ -47,6 +47,11 @@ func Main() {
|
|||||||
Usage: "operating system upgrade/downgrade",
|
Usage: "operating system upgrade/downgrade",
|
||||||
Subcommands: osSubcommands(),
|
Subcommands: osSubcommands(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "tlsconf",
|
||||||
|
Usage: "setup tls configuration",
|
||||||
|
Subcommands: tlsConfCommands(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
app.Run(os.Args)
|
||||||
|
@@ -1,19 +1,46 @@
|
|||||||
package tlsconf
|
package control
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
machineUtil "github.com/docker/machine/utils"
|
machineUtil "github.com/docker/machine/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Main() {
|
func tlsConfCommands() []cli.Command {
|
||||||
|
return []cli.Command {
|
||||||
|
{
|
||||||
|
Name: "create",
|
||||||
|
Usage: "use it to create a new set of tls configuration certs and keys or upload existing ones",
|
||||||
|
Action: tlsConfCreate,
|
||||||
|
Flags: []cli.Flag {
|
||||||
|
cli.StringFlag {
|
||||||
|
Name: "cakey",
|
||||||
|
Usage: "path to existing certificate authority key (only use with --generate)",
|
||||||
|
},
|
||||||
|
cli.StringFlag {
|
||||||
|
Name: "ca",
|
||||||
|
Usage: "path to existing certificate authority (only use with --genreate)",
|
||||||
|
},
|
||||||
|
cli.BoolFlag {
|
||||||
|
Name: "generate, g",
|
||||||
|
Usage: "generate the client key and client cert from existing ca and cakey",
|
||||||
|
},
|
||||||
|
cli.StringFlag {
|
||||||
|
Name: "outDir, o",
|
||||||
|
Usage: "the output directory to save the generated certs or keys",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func tlsConfCreate(c *cli.Context) {
|
||||||
name := "rancher"
|
name := "rancher"
|
||||||
bits := 2048
|
bits := 2048
|
||||||
|
|
||||||
vargs := os.Args
|
|
||||||
|
|
||||||
caCertPath := "ca.pem"
|
caCertPath := "ca.pem"
|
||||||
caKeyPath := "ca-key.pem"
|
caKeyPath := "ca-key.pem"
|
||||||
outDir := "/etc/docker/tls/"
|
outDir := "/etc/docker/tls/"
|
||||||
@@ -22,42 +49,28 @@ func Main() {
|
|||||||
inputCaKey := ""
|
inputCaKey := ""
|
||||||
inputCaCert := ""
|
inputCaCert := ""
|
||||||
|
|
||||||
for index := range vargs {
|
if val := c.String("outDir"); val != "" {
|
||||||
arg := vargs[index]
|
outDir = val
|
||||||
if arg == "--help" || arg == "-h" {
|
|
||||||
fmt.Println("run tlsconfig with no args to generate ca, cakey, server-key and server-cert in /var/run \n")
|
|
||||||
fmt.Println("--help or -h\t print this help text")
|
|
||||||
fmt.Println("--cakey\t\t path to existing certificate authority key (only use with -g)")
|
|
||||||
fmt.Println("--ca\t\t path to existing certificate authority (only use with -g)")
|
|
||||||
fmt.Println("--g \t\t generates server key and server cert from existing ca and caKey")
|
|
||||||
fmt.Println("--outdir \t the output directory to save the generate certs or keys")
|
|
||||||
return
|
|
||||||
} else if arg == "--outdir" {
|
|
||||||
if len(vargs) > index+1 {
|
|
||||||
outDir = vargs[index+1]
|
|
||||||
} else {
|
|
||||||
fmt.Println("please specify a output directory")
|
|
||||||
}
|
}
|
||||||
} else if arg == "-g" {
|
|
||||||
|
if c.Bool("generate") {
|
||||||
generateCaCerts = false
|
generateCaCerts = false
|
||||||
} else if arg == "--cakey" {
|
|
||||||
if len(vargs) > index+1 {
|
|
||||||
inputCaKey = vargs[index+1]
|
|
||||||
} else {
|
|
||||||
fmt.Println("please specify a input ca-key file path")
|
|
||||||
}
|
|
||||||
} else if arg == "--ca" {
|
|
||||||
if len(vargs) > index+1 {
|
|
||||||
inputCaCert = vargs[index+1]
|
|
||||||
} else {
|
|
||||||
fmt.Println("please specify a input ca file path")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if val := c.String("cakey"); val != "" {
|
||||||
|
inputCaKey = val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if val := c.String("ca"); val != "" {
|
||||||
|
inputCaCert = val
|
||||||
}
|
}
|
||||||
|
|
||||||
caCertPath = filepath.Join(outDir, caCertPath)
|
caCertPath = filepath.Join(outDir, caCertPath)
|
||||||
caKeyPath = filepath.Join(outDir, caKeyPath)
|
caKeyPath = filepath.Join(outDir, caKeyPath)
|
||||||
|
|
||||||
|
serverCertPath := "server-cert.pem"
|
||||||
|
serverKeyPath := "server-key.pem"
|
||||||
|
|
||||||
if generateCaCerts {
|
if generateCaCerts {
|
||||||
if err := machineUtil.GenerateCACertificate(caCertPath, caKeyPath, name, bits); err != nil {
|
if err := machineUtil.GenerateCACertificate(caCertPath, caKeyPath, name, bits); err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
@@ -83,12 +96,12 @@ func Main() {
|
|||||||
} else {
|
} else {
|
||||||
caCertPath = inputCaCert
|
caCertPath = inputCaCert
|
||||||
}
|
}
|
||||||
|
serverCertPath = "client-cert.pem"
|
||||||
|
serverKeyPath = "client-key.pem"
|
||||||
}
|
}
|
||||||
|
|
||||||
serverCertPath := "server-cert.pem"
|
|
||||||
serverCertPath = filepath.Join(outDir, serverCertPath)
|
|
||||||
|
|
||||||
serverKeyPath := "server-key.pem"
|
serverCertPath = filepath.Join(outDir, serverCertPath)
|
||||||
serverKeyPath = filepath.Join(outDir, serverKeyPath)
|
serverKeyPath = filepath.Join(outDir, serverKeyPath)
|
||||||
|
|
||||||
if err := machineUtil.GenerateCert([]string{""}, serverCertPath, serverKeyPath, caCertPath, caKeyPath, name, bits); err != nil {
|
if err := machineUtil.GenerateCert([]string{""}, serverCertPath, serverKeyPath, caCertPath, caKeyPath, name, bits); err != nil {
|
2
main.go
2
main.go
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/rancherio/os/cmd/respawn"
|
"github.com/rancherio/os/cmd/respawn"
|
||||||
"github.com/rancherio/os/cmd/sysinit"
|
"github.com/rancherio/os/cmd/sysinit"
|
||||||
"github.com/rancherio/os/cmd/systemdocker"
|
"github.com/rancherio/os/cmd/systemdocker"
|
||||||
"github.com/rancherio/os/cmd/tlsconf"
|
|
||||||
osInit "github.com/rancherio/os/init"
|
osInit "github.com/rancherio/os/init"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,7 +42,6 @@ func main() {
|
|||||||
registerCmd("/sbin/halt", power.Halt)
|
registerCmd("/sbin/halt", power.Halt)
|
||||||
registerCmd("/usr/bin/respawn", respawn.Main)
|
registerCmd("/usr/bin/respawn", respawn.Main)
|
||||||
registerCmd("/usr/sbin/rancherctl", control.Main)
|
registerCmd("/usr/sbin/rancherctl", control.Main)
|
||||||
registerCmd("/usr/bin/tlsconf", tlsconf.Main)
|
|
||||||
registerCmd("/usr/bin/cloud-init", cloudinit.Main)
|
registerCmd("/usr/bin/cloud-init", cloudinit.Main)
|
||||||
|
|
||||||
if !reexec.Init() {
|
if !reexec.Init() {
|
||||||
|
@@ -32,7 +32,7 @@ if [ "$USE_TLS" == "true" ]; then
|
|||||||
echo "$TLS_SERVER_CERT" > $TLS_PATH/server-cert.pem
|
echo "$TLS_SERVER_CERT" > $TLS_PATH/server-cert.pem
|
||||||
echo "$TLS_SERVER_KEY" > $TLS_PATH/server-key.pem
|
echo "$TLS_SERVER_KEY" > $TLS_PATH/server-key.pem
|
||||||
else
|
else
|
||||||
tlsconf
|
rancherctl tlsconf create
|
||||||
TLS_CA_CERT="$(cat $TLS_PATH/ca.pem)"
|
TLS_CA_CERT="$(cat $TLS_PATH/ca.pem)"
|
||||||
TLS_SERVER_CERT="$(cat $TLS_PATH/server-cert.pem)"
|
TLS_SERVER_CERT="$(cat $TLS_PATH/server-cert.pem)"
|
||||||
TLS_SERVER_KEY="$(cat $TLS_PATH/server-key.pem)"
|
TLS_SERVER_KEY="$(cat $TLS_PATH/server-key.pem)"
|
||||||
|
Reference in New Issue
Block a user