Commit graph

77 commits

Author SHA1 Message Date
Quentin Moss
8d4b83159e
Add limit to mysql server ID generated value 2016-08-09 17:05:22 -07:00
Helen Campbell
2a888f714d Fix for mysql version retrieval 2016-07-21 15:55:49 +01:00
tphoney
f183e492d9 fixing the failing unit tests for mysql_user 2016-06-21 13:35:10 +01:00
Jon Topper
ec5450ec75 Use facts for mysqld version discovery
Per https://tickets.puppetlabs.com/browse/MODULES-3441, the mysql
module has behaviour which varies by server version. The version is
discovered by running mysqld -V. On hosts without a MySQL server
package install, this fails, which means that contrary to the README,
it's not actually possible to use this module to manage a remote db.

This PR moves the version string discovery into a new fact,
mysqld_version which is used by the provider. This makes it possible
to configure the db version with a custom fact when a remote db
(eg AWS RDS) is being managed.
2016-06-15 10:43:50 +02:00
Frank van Boven
b8d301527e (MODULES-2111) Add the system database to user related tables.
Change the behaviour of applying user and grant related changes to use
the system database of MySQL.

This is a workaround to fix a bug in MySQL
(https://bugs.mysql.com/bug.php?id=65923) that causes users and grants
to be replicated, even if the "mysql" database should not be replicated.
2016-05-02 14:52:44 +02:00
Hunter Haugen
f4fe313e65 Remove mysql_table_exists() function
This function is intended to check for the existence of a table before
declaring some resource, but this is neither portable (because functions
orun on the master, not the agent) nor one-run idempotent (because the
function would run before mysql is even installed, and would take two
runs to do anything).

The correct way of doing this would be to update the providers and
dependency ordering to handle the conditional states.

Luckily this was never released so it is backwards compatible.
2016-03-28 10:48:58 -07:00
Jakub Husak
1a67c3868b Loosen MariaDB recognition to fix it on Debian 8 2016-03-18 16:26:48 +01:00
Robert Heinzmann
bdf4d0f52d Fixed MySQL 5.7.6++ compatibility
- Added MySQL version and flavour detection support
  - Added mysql_datadir provider/type (replaces Exec[mysql_install_db])
  - Added version specific parameters my.cnf ([mysqld-5.X] sections)
  - Version specific user mangement SQL (ALTER USER for 5.7.6++ ...)

Rebased-By: David Schmitt <david.schmitt@puppetlabs.com>
2015-12-10 18:39:40 +00:00
Martin Hagstrom
61058b7610 Don't hash passwords that are already hashed 2015-11-19 07:54:10 +01:00
Artur Gadelshin
27323f74e6 (MODULES-2767) fix mysql_table_exists: add check for args.size, fix rspec test 2015-11-09 16:04:38 +03:00
Artur Gadelshin
e518abd97e (MODULES-2767) allow to check if table exists before grant 2015-11-07 19:23:20 +03:00
Joseph Karns
96c9d6d9a7 Fixes unique server_id within my.cnf, The issue was that the entire mac address was not being read in to generate the id. 2015-10-12 12:36:39 -04:00
Roman Mueller
afddc3ff7b Fix fetching the mysql_user password for MySQL >=5.7.6
The password column has been renamed to authentication_string in MySQL >=5.7.6.
By using: SELECT /*!50706 AUTHENTICATION_STRING AS */ PASSWORD the query will
continue to work in older versions as well as newer ones.
2015-09-30 18:55:26 +02:00
Morgan Haskel
97b8200a5f Improved user validation and munging
We want to make sure we are validating the entire user parameter (and
validating it consistently between mysql_user and mysql_grant).
Additionally, for munging we do not want to do anything that could
truncate the username.
2015-09-24 11:35:14 -07:00
Igor Galić
837c21b963 length check for usernames should take mysql version into consideration
Starting MariaDB 10.0.0, usernames are now 80 long.
Our mysql_user and mysql_grant types now take that into consideration.

This check is *opportunistic*. It will only take place if the
mysql_version fact is available. If that is not the case, it will be
skipped, leaving the database itself to deal with it, and returning its
error verbatim to our users, if it does fail.

Our fixed and extended tests assume this isn't the first run, and the
fact is already in place.
2015-05-29 14:13:39 +02:00
Travis Fields
3ce8ad3799 (maint) - Add a fact for capturing the mysql version installed
- Add spec test for mysql_version fact
- Add `mysql_version` fact to README
2015-05-08 08:51:38 -07:00
tphoney
78a787107f minor typos fixed 2015-03-04 10:56:32 +00:00
Igor Galić
d7077b43d2 document mysql_server_id fact and add spec tests
add spec tests, expand documentation to mention lo behaviour
also, rename fact, for, consistency.
2015-03-04 08:56:45 +01:00
Hunter Haugen
b3a38a8dfe Merge pull request #645 from dveeden/auth-plugins
Support authentication plugins
2015-02-06 12:40:49 -08:00
Hunter Haugen
3fa70506c4 Merge pull request #646 from dveeden/emptypwd
Return an empty string for an empty input.
2015-02-05 10:39:28 -08:00
Daniël van Eeden
279c13b5e3 Return an empty string for an empty input.
https://tickets.puppetlabs.com/browse/MODULES-1676

This is identical to what PASSWORD('') in MySQL does:

5.6.22-debug-log> CREATE USER 'testpwd'@'localhost' IDENTIFIED BY 'foo';
Query OK, 0 rows affected (0.03 sec)

5.6.22-debug-log> SELECT User,Host,Password FROM mysql.user WHERE
User='testpwd';
+---------+-----------+-------------------------------------------+
| User    | Host      | Password                                  |
+---------+-----------+-------------------------------------------+
| testpwd | localhost | *F3A2A51A9B0F2BE2468926B4132313728C250DBF |
+---------+-----------+-------------------------------------------+
1 row in set (0.01 sec)

5.6.22-debug-log> SET PASSWORD FOR 'testpwd'@'localhost' = PASSWORD('');
Query OK, 0 rows affected (0.00 sec)

5.6.22-debug-log> SELECT User,Host,Password FROM mysql.user WHERE
User='testpwd';
+---------+-----------+----------+
| User    | Host      | Password |
+---------+-----------+----------+
| testpwd | localhost |          |
+---------+-----------+----------+
1 row in set (0.00 sec)
2015-01-28 21:08:29 +01:00
Daniël van Eeden
74132ec038 Add type & provider for managing plugins 2015-01-26 15:03:45 +01:00
Daniël van Eeden
367fcf06af Support authentication plugins
This uses CREATE USER xxx IDENTIFIED WITH yyy

For tests:
 unix_socket is not loaded by default, so this might require:
 install plugin unix_socket soname 'auth_socket.so';

 The mysql_native_password plugin is available by default and
 allows you to also set a password.

Try to make it compatible with MySQL < 5.5.7 it uses version
specific code with "/*!50508 stmt */"
2015-01-24 17:28:17 +01:00
Colleen Murphy
ccf37e7c8d Revert "Support for authentication plugins" 2015-01-22 11:27:41 -08:00
Daniël van Eeden
305b0d2a87 Support authentication plugins
This uses CREATE USER xxx IDENTIFIED WITH yyy

For tests:
 unix_socket is not loaded by default, so this might require:
 install plugin unix_socket soname 'auth_socket.so';

 The mysql_native_password plugin is available by default and
 allows you to also set a password.
2015-01-17 18:41:37 +01:00
Morgan Haskel
f92a24ef3d MODULES-1520 - update username validation
Don't fail on validation where the user isn't quoted with special
characters. The providers quote these strings by default.
2014-12-31 11:50:48 -08:00
Sébastien Lavoie
60838a5837 Reworked all identifier quoting detections
Otherwise, trying to manage `debian-sys-maint` will fail miserably, quoted or not.

Fixes #609
2014-11-27 12:47:09 -05:00
Michael Chapman
fe0365e80d Support size 15 and 16 quoted usernames
As usernames containing special characters must be quoted, they
may have two extra characters that are not counted against the
size limit of 16 characters. This patch adds a regex to handle
this case.
2014-11-20 17:23:11 +11:00
Mason Malone
4f0d4311d9 Fix regression in username validation
Commit cdd7132ff9 added logic to catch invalid database usernames,
but the regex it uses fails to match usernames with special characters that are properly quoted,
causing errors with usernames that used to work in versions < 3.0.0. This fixes the regex so that
if the username is quoted, anything is allowed between the quotes.

From the docs (http://dev.mysql.com/doc/refman/5.5/en/identifiers.html):
"Permitted characters in quoted identifiers include the full Unicode Basic Multilingual Plane (BMP),
except U+0000"
2014-11-13 18:18:02 -05: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
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
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
00a191f9ed Convert specs to RSpec 2.99.1 syntax with Transpec
This conversion is done by Transpec 2.3.6 with the following command:
    transpec -f -c "bundle exec rake spec"

* 69 conversions
    from: it { should ... }
      to: it { is_expected.to ... }

* 48 conversions
    from: obj.should
      to: expect(obj).to

* 34 conversions
    from: == expected
      to: eq(expected)

* 4 conversions
    from: it { should_not ... }
      to: it { is_expected.not_to ... }

* 3 conversions
    from: obj.should_not
      to: expect(obj).not_to

* 2 conversions
    from: lambda { }.should
      to: expect { }.to

* 2 conversions
    from: pending
      to: skip

For more details: https://github.com/yujinakayama/transpec#supported-conversions
2014-08-08 16:47:44 -04:00
Ashley Penney
bb205ad2f0 Remove all the deprecated code. 2014-08-08 14:13:22 -04:00
Ashley Penney
994ac1a058 Rebuild the acceptance tests. 2014-08-07 15:52:19 -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
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
Igor Galić
b39ebdcf74 Merge pull request #505 from larsks/bz/1093367
lowercase hostname values in qualified usernames
2014-06-05 12:17:04 +02: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
William Van Hevelingen
669466c315 RSpec renamed be_true to be_truthy in 3.0
This commits updates the spec tests to use the renamed function.
2014-06-03 23:31:19 -07: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
Steve Saliman
80b97d295d Fixed a couple of failing tests 2014-01-24 13:06:34 -07:00
Jim Radford
16baff686c mysql_deepmerge should treat underscore and dash equivalently, as mysql does 2014-01-23 22:41:58 -08:00
Srinath M
a571df4c79 Fixed testing for creating a DB with the [if not exists] clause 2013-12-16 09:59:43 -05: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
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
Marc Huffnagle
7ea41249e2 Fix raise_error deprecation warning 2013-10-31 12:42:42 -04:00