Skip to content

Commit c200716

Browse files
Merge branch '5.x-dev' into resolve-aikido-12726180
2 parents 0fd3335 + 1fbdad6 commit c200716

10 files changed

Lines changed: 43 additions & 1 deletion

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Changelog
22

33
5.1.3 - 2025-09-01
4+
- Add support for Sentinel password
45
- Security hardening
56

67
5.1.2 - 2025-07-07

Queue/Backend/Sentinel.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class Sentinel extends Redis
2222
{
2323
private $masterName = '';
2424

25+
/*
26+
* @var bool
27+
*/
28+
private $usePasswordForSentinelInstances = false;
29+
2530
protected function connect()
2631
{
2732
$hosts = explode(',', $this->host);
@@ -36,6 +41,9 @@ protected function connect()
3641
$configuredClient = new \Credis_Client($host, $ports[$index], $timeout = 0.5, $persistent = false);
3742
$configuredClient->forceStandalone();
3843
$configuredClient->connect();
44+
if ($this->usePasswordForSentinelInstances && !empty($this->password)) {
45+
$configuredClient->auth($this->password);
46+
}
3947
$configuredSentinel = new \Credis_Sentinel($configuredClient);
4048
$master = $configuredSentinel->getMasterAddressByName($this->masterName);
4149

@@ -64,6 +72,11 @@ public function setSentinelMasterName($name)
6472
$this->masterName = $name;
6573
}
6674

75+
public function setUsePasswordForSentinelInstances(bool $usePasswordForSentinelInstances)
76+
{
77+
$this->usePasswordForSentinelInstances = $usePasswordForSentinelInstances;
78+
}
79+
6780
protected function evalScript($script, $keys, $args)
6881
{
6982
return $this->redis->eval($script, $keys, $args);

Queue/Factory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public static function makeBackendFromSettings(SystemSettings $settings)
7272
$redis = new Queue\Backend\Sentinel();
7373
$redis->setSentinelMasterName($masterName);
7474
$redis->setDatabase($database);
75+
if (!empty($settings->getUsePasswordForSentinelInstances())) {
76+
$redis->setUsePasswordForSentinelInstances(true);
77+
}
7578
}
7679
} elseif ($settings->isUsingClusterBackend()) {
7780
$redis = new Queue\Backend\RedisCluster();

SystemSettings.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
6060
/** @var Setting */
6161
public $sentinelMasterName;
6262

63+
/** @var Setting */
64+
public $usePasswordForSentinelInstances;
65+
6366
public function getAvailableRedisBackendTypes()
6467
{
6568
return array(
@@ -83,6 +86,7 @@ protected function init()
8386
$this->backend = $this->createBackendSetting();
8487
$this->useWhatRedisBackendType = $this->createUseWhatRedisBackendType();
8588
$this->sentinelMasterName = $this->createSetSentinelMasterName();
89+
$this->usePasswordForSentinelInstances = $this->createUsePasswordForSentinelInstances();
8690
$this->redisHost = $this->createRedisHostSetting();
8791
$this->redisPort = $this->createRedisPortSetting();
8892
$this->redisTimeout = $this->createRedisTimeoutSetting();
@@ -114,6 +118,11 @@ public function getSentinelMasterName()
114118
return $this->sentinelMasterName->getValue();
115119
}
116120

121+
public function getUsePasswordForSentinelInstances()
122+
{
123+
return $this->usePasswordForSentinelInstances->getValue();
124+
}
125+
117126
public function isUsingUnixSocket()
118127
{
119128
return substr($this->redisHost->getValue(), 0, 1) === '/';
@@ -373,6 +382,16 @@ private function createSetSentinelMasterName()
373382
});
374383
}
375384

385+
private function createUsePasswordForSentinelInstances()
386+
{
387+
return $this->makeSetting('usePasswordForSentinelInstances', $default = false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
388+
$field->title = Piwik::translate('QueuedTracking_UsePasswordForSentinelsTitle');
389+
$field->condition = 'backend=="redis"';
390+
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
391+
$field->inlineHelp = Piwik::translate('QueuedTracking_UsePasswordForSentinelsHelp', ['</br></br>']) . '</br>';
392+
});
393+
}
394+
376395
public function checkMatchHostsAndPorts()
377396
{
378397
$hosts = $this->redisHost->getValue();

lang/el.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"RedisPortFieldTitle": "Θύρα Redis",
3232
"RedisTimeoutFieldHelp": "Ο χρόνος λήξης απόκρισης του Redis σε δευτερόλεπτα. Το \"0.0\" σημαίνει χωρίς όριο. Μπορεί να είναι δεκαδικός αριθμός, πχ \"2.5\" για χρόνο λήξης απόκρισης 2.5 δευτερόλεπτα.",
3333
"RedisTimeoutFieldTitle": "Χρόνος λήξης απόκρισης του Redis",
34+
"UsePasswordForSentinelsHelp": "Σχετικό μόνο αν το Sentinel είναι ενεργό. %1$sΑν είναι ενεργό, το συνθηματικό του Redis θα χρησιμοποιείται επίσης κατά την αυθεντικοποίηση με τα στιγμιότυπα του Sentinel για να γίνει λήψη των πληροφοριών κύριας σύνδεσης. Εναλλακτικά, το συνθηματικό χρησιμοποιείται μόνο κατά την αυθεντικοποίηση με τον κύριο Redis.",
35+
"UsePasswordForSentinelsTitle": "Χρήση του συνθηματικού με το Redis Sentinels",
3436
"UseSentinelFieldHelp": "Αν είναι ενεργό, θα χρησιμοποιηθεί το χαρακτηριστικό Redis Sentinel. Βεβαιωθείτε να ενημερώσετε το όνομα διακομιστή και τη θύρα αν απαιτηθεί. Από τη στιγμή που θα το ενεργοποιήσετε και αποθηκεύσετε την αλλαγή, θα μπορείτε να καθορίζετε πολλαπλούς διακομιστές και θύρες χωρισμένα με κόμμα.",
3537
"UseSentinelFieldTitle": "Ενεργοποίηση του Redis Sentinel",
3638
"WhatRedisBackEndType": "Επιλέξτε ποιο τύπο redis θα χρησιμοποιήσετε. Βεβαιωθείτε να ενημερώσετε το διακομιστή και θύρα αν χρειάζεται. Αφού έχετε κάνει και αποθηκεύσει την αλλαγή, θα μπορείτε να καθορίσετε πολλαπλούς διακομιστές και θύρες με λίστες και χρήση του κόμματος ως διαχωριστή μόνο για τους τύπους \"Sentinel\" και \"Cluster\"."

lang/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
"MasterNameFieldTitle": "Redis Sentinel Master name",
3434
"MasterNameFieldHelp": "The sentinel master name only needs to be configured if Sentinel is enabled.",
3535
"NumHostsNotMatchNumPorts": "The number of configured hosts doesn't match the number of configured ports.",
36-
"MultipleServersOnlyConfigurableIfSentinelEnabled": "Multiple hosts or ports can be only configured when Redis Sentinel is on. The plugin README will tell you how to do so."
36+
"MultipleServersOnlyConfigurableIfSentinelEnabled": "Multiple hosts or ports can be only configured when Redis Sentinel is on. The plugin README will tell you how to do so.",
37+
"UsePasswordForSentinelsTitle": "Use password with Redis Sentinels",
38+
"UsePasswordForSentinelsHelp": "Only relevant if Sentinel is enabled.%1$sIf enabled, the Redis password will also be used when authenticating with Sentinel instances to obtain the master connection information. Otherwise, the password is only used to authenticate with the Redis master."
3739
}
3840
}

lang/ga.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"RedisPortFieldTitle": "Redis port",
3232
"RedisTimeoutFieldHelp": "Redis am istigh ceangail i soicindí. Ciallaíonn “0.0” gan teorainn. Is féidir leis a bheith ina snámhán m.sh. “2.5” le haghaidh teorainn ama ceangail 2.5 soicind.",
3333
"RedisTimeoutFieldTitle": "Teorainn ama Redis",
34+
"UsePasswordForSentinelsHelp": "Ní bhaineann sé seo ach amháin má tá Sentinel cumasaithe.%1$sMá tá sé cumasaithe, úsáidfear an focal faire Redis freisin agus fíordheimhniú á dhéanamh le cásanna Sentinel chun an fhaisnéis nasc máistir a fháil. Seachas sin, ní úsáidtear an focal faire ach chun fíordheimhniú a dhéanamh leis an máistir Redis.",
35+
"UsePasswordForSentinelsTitle": "Úsáid pasfhocal le Redis Sentinels",
3436
"UseSentinelFieldHelp": "Má tá sé cumasaithe, úsáidfear an ghné Redis Sentinel. Déan cinnte an t-óstach agus an port a nuashonrú más gá. Nuair a bheidh an t-athrú cumasaithe agus sábháilte agat, beidh tú in ann óstach iolrach agus port scartha le camóga a shonrú.",
3537
"UseSentinelFieldTitle": "Cumasaigh Redis Sentinel",
3638
"WhatRedisBackEndType": "Roghnaigh cén cineál redis a úsáidfear. Déan cinnte an t-óstach agus an port a nuashonrú más gá. Nuair a bheidh an t-athrú roghnaithe agus sábháilte agat, beidh tú in ann óstaigh agus poirt iolracha a shonrú ag baint úsáide as liostaí scartha le camóg don chineál “Sentinel” agus “Cnuasach” amháin."
24.6 KB
Loading
24.4 KB
Loading
24.1 KB
Loading

0 commit comments

Comments
 (0)