Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a swarm joining secret if none is specified #24349

Merged
merged 1 commit into from
Jul 7, 2016

Conversation

aaronlehmann
Copy link
Contributor

The current behavior of docker swarm init is to set up a swarm that
has no secret for joining, and does not require manual acceptance for
workers. Since workers may sometimes receive sensitive data such as pull
credentials, it makes sense to harden the defaults.

This change makes docker swarm init generate a random secret if none
is provided, and print it to the terminal. This secret will be needed to
join workers or managers to the swarm. In addition to improving access
control to the cluster, this setup removes an avenue for
denial-of-service attacks, since the secret is necessary to even create
an entry in the node list.

docker swarm init --secret "" will set up a swarm without a secret,
matching the old behavior. docker swarm update --secret "" removes the
automatically generated secret after docker swarm init.

Closes #23785

cc @diogomonica @aluzzardi @tonistiigi @dnephin

@aaronlehmann
Copy link
Contributor Author

Note that this PR does not change the defaults for auto-acceptance. So while a secret will be required in all cases, under default settings, a node can't join as a manager without approval, even though it presents the secret. It will still show up as a pending node, which needs to be accepted with docker node accept on a manager.

@aaronlehmann
Copy link
Contributor Author

cc @sfsmithcha

if !flags.Changed("secret") {
var secretBytes [generatedSecretEntropyBytes]byte

if _, err := io.ReadFull(cryptorand.Reader, secretBytes[:]); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

nit: same as rand.Read()

@aaronlehmann
Copy link
Contributor Author

Updated to made docker swarm init show a docker swarm join command that can be used to join the new swarm.


var nn big.Int
nn.SetBytes(secretBytes[:])
secret = fmt.Sprintf("%0[1]*s", maxGeneratedSecretLength, nn.Text(generatedSecretBase))
Copy link
Member

Choose a reason for hiding this comment

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

This block (62-70) looks like it should be in its own function func generateRandomSecret() string

@aaronlehmann
Copy link
Contributor Author

@dnephin: Updated to address the comments, PTAL.

@tonistiigi
Copy link
Member

Design LGTM

@dnephin
Copy link
Member

dnephin commented Jul 6, 2016

Thanks LGTM

@diogomonica
Copy link
Contributor

@aaronlehmann this LGTM, but are you going to do the changes we talked about yesterday in another PR?

@aaronlehmann
Copy link
Contributor Author

@diogomonica: Yes, I'm planning to do those as a followup.

I'm waiting for design review on the mockup, and also on the swarmkit PR moby/swarmkit#1128.

The current behavior of `docker swarm init` is to set up a swarm that
has no secret for joining, and does not require manual acceptance for
workers. Since workers may sometimes receive sensitive data such as pull
credentials, it makes sense to harden the defaults.

This change makes `docker swarm init` generate a random secret if none
is provided, and print it to the terminal. This secret will be needed to
join workers or managers to the swarm. In addition to improving access
control to the cluster, this setup removes an avenue for
denial-of-service attacks, since the secret is necessary to even create
an entry in the node list.

`docker swarm init --secret ""` will set up a swarm without a secret,
matching the old behavior. `docker swarm update --secret ""` removes the
automatically generated secret after `docker swarm init`.

Closes moby#23785

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
@tonistiigi tonistiigi merged commit db67db9 into moby:master Jul 7, 2016
@aaronlehmann aaronlehmann deleted the swarm-secrets-by-default branch July 7, 2016 20:23
@praving5
Copy link

praving5 commented Jul 8, 2016

Didn't quite understand. So, the old behavior still exists right? Nodes can join swarm cluster without any secret and the default --auto-accept is set to worker?

Or are you saying that passing --secret is now mandatory and if we don't explicitly set it up, docker swarm will automatically pick one and thereafter both worker and manager nodes need to know that auto-generated secret to join the cluster?

So, are we dropping none as a parameter value for --auto-accept? or are we thinking to drop --auto-accept parameter itself since it will no more be needed since we are mandating --secret?

Can we also update the respective documentation?

@thaJeztah
Copy link
Member

@praving5 see #24430 for more context

@aaronlehmann
Copy link
Contributor Author

@praving5: The new behavior is that swarm init by default will generate a secret that you need to pass to add nodes. swarm init will print a complete command line you can use to do this, including the secret. You can always opt out of this behavior by passing --secret "" on the swarm init command line (though note that the form of this flag may change soon - see #24430).

Node acceptance is a separate concept from the joining secret. The defaults there haven't changed, so it's still necessary to accept managers with docker node accept.

The documentation you mentioned was updated as part of this PR.

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.

None yet

8 participants