sous-chefs / mysql

Development repository for the mysql cookbook
https://supermarket.chef.io/cookbooks/mysql
Apache License 2.0
338 stars 690 forks source link

ctrl_user is being ignored at mysql_user resource #664

Closed dbpolito closed 3 years ago

dbpolito commented 3 years ago

I'm doing something like this:

# create database
mysql_database 'database' do
  host node[:app][:db_host]
  port node[:app][:db_port]
  database_name node[:app][:db_name]
  user 'admin'
  password 'rootpass'
  encoding 'latin1'
  collation 'latin1_swedish_ci'
end

# create user
mysql_user 'user' do
  ctrl_host node[:app][:db_host]
  ctrl_port node[:app][:db_port]
  ctrl_user 'admin'
  ctrl_password 'rootpass'

  username node[:app][:db_user]
  database_name node[:app][:db_name]
  host '%'
  password 'pass'

  action [ :create, :grant ]
end

mysql_database works fine, but mysql_user breaks because it still trying to use root user

 [2021-03-12T15:02:47+00:00] FATAL: mysql: [Warning] Using a password on the command line interface can be insecure.
     ERROR 1045 (28000): Access denied for user 'root'@'10.0.11.54' (using password: YES)

Looking at the code i suspect it may be related, if you look at:

https://github.com/sous-chefs/mysql/blob/master/resources/mysql_user.rb#L57 https://github.com/sous-chefs/mysql/blob/master/resources/mysql_user.rb#L69

One is mapping to username and the other with user

https://github.com/sous-chefs/mysql/blob/master/resources/mysql_database.rb#L85

On database it does use user.

ramereth commented 3 years ago

@dbpolito can you please provide what you're using for the various attributes you use in your example, or change them to something else I could just copy/paste for replicating it on my end? Thanks!

dbpolito commented 3 years ago
# create database
mysql_database 'database' do
  host 'localhost'
  port '3306'
  database_name 'database'
  user 'admin'
  password 'rootpass'
  encoding 'latin1'
  collation 'latin1_swedish_ci'
end

# create user
mysql_user 'user' do
  ctrl_host 'localhost'
  ctrl_port '3306'
  ctrl_user 'admin'
  ctrl_password 'rootpass'

  username 'username'
  database_name 'database'
  host '%'
  password 'pass'

  action [ :create, :grant ]
end

My issue is that i'm managing an RDS database which the root user isn't called root, in my case it's admin, and ctrl_user is being ignored and the query is still uring root

ramereth commented 3 years ago

@dbpolito can you please confirm that #665 resolves this problem?

dbpolito commented 3 years ago

@ramereth it does look it will do the trick, thanks for looking into that :+1: