diff options
author | Ryan Cragun <me@ryan.ec> | 2015-05-01 17:09:22 -0700 |
---|---|---|
committer | Ryan Cragun <me@ryan.ec> | 2015-05-01 17:09:22 -0700 |
commit | b5ae23df27d6dd2922d40309f6c1c23e97da4bb5 (patch) | |
tree | 4a227f0495e60177eda1f9ae9f09bbcf852f6d6b | |
parent | e2b7e4e76cd8dae088299137d991a0455d87a109 (diff) | |
download | chef-b5ae23df27d6dd2922d40309f6c1c23e97da4bb5.tar.gz |
Enforce passing a node name when bootstrapping with chef-vault or userryan/validatorless_bootstrap
credentials
When bootstrapping with chef-vault or with user credentials we create
the node and client on the Chef Server before we bootstrap the node. As
it is possible to specify a server address that is not the node name we
need to enforce that the user pass a node name with -N.
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap_spec.rb | 13 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index a4095e8402..5b29591fcc 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -316,6 +316,12 @@ class Chef # new client-side hawtness, just delete your validation key. if chef_vault_handler.doing_chef_vault? || (Chef::Config[:validation_key] && !File.exist?(File.expand_path(Chef::Config[:validation_key]))) + + unless config[:chef_node_name] + ui.error("You must pass a node name with -N when bootstrapping with user credentials") + exit 1 + end + client_builder.run chef_vault_handler.run(node_name: config[:chef_node_name]) diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index f1ca510ed3..aaace60f6a 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -531,6 +531,7 @@ describe Chef::Knife::Bootstrap do describe "when running the bootstrap" do let(:knife_ssh) do knife.name_args = ["foo.example.com"] + knife.config[:chef_node_name] = "foo.example.com" knife.config[:ssh_user] = "rooty" knife.config[:identity_file] = "~/.ssh/me.rsa" allow(knife).to receive(:render_template).and_return("") @@ -590,6 +591,12 @@ describe Chef::Knife::Bootstrap do expect(knife.chef_vault_handler).not_to receive(:run).with(node_name: knife.config[:chef_node_name]) knife.run end + + it "raises an exception if the config[:chef_node_name] is not present" do + knife.config[:chef_node_name] = nil + + expect { knife.run }.to raise_error(SystemExit) + end end context "when the validation key is not present" do @@ -604,6 +611,12 @@ describe Chef::Knife::Bootstrap do expect(knife.chef_vault_handler).to receive(:run).with(node_name: knife.config[:chef_node_name]) knife.run end + + it "raises an exception if the config[:chef_node_name] is not present" do + knife.config[:chef_node_name] = nil + + expect { knife.run }.to raise_error(SystemExit) + end end context "when the validation_key is nil" do |