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

PR for issue #34, use salt api for minion key accept #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vkhatri
Copy link

@vkhatri vkhatri commented Feb 3, 2017

No description provided.

Copy link
Owner

@shortdudey123 shortdudey123 left a comment

Choose a reason for hiding this comment

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

Left quite a few comment. Spec testing needs be be greatly expanded to cover all of the changes

.kitchen.yml Outdated
@@ -38,11 +38,16 @@ suites:
includes:
- centos-7.2
- name: salt-api
data_bags_path: "test/integration/default/data_bags"
Copy link
Owner

Choose a reason for hiding this comment

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

integration/default => fixtures

Copy link
Author

Choose a reason for hiding this comment

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

ok

.kitchen.yml Outdated
@@ -38,11 +38,16 @@ suites:
includes:
- centos-7.2
- name: salt-api
data_bags_path: "test/integration/default/data_bags"
encrypted_data_bag_secret_key_path: "test/integration/default/encrypted_data_bag_secret"
Copy link
Owner

Choose a reason for hiding this comment

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

same here

@@ -24,3 +24,17 @@
'id' => node.name,
'grains' => {},
}

default['salt']['minion']['api'] = {
Copy link
Owner

Choose a reason for hiding this comment

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

api => master_api? (since minion doesn't have the concept of an api)

Copy link
Author

Choose a reason for hiding this comment

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

yes, it is better

begin
Chef::Log.info("Connecting to host=#{host}, port=#{port}, use_ssl=#{options['use_ssl']}, verify=#{options['verify']}")

https = Net::HTTP.new(host, port)
Copy link
Owner

Choose a reason for hiding this comment

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

any reason to do this yourself and not use the salt-api gem?

Copy link
Author

Choose a reason for hiding this comment

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

thank you for pointing out, will use salt-api gem

@@ -20,6 +20,15 @@
action :enable
end

user node['salt']['master']['api']['user']['name'] do
Copy link
Owner

Choose a reason for hiding this comment

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

This should be left up to a wrapper cookbook. People may want to use existing users and adding it here would cause resource cloning (which will break in April)

Copy link
Author

Choose a reason for hiding this comment

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

I am inclined to make the user setup optional to avoid such an issue rather than left it to a wrapper cookbook. If cookbook requires a user to function, user resource should be included in the cookbook itself with option to enable/disable.

Copy link
Owner

Choose a reason for hiding this comment

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

Putting the user resource here assumes that someone doesn't already have the needed user. A lot of people, including me, create service users separate with quite different properties listed. Also, if a user named saltapi is already created somewhere else, this will break in Chef13 unless someone explicitly sets the name even if they don't use the resource.

I could see this staying if it was actually put into an if block instead of using an only_if. Then doing the following

  node['salt']['master']['api']['user'].tap{ |x| x.delete('enable') }.each do |config, value|
    send(config.to_sym, value) unless value.nil?
  end

Copy link
Author

Choose a reason for hiding this comment

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

Agreed to put user resource in a block if default['salt']['master']['api']['user']['enable'] == true in favor of Chef13.

For scenarios where user already exists, it is still possible to change the user name by setting default['salt']['master']['api']['user']['name']. But, it would not matter if wrapped around an if block.

@@ -87,6 +98,28 @@
end
end

# salt-api default user acl
# TODO: to be replaced by LWRP `external_auth`
default_user_acl = {
Copy link
Owner

Choose a reason for hiding this comment

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

This should be part of node['salt']['master']['config'] and not broken out into a separate file

Copy link
Author

Choose a reason for hiding this comment

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

yeah, i missed this one

default_user_acl = {
'external_auth' => {
'pam' => {
'saltapi' => [
Copy link
Owner

Choose a reason for hiding this comment

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

user should not be hardcoded here

Copy link
Author

Choose a reason for hiding this comment

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

yes

},
}.to_yaml

file 'default-api-user.conf' do
Copy link
Owner

Choose a reason for hiding this comment

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

not needed

Copy link
Author

Choose a reason for hiding this comment

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

do you mean file[default-api-user.conf user? I will also add a check to remove this file if api is not enabled.

Copy link
Owner

Choose a reason for hiding this comment

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

It is not needed since this partially duplicates what is in the main yaml conf

Copy link
Author

Choose a reason for hiding this comment

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

got it.

@@ -75,3 +76,29 @@
ohai 'salt' do
action :nothing
end if defined?(ChefSpec)

api_password = node['salt']['key_accept_method'] == 'api_key_accept' ? Chef::EncryptedDataBagItem.load(node['salt']['minion']['api']['databag']['name'], node['salt']['minion']['api']['databag']['item'])[node['salt']['minion']['api']['databag']['key']] : nil
Copy link
Owner

Choose a reason for hiding this comment

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

This should be put into a helper method

Copy link
Author

Choose a reason for hiding this comment

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

ok

block do
salt_accept_key(options)
end
only_if { node['salt']['key_accept_method'] == 'api_key_accept' && Mixlib::ShellOut.new('salt-call test.ping').run_command.exitstatus != 0 }
Copy link
Owner

Choose a reason for hiding this comment

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

if the test.ping fails, then a warning should be output saying the api call to the master is being skipped

Copy link
Author

Choose a reason for hiding this comment

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

ok

@vkhatri
Copy link
Author

vkhatri commented Feb 4, 2017

@shortdudey123 Sound reasonable. I will give it one more try.

@shortdudey123
Copy link
Owner

@vkhatri hows it going on your end with the feedback? anything i can do on my end?

@vkhatri
Copy link
Author

vkhatri commented Feb 25, 2017

@shortdudey123 will submit a revised PR over the weekend.

@shortdudey123
Copy link
Owner

Sounds good

@vkhatri
Copy link
Author

vkhatri commented Mar 9, 2017

@shortdudey123 Got all the changes in place, just finishing up specs.

@shortdudey123
Copy link
Owner

Sounds good :)

@vkhatri
Copy link
Author

vkhatri commented Mar 12, 2017

Travis is failing because of an issue with yaml configuration file reported in issue #45 .

https://travis-ci.org/shortdudey123/chef-salt/jobs/210111392#L488

   +---
    +external_auth:
    +  pam:
    +    saltapi: !ruby/array:Chef::Node::ImmutableArray
    +      internal:
    +      - "@wheel"
    +      ivars:
    +        :@__path__: []
    +        :@__root__: 
    +        :@__node__: 
    +        :@__precedence__: 

It would be great if you could merge this PR.

include_recipe 'salt::_setup'

node.default['salt']['master']['config']['external_auth'] = {
'pam' => {
node['salt']['master']['api']['user']['name'] => [
Copy link
Owner

Choose a reason for hiding this comment

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

need to add .to_s at the end of the node attribute, otherwise it stores a Chef::Node::ImmutableArray instead of a String

@shortdudey123
Copy link
Owner

The new changes look fine in a quick skim over of them. I will review them in more detail this week.
I added a comment to address the travis failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants