Skip to content

Commit c09a1ae

Browse files
(MODULES-1550) add new Feature MySQL login paths for Mysql Community Server > 5.6.6
1 parent fff2c82 commit c09a1ae

23 files changed

+1610
-3
lines changed

.sync.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Gemfile:
3636
git: https://github.com/skywinder/github-changelog-generator
3737
ref: 20ee04ba1234e9e83eb2ffb5056e23d641c7a018
3838
condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')
39+
- gem: puppet-resource_api
3940
Rakefile:
4041
requires:
4142
- puppet_pot_generator/rake_tasks

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ group :development do
3030
gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw]
3131
gem "puppet-lint-i18n", require: false
3232
gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')
33+
gem "puppet-resource_api", require: false
3334
end
3435

3536
puppet_version = ENV['PUPPET_GEM_VERSION']

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,36 @@ mysql::db { 'mydb':
183183

184184
If required, the password can also be an empty string to allow connections without an password.
185185

186+
### Create login paths
187+
188+
This feature works only for the MySQL Community Edition >= 5.6.6.
189+
190+
A login path is a set of options (host, user, password, port and socket) that specify which MySQL server to connect to and which account to authenticate as. The authentication credentials and the other options are stored in an encrypted login file named .mylogin.cnf typically under the users home directory.
191+
192+
More information about MySQL login paths: https://dev.mysql.com/doc/refman/8.0/en/mysql-config-editor.html.
193+
194+
Some example for login paths:
195+
```puppet
196+
mysql_login_path { 'client':
197+
owner => root,
198+
host => 'localhost',
199+
user => 'root',
200+
password => Sensitive('secure'),
201+
socket => '/var/run/mysqld/mysqld.sock',
202+
ensure => present,
203+
}
204+
205+
mysql_login_path { 'remote_db':
206+
owner => root,
207+
host => '10.0.0.1',
208+
user => 'network',
209+
password => Sensitive('secure'),
210+
port => 3306,
211+
ensure => present,
212+
}
213+
```
214+
See examples/mysql_login_path.pp for further examples.
215+
186216
### Install Percona server on CentOS
187217

188218
This example shows how to do a minimal installation of a Percona server on a
@@ -549,3 +579,4 @@ This module is based on work by David Schmitt. The following contributors have c
549579
* Daniël van Eeden
550580
* Jan-Otto Kröpke
551581
* Timothy Sven Nelson
582+
* Andreas Stürz

REFERENCE.md

Lines changed: 173 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ _Private Classes_
2929
* `mysql::client::install`: Private class for MySQL client install.
3030
* `mysql::params`: Params class.
3131
* `mysql::server::account_security`: Private class for ensuring localhost accounts do not exist
32-
* `mysql::server::binarylog`: Binary log configuration requires the mysql user to be present. This must be done after package install
3332
* `mysql::server::config`: Private class for MySQL server configuration.
3433
* `mysql::server::install`: Private class for managing MySQL package.
3534
* `mysql::server::installdb`: Builds initial databases on installation.
35+
* `mysql::server::managed_dirs`: Binary log configuration requires the mysql user to be present. This must be done after package install
3636
* `mysql::server::providers`: Convenience class to call each of the three providers with the corresponding hashes provided in mysql::server.
3737
* `mysql::server::root_password`: Private class for managing the root password
3838
* `mysql::server::service`: Private class for managing the MySQL service
@@ -46,6 +46,7 @@ _Private Classes_
4646
_Public Resource types_
4747

4848
* [`mysql_grant`](#mysql_grant): @summary Manage a MySQL user's rights.
49+
* [`mysql_login_path`](#mysql_login_path): Manage a MySQL login path.
4950
* [`mysql_plugin`](#mysql_plugin): Manage MySQL plugins.
5051
* [`mysql_user`](#mysql_user): @summary Manage a MySQL user. This includes management of users password as well as privileges.
5152

@@ -56,12 +57,17 @@ _Private Resource types_
5657

5758
**Functions**
5859

60+
* [`mysql::mysql_password`](#mysqlmysql_password): @summary
5961
* [`mysql::normalise_and_deepmerge`](#mysqlnormalise_and_deepmerge): Recursively merges two or more hashes together, normalises keys with differing use of dashesh and underscores,
6062
then returns the resulting hash.
6163
* [`mysql::password`](#mysqlpassword): Hash a string as mysql's "PASSWORD()" function would do it
6264
* [`mysql::strip_hash`](#mysqlstrip_hash): When given a hash this function strips out all blank entries.
6365
* [`mysql_password`](#mysql_password): Hash a string as mysql's "PASSWORD()" function would do it
6466

67+
**Data types**
68+
69+
* [`Mysql::Options`](#mysqloptions):
70+
6571
**Tasks**
6672

6773
* [`export`](#export): Allows you to backup your database to local file.
@@ -411,6 +417,14 @@ The location, as a path, of the MySQL configuration file.
411417

412418
Default value: $mysql::params::config_file
413419

420+
##### `config_file_mode`
421+
422+
Data type: `Any`
423+
424+
The MySQL configuration file's permissions mode.
425+
426+
Default value: $mysql::params::config_file_mode
427+
414428
##### `includedir`
415429

416430
Data type: `Any`
@@ -443,6 +457,14 @@ Whether the MySQL configuration file should be managed. Valid values are `true`,
443457

444458
Default value: $mysql::params::manage_config_file
445459

460+
##### `options`
461+
462+
Data type: `Mysql::Options`
463+
464+
A hash of options structured like the override_options, but not merged with the default options. Use this if you don’t want your options merged with the default options.
465+
466+
Default value: {}
467+
446468
##### `override_options`
447469

448470
Data type: `Any`
@@ -515,6 +537,22 @@ The name of the group of the MySQL daemon user. Can be a group name or a group I
515537

516538
Default value: $mysql::params::mysql_group
517539

540+
##### `mycnf_owner`
541+
542+
Data type: `Any`
543+
544+
Name or user-id who owns the mysql-config-file.
545+
546+
Default value: $mysql::params::mycnf_owner
547+
548+
##### `mycnf_group`
549+
550+
Data type: `Any`
551+
552+
Name or group-id which owns the mysql-config-file.
553+
554+
Default value: $mysql::params::mycnf_group
555+
518556
##### `root_password`
519557

520558
Data type: `Any`
@@ -715,7 +753,7 @@ Default value: $mysql::params::root_group
715753

716754
Data type: `Any`
717755

718-
Whether or not to compress the backup (when using the mysqldump provider)
756+
Whether or not to compress the backup (when using the mysqldump or xtrabackup provider)
719757

720758
Default value: `true`
721759

@@ -1113,6 +1151,100 @@ namevar
11131151

11141152
Name to describe the grant.
11151153

1154+
### mysql_login_path
1155+
1156+
This type provides Puppet with the capabilities to store authentication credentials in an obfuscated login path file
1157+
named .mylogin.cnf created with the mysql_config_editor utility. Supports only MySQL Community Edition > v5.6.6.
1158+
1159+
* **See also**
1160+
https://dev.mysql.com/doc/refman/8.0/en/mysql-config-editor.html
1161+
1162+
#### Examples
1163+
1164+
#####
1165+
1166+
```puppet
1167+
mysql_login_path { 'local_socket':
1168+
owner => 'root',
1169+
host => 'localhost',
1170+
user => 'root',
1171+
password => Sensitive('secure'),
1172+
socket => '/var/run/mysql/mysql.sock',
1173+
ensure => present,
1174+
}
1175+
1176+
mysql_login_path { 'local_tcp':
1177+
owner => 'root',
1178+
host => '127.0.0.1',
1179+
user => 'root',
1180+
password => Sensitive('more_secure'),
1181+
port => 3306,
1182+
ensure => present,
1183+
}
1184+
```
1185+
1186+
#### Properties
1187+
1188+
The following properties are available in the `mysql_login_path` type.
1189+
1190+
##### `ensure`
1191+
1192+
Data type: `Enum[present, absent]`
1193+
1194+
Whether this resource should be present or absent on the target system.
1195+
1196+
##### `host`
1197+
1198+
Data type: `Optional[String]`
1199+
1200+
Host name to be entered into the login path.
1201+
1202+
##### `user`
1203+
1204+
Data type: `Optional[String]`
1205+
1206+
Username to be entered into the login path.
1207+
1208+
##### `password`
1209+
1210+
Data type: `Optional[Sensitive[String[1]]]`
1211+
1212+
Password to be entered into login path
1213+
1214+
##### `socket`
1215+
1216+
Data type: `Optional[String]`
1217+
1218+
Socket path to be entered into login path
1219+
1220+
##### `port`
1221+
1222+
Data type: `Optional[Integer[0,65535]]`
1223+
1224+
Port number to be entered into login path.
1225+
1226+
#### Parameters
1227+
1228+
The following parameters are available in the `mysql_login_path` type.
1229+
1230+
##### `name`
1231+
1232+
namevar
1233+
1234+
Data type: `String`
1235+
1236+
Name of the login path you want to manage.
1237+
1238+
##### `owner`
1239+
1240+
namevar
1241+
1242+
Data type: `String`
1243+
1244+
The user to whom the logon path should belong.
1245+
1246+
Default value: root
1247+
11161248
### mysql_plugin
11171249

11181250
Manage MySQL plugins.
@@ -1224,6 +1356,37 @@ The name of the user. This uses the 'username@hostname' or username@hostname.
12241356

12251357
## Functions
12261358

1359+
### mysql::mysql_password
1360+
1361+
Type: Ruby 4.x API
1362+
1363+
---- original file header ----
1364+
1365+
Hash a string as mysql's "PASSWORD()" function would do it
1366+
1367+
@param [String] password Plain text password.
1368+
1369+
@return [String] the mysql password hash from the clear text password.
1370+
1371+
#### `mysql::mysql_password(Any *$args)`
1372+
1373+
---- original file header ----
1374+
1375+
Hash a string as mysql's "PASSWORD()" function would do it
1376+
1377+
@param [String] password Plain text password.
1378+
1379+
@return [String] the mysql password hash from the clear text password.
1380+
1381+
Returns: `Data type` Describe what the function returns here
1382+
1383+
##### `*args`
1384+
1385+
Data type: `Any`
1386+
1387+
The original array of arguments. Port this to individually managed params
1388+
to get the full benefit of the modern function API.
1389+
12271390
### mysql::normalise_and_deepmerge
12281391

12291392
Type: Ruby 4.x API
@@ -1326,6 +1489,14 @@ Data type: `String`
13261489

13271490
Plain text password.
13281491

1492+
## Data types
1493+
1494+
### Mysql::Options
1495+
1496+
The Mysql::Options data type.
1497+
1498+
Alias of `Hash[String, Hash]`
1499+
13291500
## Tasks
13301501

13311502
### export

examples/mysql_login_path.pp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Debian MySQL Commiunity Server 8.0
2+
include apt
3+
apt::source { 'repo.mysql.com':
4+
location => 'http://repo.mysql.com/apt/debian',
5+
release => $::lsbdistcodename,
6+
repos => 'mysql-8.0',
7+
key => {
8+
id => 'A4A9406876FCBD3C456770C88C718D3B5072E1F5',
9+
server => 'hkp://keyserver.ubuntu.com:80',
10+
},
11+
include => {
12+
src => false,
13+
deb => true,
14+
},
15+
notify => Exec['apt-get update']
16+
}
17+
exec { 'apt-get update':
18+
path => '/usr/bin:/usr/sbin:/bin:/sbin',
19+
refreshonly => true,
20+
}
21+
22+
$root_pw = 'password'
23+
class { '::mysql::server':
24+
root_password => $root_pw,
25+
service_name => 'mysql',
26+
package_name => 'mysql-community-server',
27+
create_root_my_cnf => false,
28+
require => [
29+
Apt::Source['repo.mysql.com'],
30+
Exec['apt-get update']
31+
],
32+
notify => Mysql_login_path['client']
33+
}
34+
35+
class { '::mysql::client':
36+
package_manage => false,
37+
package_name => 'mysql-community-client',
38+
require => Class['::mysql::server'],
39+
}
40+
41+
mysql_login_path { 'client':
42+
ensure => present,
43+
host => 'localhost',
44+
user => 'root',
45+
password => Sensitive($root_pw),
46+
socket => '/var/run/mysqld/mysqld.sock',
47+
owner => root,
48+
}
49+
50+
mysql_login_path { 'local_dan':
51+
ensure => present,
52+
host => '127.0.0.1',
53+
user => 'dan',
54+
password => Sensitive('blah'),
55+
port => 3306,
56+
owner => root,
57+
require => Class['::mysql::server'],
58+
}
59+
60+
mysql_user { 'dan@localhost':
61+
ensure => present,
62+
password_hash => mysql::password('blah'),
63+
require => Mysql_login_path['client'],
64+
}
65+
66+
67+
68+

0 commit comments

Comments
 (0)