Skip to content

Commit 250c0b4

Browse files
author
Steffen Jørgensen
committed
(voxpupuli#527) Add masteruser parameter
Enable setting the masteruser parameter which was introduced in Redis 6+ to be able to connect using the new ACL rules.
1 parent ad3cd35 commit 250c0b4

9 files changed

+98
-4
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ class { 'redis':
3333
}
3434
```
3535

36+
With ACL authentication
37+
38+
```puppet
39+
class { 'redis':
40+
bind => '10.0.1.1',
41+
masterauth => 'secret',
42+
masteruser => 'username',
43+
}
44+
```
45+
3646
### Slave node
3747

3848
```puppet

REFERENCE.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ The following parameters are available in the `redis` class:
122122
* [`manage_package`](#-redis--manage_package)
123123
* [`managed_by_cluster_manager`](#-redis--managed_by_cluster_manager)
124124
* [`masterauth`](#-redis--masterauth)
125+
* [`masteruser`](#-redis--masteruser)
125126
* [`maxclients`](#-redis--maxclients)
126127
* [`maxmemory`](#-redis--maxmemory)
127128
* [`maxmemory_policy`](#-redis--maxmemory_policy)
@@ -532,7 +533,15 @@ Default value: `false`
532533

533534
Data type: `Optional[Variant[String[1], Sensitive[String[1]], Deferred]]`
534535

535-
If the master is password protected (using the "requirepass" configuration
536+
If the master is password protected (using the "requirepass" configuration)
537+
538+
Default value: `undef`
539+
540+
##### <a name="-redis--masteruser"></a>`masteruser`
541+
542+
Data type: `Optional[Variant[String[1], Sensitive[String[1]], Deferred]]`
543+
544+
If the master is password protected and a user is defined (using the "user" configuration)
536545

537546
Default value: `undef`
538547

@@ -1514,6 +1523,7 @@ class {'redis::sentinel':
15141523
The following parameters are available in the `redis::sentinel` class:
15151524

15161525
* [`auth_pass`](#-redis--sentinel--auth_pass)
1526+
* [`auth_user`](#-redis--sentinel--auth_user)
15171527
* [`config_file`](#-redis--sentinel--config_file)
15181528
* [`config_file_orig`](#-redis--sentinel--config_file_orig)
15191529
* [`config_file_mode`](#-redis--sentinel--config_file_mode)
@@ -1563,6 +1573,14 @@ The password to use to authenticate with the master and slaves.
15631573

15641574
Default value: `undef`
15651575

1576+
##### <a name="-redis--sentinel--auth_user"></a>`auth_user`
1577+
1578+
Data type: `Optional[Variant[String[1], Sensitive[String[1]]]]`
1579+
1580+
The username to use to authenticate with the master and slaves.
1581+
1582+
Default value: `undef`
1583+
15661584
##### <a name="-redis--sentinel--config_file"></a>`config_file`
15671585

15681586
Data type: `Stdlib::Absolutepath`
@@ -1953,6 +1971,7 @@ The following parameters are available in the `redis::instance` defined type:
19531971
* [`managed_by_cluster_manager`](#-redis--instance--managed_by_cluster_manager)
19541972
* [`manage_service_file`](#-redis--instance--manage_service_file)
19551973
* [`masterauth`](#-redis--instance--masterauth)
1974+
* [`masteruser`](#-redis--instance--masteruser)
19561975
* [`maxclients`](#-redis--instance--maxclients)
19571976
* [`maxmemory`](#-redis--instance--maxmemory)
19581977
* [`maxmemory_policy`](#-redis--instance--maxmemory_policy)
@@ -2305,7 +2324,15 @@ Default value: `true`
23052324

23062325
Data type: `Optional[Variant[String[1], Sensitive[String[1]], Deferred]]`
23072326

2308-
If the master is password protected (using the "requirepass" configuration
2327+
If the master is password protected (using the "requirepass" configuration)
2328+
2329+
Default value: `$redis::masterauth`
2330+
2331+
##### <a name="-redis--instance--masteruser"></a>`masteruser`
2332+
2333+
Data type: `Optional[Variant[String[1], Sensitive[String[1]], Deferred]]`
2334+
2335+
If the master is password protected and a user is defined (using the "user" configuration)
23092336

23102337
Default value: `$redis::masterauth`
23112338

manifests/init.pp

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@
9595
# @param managed_by_cluster_manager
9696
# Choose if redis will be managed by a cluster manager such as pacemaker or rgmanager
9797
# @param masterauth
98-
# If the master is password protected (using the "requirepass" configuration
98+
# If the master is password protected (using the "requirepass" configuration)
99+
# @param masteruser
100+
# If the master is password protected and a user is defined (using the "user" configuration)
99101
# @param maxclients
100102
# Set the max number of connected clients at the same time.
101103
# @param maxmemory
@@ -392,6 +394,7 @@
392394
Boolean $manage_package = true,
393395
Boolean $manage_repo = false,
394396
Optional[Variant[String[1], Sensitive[String[1]], Deferred]] $masterauth = undef,
397+
Optional[Variant[String[1], Sensitive[String[1]], Deferred]] $masteruser = undef,
395398
Integer[1] $maxclients = 10000,
396399
$maxmemory = undef,
397400
Optional[Redis::MemoryPolicy] $maxmemory_policy = undef,

manifests/instance.pp

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@
7474
# @param manage_service_file
7575
# Determine if the systemd service file should be managed
7676
# @param masterauth
77-
# If the master is password protected (using the "requirepass" configuration
77+
# If the master is password protected (using the "requirepass" configuration)
78+
# @param masteruser
79+
# If the master is password protected and a user is defined (using the "user" configuration)
7880
# @param maxclients
7981
# Set the max number of connected clients at the same time.
8082
# @param maxmemory
@@ -325,6 +327,7 @@
325327
Stdlib::Filemode $log_dir_mode = $redis::log_dir_mode,
326328
Redis::LogLevel $log_level = $redis::log_level,
327329
Optional[Variant[String[1], Sensitive[String[1]], Deferred]] $masterauth = $redis::masterauth,
330+
Optional[Variant[String[1], Sensitive[String[1]], Deferred]] $masteruser = $redis::masterauth,
328331
Integer[1] $maxclients = $redis::maxclients,
329332
Optional[Variant[Integer, String]] $maxmemory = $redis::maxmemory,
330333
Optional[Redis::MemoryPolicy] $maxmemory_policy = $redis::maxmemory_policy,
@@ -526,6 +529,7 @@
526529
slaveof => $slaveof,
527530
replicaof => $replicaof,
528531
masterauth => $masterauth,
532+
masteruser => $masteruser,
529533
slave_serve_stale_data => $slave_serve_stale_data,
530534
slave_read_only => $slave_read_only,
531535
repl_announce_ip => $repl_announce_ip,

manifests/sentinel.pp

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# @param auth_pass
44
# The password to use to authenticate with the master and slaves.
55
#
6+
# @param auth_user
7+
# The username to use to authenticate with the master and slaves.
8+
#
69
# @param config_file
710
# The location and name of the sentinel config file.
811
#
@@ -147,6 +150,7 @@
147150
#
148151
class redis::sentinel (
149152
Optional[Variant[String[1], Sensitive[String[1]]]] $auth_pass = undef,
153+
Optional[Variant[String[1], Sensitive[String[1]]]] $auth_user = undef,
150154
Stdlib::Absolutepath $config_file = $redis::params::sentinel_config_file,
151155
Stdlib::Absolutepath $config_file_orig = $redis::params::sentinel_config_file_orig,
152156
Stdlib::Filemode $config_file_mode = '0644',
@@ -193,6 +197,11 @@
193197
} else {
194198
$auth_pass
195199
}
200+
$auth_user_unsensitive = if $auth_user =~ Sensitive {
201+
$auth_user.unwrap
202+
} else {
203+
$auth_user
204+
}
196205

197206
contain 'redis'
198207

spec/classes/redis_sentinel_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class { 'redis':
110110
{
111111
sentinel_tls_port: 26_380,
112112
auth_pass: 'password',
113+
auth_user: 'username',
113114
sentinel_bind: '192.0.2.10',
114115
protected_mode: false,
115116
master_name: 'cow',
@@ -151,6 +152,7 @@ class { 'redis':
151152
sentinel parallel-syncs cow 1
152153
sentinel failover-timeout cow 28000
153154
sentinel auth-pass cow password
155+
sentinel auth-user cow username
154156
sentinel notification-script cow /path/to/bar.sh
155157
sentinel client-reconfig-script cow /path/to/foo.sh
156158
@@ -177,6 +179,7 @@ class { 'redis':
177179
let(:params) do
178180
{
179181
auth_pass: 'password',
182+
auth_user: 'username',
180183
sentinel_bind: ['192.0.2.10', '192.168.1.1'],
181184
master_name: 'cow',
182185
down_after: 6000,
@@ -203,6 +206,7 @@ class { 'redis':
203206
sentinel parallel-syncs cow 1
204207
sentinel failover-timeout cow 28000
205208
sentinel auth-pass cow password
209+
sentinel auth-user cow username
206210
sentinel notification-script cow /path/to/bar.sh
207211
sentinel client-reconfig-script cow /path/to/foo.sh
208212

spec/classes/redis_spec.rb

+21
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,27 @@ class { 'redis':
523523
}
524524
end
525525

526+
describe 'with parameter masteruser ACL' do
527+
let(:params) do
528+
{
529+
masterauth: '_PASSWORD_VALUE_',
530+
masteruser: '_USERNAME_VALUE_'
531+
}
532+
end
533+
534+
it {
535+
is_expected.to contain_file(config_file_orig).with(
536+
'content' => %r{masterauth.*_PASSWORD_VALUE_}
537+
)
538+
}
539+
540+
it {
541+
is_expected.to contain_file(config_file_orig).with(
542+
'content' => %r{masteruser.*_USERNAME_VALUE_}
543+
)
544+
}
545+
end
546+
526547
describe 'with parameter maxclients' do
527548
let(:params) do
528549
{

templates/redis-sentinel.conf.erb

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ sentinel failover-timeout <%= @master_name %> <%= @failover_timeout %>
2727
<% if @auth_pass_unsensitive -%>
2828
sentinel auth-pass <%= @master_name %> <%= @auth_pass_unsensitive %>
2929
<% end -%>
30+
<% if @auth_user_unsensitive -%>
31+
sentinel auth-user <%= @master_name %> <%= @auth_user_unsensitive %>
32+
<% end -%>
3033
<% if @notification_script -%>
3134
sentinel notification-script <%= @master_name %> <%= @notification_script %>
3235
<% end -%>

templates/redis.conf.epp

+13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Optional[String[1]] $slaveof,
2424
Optional[String[1]] $replicaof,
2525
Optional[Variant[String[1], Sensitive[String[1]]]] $masterauth,
26+
Optional[Variant[String[1], Sensitive[String[1]]]] $masteruser,
2627
Boolean $slave_serve_stale_data,
2728
Boolean $slave_read_only,
2829
Optional[Stdlib::Host] $repl_announce_ip,
@@ -411,6 +412,18 @@ dir <%= $workdir %>
411412
# masterauth <master-password>
412413
<% if $masterauth { -%>masterauth <%= $masterauth %><% } -%>
413414

415+
# However this is not enough if you are using Redis ACLs (for Redis version
416+
# 6 or greater), and the default user is not capable of running the PSYNC
417+
# command and/or other commands needed for replication. In this case it's
418+
# better to configure a special user to use with replication, and specify the
419+
# username configuration as such:
420+
#
421+
# masteruser <username>
422+
<% if $masteruser { -%>masteruser <%= $masteruser %><% } -%>
423+
424+
# When masteruser is specified, the replica will authenticate against its
425+
# master using the new AUTH form: AUTH <username> <password>.
426+
414427
# When a slave loses the connection with the master, or when the replication
415428
# is still in progress, the slave can act in two different ways:
416429
#

0 commit comments

Comments
 (0)