Skip to content

Commit 153655b

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 153655b

File tree

6 files changed

+66
-4
lines changed

6 files changed

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

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

@@ -1953,6 +1962,7 @@ The following parameters are available in the `redis::instance` defined type:
19531962
* [`managed_by_cluster_manager`](#-redis--instance--managed_by_cluster_manager)
19541963
* [`manage_service_file`](#-redis--instance--manage_service_file)
19551964
* [`masterauth`](#-redis--instance--masterauth)
1965+
* [`masteruser`](#-redis--instance--masteruser)
19561966
* [`maxclients`](#-redis--instance--maxclients)
19571967
* [`maxmemory`](#-redis--instance--maxmemory)
19581968
* [`maxmemory_policy`](#-redis--instance--maxmemory_policy)
@@ -2305,7 +2315,15 @@ Default value: `true`
23052315

23062316
Data type: `Optional[Variant[String[1], Sensitive[String[1]], Deferred]]`
23072317

2308-
If the master is password protected (using the "requirepass" configuration
2318+
If the master is password protected (using the "requirepass" configuration)
2319+
2320+
Default value: `$redis::masterauth`
2321+
2322+
##### <a name="-redis--instance--masteruser"></a>`masteruser`
2323+
2324+
Data type: `Optional[Variant[String[1], Sensitive[String[1]], Deferred]]`
2325+
2326+
If the master is password protected and a user is defined (using the "user" configuration)
23092327

23102328
Default value: `$redis::masterauth`
23112329

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,

spec/classes/redis_spec.rb

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

526+
describe 'with parameter masteruser' do
527+
let(:params) do
528+
{
529+
masteruser: '_VALUE_'
530+
}
531+
end
532+
533+
it {
534+
is_expected.to contain_file(config_file_orig).with(
535+
'content' => %r{masteruser.*_VALUE_}
536+
)
537+
}
538+
end
539+
526540
describe 'with parameter maxclients' do
527541
let(:params) do
528542
{

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+
# masteruser 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)