Skip to content

Commit 23f89af

Browse files
authored
Merge pull request #1295 from andeman/master
(MODULES-1550) add new Feature MySQL login paths
2 parents 4a056a8 + 0bbe3fe commit 23f89af

File tree

20 files changed

+1549
-2
lines changed

20 files changed

+1549
-2
lines changed

.sync.yml

+1
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

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ group :development do
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')
3333
gem 'ed25519', '>= 1.2', '< 2.0'
3434
gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0'
35+
gem "puppet-resource_api", require: false
3536
end
3637

3738
puppet_version = ENV['PUPPET_GEM_VERSION']

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,36 @@ mysql::db { 'mydb':
184184

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

187+
### Create login paths
188+
189+
This feature works only for the MySQL Community Edition >= 5.6.6.
190+
191+
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.
192+
193+
More information about MySQL login paths: https://dev.mysql.com/doc/refman/8.0/en/mysql-config-editor.html.
194+
195+
Some example for login paths:
196+
```puppet
197+
mysql_login_path { 'client':
198+
owner => root,
199+
host => 'localhost',
200+
user => 'root',
201+
password => Sensitive('secure'),
202+
socket => '/var/run/mysqld/mysqld.sock',
203+
ensure => present,
204+
}
205+
206+
mysql_login_path { 'remote_db':
207+
owner => root,
208+
host => '10.0.0.1',
209+
user => 'network',
210+
password => Sensitive('secure'),
211+
port => 3306,
212+
ensure => present,
213+
}
214+
```
215+
See examples/mysql_login_path.pp for further examples.
216+
187217
### Install Percona server on CentOS
188218

189219
This example shows how to do a minimal installation of a Percona server on a
@@ -613,3 +643,4 @@ This module is based on work by David Schmitt. The following contributors have c
613643
* Daniël van Eeden
614644
* Jan-Otto Kröpke
615645
* Timothy Sven Nelson
646+
* Andreas Stürz

REFERENCE.md

+136-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ _Private Classes_
3232
* `mysql::server::config`: Private class for MySQL server configuration.
3333
* `mysql::server::install`: Private class for managing MySQL package.
3434
* `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
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,6 +57,7 @@ _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
@@ -66,6 +68,14 @@ then returns the resulting hash.
6668

6769
* [`Mysql::Options`](#mysqloptions):
6870

71+
**Data types**
72+
73+
* [`Mysql::Options`](#mysqloptions):
74+
75+
**Data types**
76+
77+
* [`Mysql::Options`](#mysqloptions):
78+
6979
**Tasks**
7080

7181
* [`export`](#export): Allows you to backup your database to local file.
@@ -1157,6 +1167,100 @@ namevar
11571167

11581168
Name to describe the grant.
11591169

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

11621266
Manage MySQL plugins.
@@ -1268,6 +1372,37 @@ The name of the user. This uses the 'username@hostname' or username@hostname.
12681372

12691373
## Functions
12701374

1375+
### mysql::mysql_password
1376+
1377+
Type: Ruby 4.x API
1378+
1379+
---- original file header ----
1380+
1381+
Hash a string as mysql's "PASSWORD()" function would do it
1382+
1383+
@param [String] password Plain text password.
1384+
1385+
@return [String] the mysql password hash from the clear text password.
1386+
1387+
#### `mysql::mysql_password(Any *$args)`
1388+
1389+
---- original file header ----
1390+
1391+
Hash a string as mysql's "PASSWORD()" function would do it
1392+
1393+
@param [String] password Plain text password.
1394+
1395+
@return [String] the mysql password hash from the clear text password.
1396+
1397+
Returns: `Data type` Describe what the function returns here
1398+
1399+
##### `*args`
1400+
1401+
Data type: `Any`
1402+
1403+
The original array of arguments. Port this to individually managed params
1404+
to get the full benefit of the modern function API.
1405+
12711406
### mysql::normalise_and_deepmerge
12721407

12731408
Type: Ruby 4.x API

examples/mysql_login_path.pp

+68
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)