Skip to content

Use root credentials explicitly #92

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

Closed
wants to merge 11 commits into from

Conversation

inkblot
Copy link
Contributor

@inkblot inkblot commented Aug 7, 2012

The mysql root password is stored in .my.cnf in root's home directory. However, the mysql and mysqladmin commands use the value of the HOME environment variable rather than libc user ent data to determine the location of .my.cnf. This causes the puppet module's mysql and mysqladmin invocations to fail when HOME and the current user's home directory are not the same, e.g. if the puppet process was started using sudo.

I had created a pull request earlier and then got talked out of it. My initial discovery was that 'sudo puppet agent -t' failed but the running puppet daemon was able to apply the catalog. Someone suggested 'sudo -i puppet agent -t' which works. I have since discovered that even restarting the agent daemon with sudo ('sudo /etc/init.d/puppet restart') causes the a mismatch. This is much more insidious because the running daemon will fail on every run.

inkblot and others added 8 commits May 2, 2012 18:28
…unning puppet as root using sudo because mysql will still look in the user's home directory in that case unless told otherwise.
Conflicts:
	lib/puppet/provider/database/mysql.rb
There are some added invocations of mysql and mysqladmin since the original
commit that also need the defaults file specified.
mysql and mysqladmin are not actually interpolating ~root, but there's a fact
for that.
The fact supplied by stdlib is root_home.
These commands are using unqualified table names, so a database needs to be
specified.
@nelg
Copy link

nelg commented Aug 23, 2012

I have merged this change and tested it on the systems I managed.

This change is required for me as puppet otherwise returns errors about not being able to find .my.cnf, as $HOME is not /root when puppet is started via the init script, and via the way we run puppet manually.

Please can someone merge this change into puppetlabs-mysql.

@hunner
Copy link
Contributor

hunner commented Aug 24, 2012

Hi @inkblot, thanks for this pull request!

This is definitely something we want to merge, but 7 of the provider spec tests will fail because they are expecting specific arguments to the mysql() function. Could you please update the spec tests as well, so that we can merge this cleanly? Thanks!

@inkblot
Copy link
Contributor Author

inkblot commented Aug 26, 2012

What gems are required to run the rspec suite?

@hunner
Copy link
Contributor

hunner commented Aug 27, 2012

@inkblot You should only have to gem install puppetlabs_spec_helper . Then you can run rake help to see the available tasks or rake spec to run the spec tests. If more steps are required then we would like to know!

@inkblot
Copy link
Contributor Author

inkblot commented Aug 28, 2012

There are more. In a clean gemset after installing puppetlabs_spec_helper:

no such file to load -- puppet (LoadError)

I will committing a Gemfile.

@hunner
Copy link
Contributor

hunner commented Aug 28, 2012

Ah sorry, I forgot to mention that puppet is a requirement as well (whether system packages or gems) because I just take it for granted :).

@hunner
Copy link
Contributor

hunner commented Aug 28, 2012

@inkblot
Copy link
Contributor Author

inkblot commented Aug 29, 2012

bundle install doesn't see .gemfile. How does one use a Gemfile that's called .gemfile?

@inkblot
Copy link
Contributor Author

inkblot commented Aug 29, 2012

Found the blog post. How do I mock the root_home fact from stdlib so that the spec can assert a stable value?

@inkblot
Copy link
Contributor Author

inkblot commented Aug 29, 2012

After running bundler, git status tells me I've made changes. I disagree. Is .gemfile.lock supposed to be in .gitignores?

Also, after running rake spec git says there are more changes, and then after rake spec_clean it changes again.

@hunner
Copy link
Contributor

hunner commented Aug 29, 2012

@inkblot Perhaps .gemfile.lock should be in .gitignore. I'm not sure. I think the rake spec making changes is for spec/fixtures? That should probably also be in the ignore.

You can mock the $root_home fact by adding it to the appropriate let(:facts) { ... } like https://github.com/puppetlabs/puppetlabs-mysql/blob/master/spec/classes/mysql_server_spec.rb#L12

The mysql invocations in the provider changed, and they're pretty tightly
coupled, so they need to be updated here.   The :root_home fact isn't getting
set for some reason, but this does pass as is.
This demonstrates facts not getting mocked.  I don't know enough to say why.
@inkblot
Copy link
Contributor Author

inkblot commented Aug 30, 2012

@hunner Can you take a look at this spec and help me understand what's not working right? The fact isn't getting successfully mocked. One thing I notice is that all of the other specs that mock facts are in spec/classes, and this one is in spec/unit. Is there a significant difference between the two location?

@rockymeza
Copy link

I tried to use this pull request, but when I ran it as is, I encountered an error:

remote: err: /Stage[main]//Node[********]/Django::Site[***]/Mysql::Db[***]/Database[***]/ensure: change from absent to present failed: Execution of '/usr/bin/mysql --defaults-file=~root/.my.cnf -NBe create database `***` character set utf8' returned 1: Could not open required defaults file: /home/puppet/.git/~root/.my.cnf
remote: Fatal error in defaults handling. Program aborted

I tried it with just /root/.my.cnf and it worked, but I don't know how portable that is.

@rockymeza
Copy link

Sorry, nevermind, I used an updated version that uses Facter. My bad.

@hunner
Copy link
Contributor

hunner commented Oct 4, 2012

Pinging again for this. @branan, could you review it?

This needs to be rebased to be merged.

@hunner hunner mentioned this pull request Oct 9, 2012
@hunner hunner closed this Oct 9, 2012
pmcmaw pushed a commit to pmcmaw/puppetlabs-mysql that referenced this pull request Mar 3, 2021
pdksync - (maint) Update pdk-template to f778803
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.

5 participants