Make --tlsverify enable tls regardless of value specified
| ... | ... |
@@ -83,9 +83,14 @@ func main() {
|
| 83 | 83 |
) |
| 84 | 84 |
tlsConfig.InsecureSkipVerify = true |
| 85 | 85 |
|
| 86 |
+ // Regardless of whether the user sets it to true or false, if they |
|
| 87 |
+ // specify --tlsverify at all then we need to turn on tls |
|
| 88 |
+ if flag.IsSet("-tlsverify") {
|
|
| 89 |
+ *flTls = true |
|
| 90 |
+ } |
|
| 91 |
+ |
|
| 86 | 92 |
// If we should verify the server, we need to load a trusted ca |
| 87 | 93 |
if *flTlsVerify {
|
| 88 |
- *flTls = true |
|
| 89 | 94 |
certPool := x509.NewCertPool() |
| 90 | 95 |
file, err := ioutil.ReadFile(*flCa) |
| 91 | 96 |
if err != nil {
|
| ... | ... |
@@ -35,7 +35,7 @@ var ( |
| 35 | 35 |
flSocketGroup = flag.String([]string{"G", "-group"}, "docker", "Group to assign the unix socket specified by -H when running in daemon mode\nuse '' (the empty string) to disable setting of a group")
|
| 36 | 36 |
flLogLevel = flag.String([]string{"l", "-log-level"}, "info", "Set the logging level")
|
| 37 | 37 |
flEnableCors = flag.Bool([]string{"#api-enable-cors", "-api-enable-cors"}, false, "Enable CORS headers in the remote API")
|
| 38 |
- flTls = flag.Bool([]string{"-tls"}, false, "Use TLS; implied by --tlsverify=true")
|
|
| 38 |
+ flTls = flag.Bool([]string{"-tls"}, false, "Use TLS; implied by --tlsverify flag")
|
|
| 39 | 39 |
flTlsVerify = flag.Bool([]string{"-tlsverify"}, dockerTlsVerify, "Use TLS and verify the remote (daemon: verify client, client: verify daemon)")
|
| 40 | 40 |
|
| 41 | 41 |
// these are initialized in init() below since their default values depend on dockerCertPath which isn't fully initialized until init() runs |
| ... | ... |
@@ -84,7 +84,7 @@ expect an integer, and they can only be specified once. |
| 84 | 84 |
-s, --storage-driver="" Force the Docker runtime to use a specific storage driver |
| 85 | 85 |
--selinux-enabled=false Enable selinux support. SELinux does not presently support the BTRFS storage driver |
| 86 | 86 |
--storage-opt=[] Set storage driver options |
| 87 |
- --tls=false Use TLS; implied by --tlsverify=true |
|
| 87 |
+ --tls=false Use TLS; implied by --tlsverify flag |
|
| 88 | 88 |
--tlscacert="/home/sven/.docker/ca.pem" Trust only remotes providing a certificate signed by the CA given here |
| 89 | 89 |
--tlscert="/home/sven/.docker/cert.pem" Path to TLS certificate file |
| 90 | 90 |
--tlskey="/home/sven/.docker/key.pem" Path to TLS key file |
| ... | ... |
@@ -2687,3 +2687,28 @@ func TestContainerNetworkMode(t *testing.T) {
|
| 2687 | 2687 |
|
| 2688 | 2688 |
logDone("run - container shared network namespace")
|
| 2689 | 2689 |
} |
| 2690 |
+ |
|
| 2691 |
+func TestRunTLSverify(t *testing.T) {
|
|
| 2692 |
+ cmd := exec.Command(dockerBinary, "ps") |
|
| 2693 |
+ out, ec, err := runCommandWithOutput(cmd) |
|
| 2694 |
+ if err != nil || ec != 0 {
|
|
| 2695 |
+ t.Fatalf("Should have worked: %v:\n%v", err, out)
|
|
| 2696 |
+ } |
|
| 2697 |
+ |
|
| 2698 |
+ // Regardless of whether we specify true or false we need to |
|
| 2699 |
+ // test to make sure tls is turned on if --tlsverify is specified at all |
|
| 2700 |
+ |
|
| 2701 |
+ cmd = exec.Command(dockerBinary, "--tlsverify=false", "ps") |
|
| 2702 |
+ out, ec, err = runCommandWithOutput(cmd) |
|
| 2703 |
+ if err == nil || ec == 0 || !strings.Contains(out, "trying to connect") {
|
|
| 2704 |
+ t.Fatalf("Should have failed: \nec:%v\nout:%v\nerr:%v", ec, out, err)
|
|
| 2705 |
+ } |
|
| 2706 |
+ |
|
| 2707 |
+ cmd = exec.Command(dockerBinary, "--tlsverify=true", "ps") |
|
| 2708 |
+ out, ec, err = runCommandWithOutput(cmd) |
|
| 2709 |
+ if err == nil || ec == 0 || !strings.Contains(out, "cert") {
|
|
| 2710 |
+ t.Fatalf("Should have failed: \nec:%v\nout:%v\nerr:%v", ec, out, err)
|
|
| 2711 |
+ } |
|
| 2712 |
+ |
|
| 2713 |
+ logDone("run - verify tls is set for --tlsverify")
|
|
| 2714 |
+} |
| ... | ... |
@@ -394,12 +394,22 @@ func (f *FlagSet) Lookup(name string) *Flag {
|
| 394 | 394 |
return f.formal[name] |
| 395 | 395 |
} |
| 396 | 396 |
|
| 397 |
+// Indicates whether the specified flag was specified at all on the cmd line |
|
| 398 |
+func (f *FlagSet) IsSet(name string) bool {
|
|
| 399 |
+ return f.actual[name] != nil |
|
| 400 |
+} |
|
| 401 |
+ |
|
| 397 | 402 |
// Lookup returns the Flag structure of the named command-line flag, |
| 398 | 403 |
// returning nil if none exists. |
| 399 | 404 |
func Lookup(name string) *Flag {
|
| 400 | 405 |
return CommandLine.formal[name] |
| 401 | 406 |
} |
| 402 | 407 |
|
| 408 |
+// Indicates whether the specified flag was specified at all on the cmd line |
|
| 409 |
+func IsSet(name string) bool {
|
|
| 410 |
+ return CommandLine.IsSet(name) |
|
| 411 |
+} |
|
| 412 |
+ |
|
| 403 | 413 |
// Set sets the value of the named flag. |
| 404 | 414 |
func (f *FlagSet) Set(name, value string) error {
|
| 405 | 415 |
flag, ok := f.formal[name] |