Skip to content

API changes to rotate swarm root CA#32993

Merged
aaronlehmann merged 3 commits intomoby:masterfrom
cyli:root-rotation-cli
May 12, 2017
Merged

API changes to rotate swarm root CA#32993
aaronlehmann merged 3 commits intomoby:masterfrom
cyli:root-rotation-cli

Conversation

@cyli
Copy link
Contributor

@cyli cyli commented May 3, 2017

This is stacked on top of #32875. Merged.

This is the first stab the CLI command to actually rotate the root CA cert. I added a new one, because we want to optionally take a root certificate and key, and/or external CAs, but we also want the user to be able to tell swarm to generate one. So:

root@ubuntu:~#  docker swarm ca
-----BEGIN CERTIFICATE-----
MIIBazCCARCgAwIBAgIUJPzo67QC7g8Ebg2ansjkZ8CbmaswCgYIKoZIzj0EAwIw
EzERMA8GA1UEAxMIc3dhcm0tY2EwHhcNMTcwNTAzMTcxMDAwWhcNMzcwNDI4MTcx
MDAwWjATMREwDwYDVQQDEwhzd2FybS1jYTBZMBMGByqGSM49AgEGCCqGSM49AwEH
A0IABKL6/C0sihYEb935wVPRA8MqzPLn3jzou0OJRXHsCLcVExigrMdgmLCC+Va4
+sJ+SLVO1eQbvLHH8uuDdF/QOU6jQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB
Af8EBTADAQH/MB0GA1UdDgQWBBSfUy5bjUnBAx/B0GkOBKp91XvxzjAKBggqhkjO
PQQDAgNJADBGAiEAnbvh0puOS5R/qvy1PMHY1iksYKh2acsGLtL/jAIvO4ACIQCi
lIwQqLkJ48SQqCjG1DBTSBsHmMSRT+6mE2My+Z3GKA==
-----END CERTIFICATE-----

root@ubuntu:~# docker swarm ca --help

Usage:	docker swarm ca [OPTIONS]

Manage root CA

Options:
      --ca-cert pem-file          Path to the PEM-formatted root CA certificate to use for the new cluster
      --ca-key pem-file           Path to the PEM-formatted root CA key to use for the new cluster
      --cert-expiry duration      Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s)
  -d, --detach                    Exit immediately instead of waiting for the root rotation to converge
      --external-ca external-ca   Specifications of one or more certificate signing endpoints
      --help                      Print usage
  -q, --quiet                     Suppress progress output
      --rotate                    Rotate the swarm CA - if no certificate or key are provided, new ones will be generated

Sample progress bar here, copied styling from the synchronous service create progress bar: https://asciinema.org/a/dcpy5y2fcueb8fpmokxvf3vec

If the design looks good, I'll add a bunch more tests and update the docs. cc @aaronlehmann @aluzzardi @diogomonica

Note: I originally thought about just doing docker swarm update --rotate-ca cert=/path/...,key=/path/... but I wasn't sure how to also do tell the CLI to just generate a cert and key - it'd probably have to look like docker swarm update --rotate-ca "" which seems weird, hence the new command.

Also a suggestion from @NathanMcCauley: if we have service identities, and those could be rotated, do we want to use the same command to view/rotate those as well?

cute

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

propagate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D thanks

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure there's a good reason, but why are there a different number of spaces before these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to right-align the text, since they appear next to the progress bars. Happy to left-align instead, though.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the output looks like this:

desired root digest: sha256:a594409c21f2339d4fa5a207549e500574d6a9872dcd040f4e63e461aa969302                                                                                      
  nodes rotated TLS certificates: 1/1 done [==================================================>]                                                                                  
   nodes rotated CA certificates: 1/1 done [==================================================>] 

I have a slight preference for:

desired root digest: sha256:a594409c21f2339d4fa5a207549e500574d6a9872dcd040f4e63e461aa969302                                                                                      
  nodes rotated TLS certificates: 1/1 done [==================================================>]                                                                                  
  nodes rotated CA certificates:  1/1 done [==================================================>] 

But this is not important

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am indifferent, so happy to change it :)

Copy link
Contributor Author

@cyli cyli May 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, along with the asciinema recording

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note streamformatter was refactored and this line will need to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I wouldn't have noticed that! :) Updated.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to wait like this after the root rotation? For a service create or service update, a very common failure mode is that tasks briefly reach the Running state, but immediately fail due to a misconfiguration, or even something like specifying an entrypoint that doesn't exist in the image. Is there any equivalent with root rotation, or would this only cover a new root rotation starting right after the old one finishes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronlehmann It was only to cover another root rotation - agree it's probably not necessary though.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest removing this phase. It would simplify the code and be a little more user-friendly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@cyli cyli mentioned this pull request May 3, 2017
10 tasks

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like something done by the editor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:( yeah it's picky. Sorry about that!

@aaronlehmann
Copy link

CI faliing:

22:42:42 --- FAIL: TestProgress (0.00s)
22:42:42 panic: runtime error: makeslice: len out of range [recovered]
22:42:42 	panic: runtime error: makeslice: len out of range

@aaronlehmann aaronlehmann added the status/failing-ci Indicates that the PR in its current state fails the test suite label May 4, 2017
@aaronlehmann aaronlehmann removed the status/failing-ci Indicates that the PR in its current state fails the test suite label May 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lazy initialization doesn't seem necessary. Normally I'd say to just define an updater outside the for loop. However, I'm not sure the abstraction is justified here. In service create/update, there are two implementations. Here, there is only one implementation, so it seems like it could just be a function call updateProgress or something.done should become a return value. As for initialized, you could just move those initial progress.Update calls to happen before the for loop in this function.

@aaronlehmann
Copy link

Design LGTM

@thaJeztah thaJeztah added this to the 17.06.0 milestone May 5, 2017
@diogomonica
Copy link
Contributor

LGTM, still playing with it.

@cyli
Copy link
Contributor Author

cyli commented May 8, 2017

I've split out the CLI code to docker/cli#48.

@cyli cyli changed the title WIP: Synchronous root rotation CLI command WIP: API to rotate swarm root CA May 9, 2017
@mlaventure
Copy link
Contributor

@cyli

00:15:37 These files are not properly gofmt'd:
00:15:37  - integration-cli/docker_api_swarm_test.go
00:15:37 
00:15:37 Please reformat the above files using "gofmt -s -w" and commit the result.

@cyli
Copy link
Contributor Author

cyli commented May 10, 2017

@mlaventure Thank you - fixed.

@cyli
Copy link
Contributor Author

cyli commented May 10, 2017

Also updated the api version history here. cc @thaJeztah if you wouldn't mind checking the docs here as well :)

@mlaventure
Copy link
Contributor

@cyli it looks like the cli revision is invalid now

@aaronlehmann
Copy link

That was my branch, which I had to rebase to get merged and allow moby to switch back to the official repo. I've restored that revision. A simple rebuild should work.

@cyli
Copy link
Contributor Author

cyli commented May 10, 2017

Thanks @aaronlehmann!

@cyli cyli mentioned this pull request May 10, 2017
@cyli cyli changed the title WIP: API to rotate swarm root CA API changes to rotate swarm root CA May 10, 2017
in the Docker REST APIs when viewing or updating the swarm spec info, and
also propagate the desired CA key in the Docker REST APIs when updating
swarm spec info only (it is not available for viewing).

Signed-off-by: Ying Li <ying.li@docker.com>
@cyli
Copy link
Contributor Author

cyli commented May 11, 2017

Rebased again. PTAL.

cyli added 2 commits May 11, 2017 11:13
Signed-off-by: Ying Li <ying.li@docker.com>
Signed-off-by: Ying Li <ying.li@docker.com>
@aaronlehmann
Copy link

LGTM

@cyli
Copy link
Contributor Author

cyli commented May 12, 2017

Also pinging @cpuguy83 for review: since you reviewed the last API changes that included TLS info (sorry, no good deed goes unpunished :)) - this is the follow up that will trigger the root rotation that can make use of the TLS info.

Alternately @vdemeester or @tiborvass or may or may not be familiar with the feature.

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aaronlehmann aaronlehmann merged commit eb8abc9 into moby:master May 12, 2017
@cyli
Copy link
Contributor Author

cyli commented May 12, 2017

Thanks @cpuguy83 and @aaronlehmann! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants