Skip to content

Commit 089b08f

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 089b08f

File tree

8 files changed

+80
-4
lines changed

8 files changed

+80
-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_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)