Commit graph

126 commits

Author SHA1 Message Date
Igor Galić
8dd37aea3a Merge pull request #594 from skroll/escape_backslash
Fix escaped backslashes in grants
2014-11-07 15:23:52 +01:00
Maxence Dunnewind
cdd7132ff9 Improve checks for MySQL user's name.
As per http://dev.mysql.com/doc/refman/5.5/en/identifiers.html , MySQL
allows for more than '\w-'. This commit improves the check to ensure
that:
 - if username only contains [0-9a-zA-Z$_], it might be quoted. It is
   not a requirement though
 - if username contains anything else, it MUST be quoted

I kept 2 checks, but the 2nd one can probably be removed (I can't find a
username which match the 2nd one but not the first.)
2014-11-06 08:51:07 +01:00
Scott Kroll
9dbdd89c7a Fix escaped backslashes in grants
* Mysql uses the underscore character to represent a single character
  wildcard.
* A grant on table `the_database`.* would match `theAdatabase`.*, so
  underscores must be escaped to avoid this match.
* The output from mysql escapes special characters (\n, \t, \0, and \\),
  but the input does not need to be escaped.
* In order for the provider to compare the tables, the output of
  mysql -NBe <query> must have \\ substituted with \.
2014-11-05 14:53:14 -05:00
Igor Galić
40dd180588 Merge pull request #571 from jtopper/master
[MODULES-1333] Add explicit dependencies for mysql_database and mysql_user types
2014-10-28 16:14:59 +01:00
Maxence Dunnewind
46065c4095 The old regex requires something after the 'host' part. Fix this.
Old regex is : /^GRANT\s(.+)\sON\s(.+)\sTO\s(.*)@(.*?)(\s.*)$/ . The
last part (\s.*)$ means "a space followed by anything". The issue is
that when user has no GRANT privileges, the "SHOW GRANTS FOR #{user_string}" returns
"GRANT SELECT ON `database`.* TO 'user'@'%'" which does not match (\s.*)$ .
This small patch fixes this making last bloc optional (thanks to '?').
2014-10-27 16:41:33 +01:00
Igor Galić
400d3b29cf Merge pull request #570 from fnerdwq/mysql_grant_column_privs
(MODULES-552) Add capability to specify column_privileges
2014-10-07 15:46:08 +02:00
Frederik Wagner
f88719b52f (MODULES-552) Add capability to specify column_privileges 2014-10-06 08:11:01 +02:00
Jon Topper
c4d45c3eb5 Add explicit dependencies for types
mysql_grant has an autorequire()'d dependency on the .my.cnf file used
by the provider to talk to the database.

I've added this to mysql_database and mysql_user too since logically
these also need the file to be in place.

I've hit this bug because of a slightly unusual edge case in our own
manifests, but I think this fix belongs upstream regardless.
2014-09-16 15:46:13 +01:00
Igor Galić
443ff061ea Merge pull request #569 from fnerdwq/mysql_grant_revokation
(MODULES-1330) Change order of revokation.
2014-09-16 15:02:13 +02:00
Frederik Wagner
bbbc6cd446 (MODULES-1330) Change order of revokation 2014-09-16 14:06:26 +02:00
Matthew Monaco
d986a87558 mysql_database: prevent syntax error with collate=>'binary'
On MySQL v5.5.38, creating a database such as:

	CREATE DATABASE `mydb` CHARACTER SET binary COLLATE binary;

seems to hit a parser bug. A workaround is simply to quote COLLATE
`binary`. As the quoting is harmless, and for aesthetics, quote both
the CHARACTER SET and COLLATE arguments.
2014-09-15 23:22:59 -06:00
Ashley Penney
bb205ad2f0 Remove all the deprecated code. 2014-08-08 14:13:22 -04:00
Ray Lehtiniemi
548952a6f9 Prevent ERROR 1008 in mysql_database provider
Check for database existence when dropping to prevent

  ERROR 1008 (HY000): Can't drop database 'test'; database doesn't exist

Signed-off-by: Ray Lehtiniemi <rayl@mail.com>
2014-07-23 21:41:16 -06:00
jsosic
356672342e Fix problem with GRANT not recognizing backslash
If database grant has backslash in database name (for example: example\_dev), then puppet will try to apply same resource every run because MySQL reports that table name with double backslash (for example: example\\_dev). By global replace of double backslash with single one, this issue is fixed.
2014-07-13 04:01:53 +02:00
Jaakko
3cfbb581cc Change grant provider to ignore grants for non existing users.
In the grant provider users are fetched by querying mysql.user table. Grants
for those users are fetched using show grants for... syntax. This can lead to
errors, when some of the users in mysql.user table do not have currently
active grants.

This happens at least when MySQL is started with --skip-name-resolve option,
when there are users with the hostname part specified as a FQDN. Such users are
created by mysql_install_db. This leads to problems if mysql::account_security
is included for the node and skip-name-resolve is specified in override_options
hash for mysql::server.

Includes acceptance test for the change.
2014-06-17 13:07:56 +02:00
Ashley Penney
d884e2fc1e Merge pull request #522 from cmurphy/fix_mysql_grant_MODULES-1040
Require title of mysql_grant resource to match form user/table
2014-06-05 13:07:40 -04:00
Colleen Murphy
07b661dcea Require title of mysql_grant resource to match form user/table
This addresses https://tickets.puppetlabs.com/browse/MODULES-1040.
The user parameter is required to have the form username@host. A grant
is identified in the instances method by a name of the form
username@host/table. The resource will fail to be identified as already
existing if the name given to the resource does not match this form.
2014-06-04 10:44:36 -07:00
Lars Kellogg-Stedman
0afb8f09e8 lowercase hostname values in qualified usernames
MySQL/MariaDB automatically downcase hostnames:

  MariaDB [mysql]> create user 'testuser'@'HOSTNAME';
  MariaDB [mysql]> select user,host from user where host = 'hostname';
  +----------+----------+
  | user     | host     |
  +----------+----------+
  | testuser | hostname |
  +----------+----------+

This causes problems when a mysql_user or datbase_user has an hostname
with non-lowercase characters:

  database_user { "root@HOSTNAME":
    ensure => absent,
  }

The SELECT statements used to determine if the user exists will fail
because the comparisons use "HOSTNAME" but the database has "hostname".
This patch forces the hostname part of "user@hostname" to lower case in
the custom type definitions.
2014-06-04 09:30:45 -04:00
Ashley Penney
30ce3e0e12 Repair this by ensuring calls to mysql include the database name.
A prior commit accidently broke this, meaning that mysql_database
was querying the mysql defaults instead of each individual database
when trying to determine the current collate settings.
2014-02-18 14:38:21 -05:00
Igor Galić
c747ea7ab5 Merge pull request #422 from stevesaliman/master
fixed a quoting problem with the mysql_database provider
2014-01-25 03:50:23 -08:00
Jim Radford
16baff686c mysql_deepmerge should treat underscore and dash equivalently, as mysql does 2014-01-23 22:41:58 -08:00
Steve Saliman
21aca48e02 fixed a problem with the mysql_database provider 2014-01-22 12:44:59 -07:00
Dejan Golja
ce7b661f10 Bugfix for mysql_grant provider when we try to grant remove privileges
on PROCEDURE. Resolve for bug https://tickets.puppetlabs.com/browse/MODULES-130
(https://github.com/puppetlabs/puppetlabs-mysql/issues/378)
2014-01-20 23:56:26 +11:00
Srinath M
1cc07977c5 Added [if not exists] to [create database] clause.
this should avoid errors like:
ERROR 1007 (HY000): Can't create database 'MyDB'; database exists

This error can cause a multi-master replication to stop due to conflicting
commands between nodes. For  example, if the command create DB is run in
 different nodes and then they will send it in the replication logs to each
other and then they will try to run them second time and fail.
2013-12-15 21:47:10 -05:00
Reinhard Vicinus
07c3b76eb9 mysql_grant bugfix: remove duplicate privileges and GRANT privilege, otherwise the resource gets changed every puppet run 2013-12-11 13:17:52 +01:00
Reinhard Vicinus
9de42ac43e mysql_grant bugfix: REVOKE ALL PRIVILEGES doesn't revoke GRANT OPTION 2013-12-11 13:16:14 +01:00
Reinhard Vicinus
f5a78f1c5f mysql_grant bugfix: on table *.* SHOW GRANT can return 'WITH MAX_QUERIES_PER_HOUR' which breaks the captures on the match 2013-12-11 13:15:21 +01:00
Tamas Szasz
aee0e01d81 Type mysql_grant was limited to work only with resource names foo@localhost/*.* or foo@localhost/bar.* but NOT with root@localhost/@ which is the parsed value of "GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION" grant line.
New spec test was created for the type mysql_grant.rb
2013-11-16 19:11:39 +01:00
Tamas Szasz
fbfc5d831f defaults_file methods removed from every provider (old & new) and moved
the method to the global mysql.rb which is now included in every provider
file.

Class from the global mysql.rb file is a parent of every provider.
2013-11-16 19:09:09 +01:00
Tamas Szasz
4ac8879734 Fixed missing parent for global mysql class
Added "require" to the global mysql.rb file like in the other provider files.

defaults-file changed to defaults-extra-file in all the database_* (old) providers, the same as in the mysql_* providers.

Changed defaults-file to defaults-extra-file in all test files
2013-11-12 21:32:41 +01:00
w32-blaster
e315ee96d0 Changed defaults-file to defaults-extra-file
Should load the .my.cnf file with "--defaults-extra-file" instead of "--defaults-file". This is necessary if we have global my.cnf file but we want to use both of them.
2013-11-11 18:48:00 +01:00
Igor Galić
1afa6571fb database_user gives the wrong deprecation warning
This appears to have been a bad copy/paste error.
Reported by @vicinus, this should fix #344
2013-10-30 23:18:00 +01:00
Ashley Penney
d271ab5f76 Fix an issue with lowercase privileges.
This fixes the case where a user passes in lowercase privileges and
we incorrectly assume this means a change and reapply them.
2013-10-28 12:44:48 -04:00
Ashley Penney
c6647c46b3 Fix ordering causing mysql_grant to reapply.
Because arrays are ordered lists, Puppet compares the list of retrieved
privileges against the defined privilege list.  This causes it to
reapply privilege if the ordering differs.  We now forcibly order in
the type and the provider to make sure we never falsely reapply
privileges.
2013-10-20 12:40:18 -04:00
Ashley Penney
09f42c8bb3 Further improvements to our matching - stop trying to guess what
might be the username or hostname and just match the entire thing
no matter what it may be.
2013-10-10 13:48:24 -07:00
Ashley Penney
93aab36804 Previously we were matching to ensure that usernames matched
user@host but MySQL allows you to use @host with a blank user.

No longer .select but allow all and remove these successfully.
2013-10-08 10:12:46 -07:00
Ashley Penney
cc51d7ad7d Improve mysql_grant to work with IPv6.
This work attempts to improve the situation for matching IPv6
IP addresses, as the previous regex couldn't handle them properly.
2013-10-07 11:57:02 -07:00
Ashley Penney
f8af684fe0 Merge pull request #276 from apenney/mysql_grant_fixes
Improvements to mysql_grant.
2013-10-02 09:54:09 -07:00
Nate Riffe
aef9fd0912 Add collation with the create statement 2013-09-29 09:39:06 -05:00
Justin Burnham
1b4a486bf9 Fixes issue #274 by using recursive hash merge. 2013-09-25 10:38:08 -07:00
Ashley Penney
003d5b3c6a Improvements to mysql_grant.
Ensure that table and user are required properties, as well as remove
the optional table handling in the provider and enforce it.
2013-09-24 15:37:11 -04:00
Ashley Penney
a972e4d3a0 Merge pull request #258 from apenney/refactor
Completely redesign the MySQL module.
2013-09-23 14:05:08 -07:00
Pan
58b7dc2c87 Add quote to username and host in mysql_grant constructor
The quote is need for username and host in mysql grant. revoke and grant function is already doing it with cmd_user(). not sure why the constructor didn't do it. This patch fixed #261 and #262.
2013-09-18 17:04:36 -07:00
Ashley Penney
4d6962e868 Various adjustments to classes to align with refactored work.
Handful of changes here, such as removing flush (so that mysql_user
can be used for root password changes) and other tweaks here.

Add time option to mysql::backup.
2013-09-13 13:14:48 -04:00
Ashley Penney
6a733e9503 Add a new function, mysql_strip_hash()
This is used in the backwards compatibility code in init.pp.
2013-09-13 13:10:21 -04:00
Ashley Penney
2abccab4d9 Refactor and rename database_grant to mysql_grant.
This provider has undergone the largest set of changes and currently
just accepts a full SQL grant string as the name and then applies it,
making things easier for DBAs and removes the awkward attempts at
modelling grants into Puppet.
2013-09-03 17:24:21 -04:00
Ashley Penney
16770faa29 Rename and refactor database_user to mysql_user.
This work adds max_connections_per_hour, max_queries_per_hour, and
max_updates_per_hour support to the provider and extends self.instances to add
in the new parameters when checking existing users.  It also adds
self.prefetch in order to speed up Puppet runs.

Provider is also switched to using mk_resource_methods to generate
all the resource readers, and exists? and other methods now use the
property_hash where appropriate.

Tests rewritten to handle changes and extend code coverage.
2013-08-28 18:11:21 -04:00
Ashley Penney
7d4f9fc685 Rename and refactor database to mysql_database.
Add collate as a new managable parameter, and extend self.instances to
add in all parameters when checking existing databases.  It also adds
self.prefetch in order to speed up Puppet runs.

Provider is also switched to using mk_resource_methods to generate
all the resource readers, and exists? and other methods now use the
property_hash where appropriate.

Tests rewritten to handle changes and extend code coverage.
2013-08-28 18:11:21 -04:00
Ashley Penney
4d3f73b550 Fixes suggested by RubyMine. (style for the most part.) 2013-07-11 19:42:41 -04:00
Marius Bakke
dc2ec8101e allow setting max_user_connections during user creation 2013-07-10 10:07:56 +02:00
Marius Bakke
2548ab63e8 support max_user_connections in database_user 2013-07-08 17:31:07 +02:00
Ashley Penney
8bf03681f3 Various changes to the provider to ensure commands are successful,
as well as improvements to the tests.
2013-07-03 16:08:48 -04:00
Stuart Grimshaw
608e4e8f43 Fixed SQL for databse_grant and database_user when ANSI_QUOTES Mysql option is set. 2013-06-24 14:50:39 -07:00
François Deppierraz
3175030c7a Fix a typo in database_user.rb 2013-02-05 16:34:50 +01:00
Hunter Haugen
ca2b16c691 Patch providers for absent my.cnf
If the /root/.my.cnf file does not exist but is specified by the
`--defaults-file` argument, the mysql calls will fail. The
`mysql::config` class creates this file, but if the custom resources are
used without including our classes then it will still break.

This allows users to use our custom resources without having to use our
classes.
2013-01-10 15:31:21 -08:00
Olivier Bilodeau
8510a41bb3 fixed character-set detection regex
Previous regex matched COLLATE value instead of CHARACTER SET. For
example:

> CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */

Returned utf8_bin instead of utf8 causing an unfortunate database refresh in my
configuration. Fixed the regex by adding the optional presence of the COLLATE
keyword.
2012-12-11 12:56:57 -05:00
Hunter Haugen
64d38890c6 Add mysql argument to use mysql database back 2012-10-09 14:02:05 -07:00
Nate Riffe
bdb416053a Use root's credentials when executing mysql.
This is necessary when running puppet as root using sudo because mysql
will still look in the user's home directory in that case unless told
otherwise.
2012-10-09 13:59:58 -07:00
Janos Pasztor
ef3ccd1b8b Added : to allowed host names for IPv6 addresses 2012-09-04 21:44:51 +02:00
Reid Vandewiele
8dac527b2a Add priv validation to database_grant provider
The mysql database_grant provider currently has what is arguably a heinous
design flaw. At present:

 1. The 'privileges' parameter for the database_grant type, mysql provider,
    does not expect the same syntax as the mysql Grant command ('SELECT',
    'UPDATE', 'DELETE', etc). Rather, it expects the user to supply column
    names used to store raw grants in the mysql.db or mysql.user tables
    internally ('Select_priv', 'Update_priv', 'Delete_priv', etc).

 2. If a user supplies `privileges => [ 'SELECT', 'INSERT' ]` instead of
    `privileges => [ 'Select_priv', 'Insert_priv' ]`, the provider fails
    silently and will continuously attempt to update the privileges with
    each successive puppet run. In the specific example provided, all privs
    for the user/db will be set to false since e.g. 'INSERT' does not match
    any valid privilege.

Unfortunately it doesn't look simple to modify the provider such that the
intuitive SELECT, DELETE, etc. keywords can be used without changing
existing behavior. Leaving that alone for now, it *is* pretty simple to add
a validation function that will at least fail cleanly if non-functional
privilege values are supplied that don't mean anything to the provider. If
the user is trying to use valid MySQL Grant syntax, the new validation
procedure will recognize this and suggest a correction. Hopefully giving
users this kind of warning will clue them in to what kind of input the
provider expects.
2012-08-04 10:28:06 -07:00
Branan Purvine-Riley
66c17cd14c Merge pull request #82 from agerlic/escape_database_name
escape database name
2012-07-16 11:19:32 -07:00
Alexandre Gerlic
de0f749ea5 add missing db param to database_grant 2012-06-21 17:27:39 +02:00
Alexandre Gerlic
2817f362d5 escape database name 2012-06-20 23:58:34 +02:00
Rodrigo Menezes
f0f9e76db7 Default types hacks not needed.
Default types hacks not needed.
2012-05-22 16:50:46 -07:00
Dan Bode
05f7807fc0 Merge pull request #71 from runningman/security
Fixed regex of database user.
2012-05-06 23:56:01 -07:00
Michael Arnold
eaf9ee50f6 Fixed regex of database user.
The incorrect regex did not all for the anonymous mysql users to be
removed via the mysql::server::account_security class.  The regex is now
increased to cover for @localhost and @%.
2012-05-06 23:17:49 -07:00
Branan Purvine-Riley
6a81a2f687 (#14316) make privileges case-insensitive 2012-05-04 10:04:46 -07:00
Branan Purvine-Riley
4485dbb95f Remove the global *_PRIVS variables 2012-05-01 17:00:46 -07:00
Dan Bode
015490c787 Fix bug when querying for all database users
This commit fixes an issue in self.instances of
database_user where none of the users were actually
being detected.

There was a accidental '\' in front of the '.' which 
means that it will only consider users that have
one or more '.' in front of the '@'.

This commit removes the '\' so that all users are
returned that have one or more characters in from
of an '@'.
2012-03-14 23:05:20 -07:00
Nan Liu
b1f90fd1d2 Major refactor of mysql module.
This is a major change to the module and would be released as a new
version.

* Add self.instances to database and database_user for puppet resource.
* Update database provider to use flush method.
* Update module to conform to puppet-lint recommendations.
* Cleanup some unecessary logic in mysql::db define type.
* Move mysql_restart to config class.
* Use class to class dependency instead of resource dependency.
* Change appropriate rspec-puppet tests.
* Add fixtures directory to simplify testing.
* Update raketask and spec_helper to reflect fixture changes.
* Update mysql_password function to support validation.
* Move client installation to a separate class.
* Update documentation and readme.
2012-03-13 15:19:53 -07:00
Matthias Pigulla
d15c9d1621 (#11363) Add two missing privileges to grant: event_priv, trigger_priv
These were missing from the list of allowed privileges:

* event_priv
* trigger_priv

No rspec changes, as we don't even have basic coverage on these providers and
its a minor change so should be low risk.
2011-12-30 16:33:21 +00:00
Christian G. Warden
0292456f76 (#11184) Allow wildcards in account host names
Allow wildcard in the host part of MySQL accounts:

http://dev.mysql.com/doc/refman/5.0/en/grant.html#grant-accounts-passwords

For the examples, Add a database_user test that contains a wildcard in the host
name part.

Also in the examples, pass root_password to mysql::server in config_hash.
2011-12-05 23:39:47 +00:00
Matthias Pigulla
b0ff433860 Fix (#10882) by making all commands optional. 2011-11-16 16:49:31 +01:00
Dan Bode
4774c63435 Database should set charset on create.
Previously, the charset of the database was not
being set on create, causing puppet to have to
potentially run twice to update it.
2011-06-16 21:57:06 -07:00
Dan Bode
f65e49e2ce added more input validation for db user. 2011-05-26 18:10:30 -07:00
Dan Bode
d28f0e0327 adding first commit for mysql. 2011-05-24 23:22:43 -07:00