From 482d9bdee0292c122fb28993be5fe1911a189ea7 Mon Sep 17 00:00:00 2001 From: Ying Li Date: Mon, 19 Jun 2017 13:34:18 -0700 Subject: [PATCH 1/2] If `docker swarm ca` is not called with the `--rotate` flag, the other flags, including cert expiry, will be ignored, so warn if a user attempts to use `docker swarm ca --cert-expiry` or something. Signed-off-by: Ying Li (cherry picked from commit 32b43bc21a053cbe566feefd3c54def739d40bfe) Signed-off-by: Andrew Hsu --- components/cli/cli/command/swarm/ca.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/cli/cli/command/swarm/ca.go b/components/cli/cli/command/swarm/ca.go index fab0929b64..2f01ab4da4 100644 --- a/components/cli/cli/command/swarm/ca.go +++ b/components/cli/cli/command/swarm/ca.go @@ -61,6 +61,11 @@ func runRotateCA(dockerCli command.Cli, flags *pflag.FlagSet, opts caOptions) er } if !opts.rotate { + for _, f := range []string{flagCACert, flagCAKey, flagCACert, flagExternalCA} { + if flags.Changed(f) { + return fmt.Errorf("`--%s` flag requires the `--rotate` flag to update the CA", f) + } + } if swarmInspect.ClusterInfo.TLSInfo.TrustRoot == "" { fmt.Fprintln(dockerCli.Out(), "No CA information available") } else { @@ -71,7 +76,7 @@ func runRotateCA(dockerCli command.Cli, flags *pflag.FlagSet, opts caOptions) er genRootCA := true spec := &swarmInspect.Spec - opts.mergeSwarmSpec(spec, flags) + opts.mergeSwarmSpec(spec, flags) // updates the spec given the cert expiry or external CA flag if flags.Changed(flagCACert) { spec.CAConfig.SigningCACert = opts.rootCACert.Contents() genRootCA = false From 3d947e7a2da72217f63dd28b48c8b1443684be52 Mon Sep 17 00:00:00 2001 From: Ying Li Date: Wed, 12 Jul 2017 11:44:47 -0700 Subject: [PATCH 2/2] Fix warning in docker CLI when `swarm ca --ca-cert`, etc. flags are passed, and add a test. Signed-off-by: Ying Li (cherry picked from commit 4615c92f661b724ece58937ccfecbb24f602fc32) Conflicts: components/cli/cli/command/swarm/ca_test.go Signed-off-by: Andrew Hsu --- components/cli/cli/command/swarm/ca.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/cli/cli/command/swarm/ca.go b/components/cli/cli/command/swarm/ca.go index 2f01ab4da4..5fd6a97466 100644 --- a/components/cli/cli/command/swarm/ca.go +++ b/components/cli/cli/command/swarm/ca.go @@ -61,7 +61,7 @@ func runRotateCA(dockerCli command.Cli, flags *pflag.FlagSet, opts caOptions) er } if !opts.rotate { - for _, f := range []string{flagCACert, flagCAKey, flagCACert, flagExternalCA} { + for _, f := range []string{flagCACert, flagCAKey, flagCertExpiry, flagExternalCA} { if flags.Changed(f) { return fmt.Errorf("`--%s` flag requires the `--rotate` flag to update the CA", f) }