Skip to content

Commit 9722116

Browse files
andreas-stuerzAndreas Stuerz
authored andcommitted
(MODULES-1550) add new Feature MySQL login paths for Mysql Community Server > 5.6.6
1 parent 4a056a8 commit 9722116

File tree

23 files changed

+1567
-0
lines changed

23 files changed

+1567
-0
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
@@ -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

Lines changed: 31 additions & 0 deletions
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

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,10 @@ then returns the resulting hash.
6668

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

71+
**Data types**
72+
73+
* [`Mysql::Options`](#mysqloptions):
74+
6975
**Tasks**
7076

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

11581164
Name to describe the grant.
11591165

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

11621262
Manage MySQL plugins.
@@ -1268,6 +1368,37 @@ The name of the user. This uses the 'username@hostname' or username@hostname.
12681368

12691369
## Functions
12701370

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

12731404
Type: Ruby 4.x API

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)