Commit 38bc4c0
committed
bug symfony#65636 [Cache] Fix authenticating to the master when using Redis Sentinel (nicolas-grekas)
This PR was merged into the 6.4 branch.
Discussion
----------
[Cache] Fix authenticating to the master when using Redis Sentinel
| Q | A
| ------------- | ---
| Branch? | 6.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | -
| License | MIT
A Sentinel DSN opens two connections: one to the Sentinel process, to ask for the current master, and one to that master, to run the commands. They can require different credentials, and many setups leave the Sentinel unauthenticated while the master requires a password.
`RedisTrait` resolves credentials into `$params['auth']`, which symfony#63324 leaves empty in Sentinel mode on purpose, so that the DSN userinfo is not sent to the Sentinel. symfony#65421 then made two code paths read `$params['auth']` where they used to read the userinfo: the Predis branch, and the `$redis->auth()` call used with phpredis below 6. In Sentinel mode both now got nothing, so the master connection was made without credentials:
```php
RedisAdapter::createConnection('redis://:p4ssw0rd@127.0.0.1:26379?redis_sentinel=mymaster');
// Redis connection failed: NOAUTH Authentication required.
```
This patch takes the resolution that 7.4 already has since symfony#63391: the userinfo authenticates the master, the `auth` query parameter or option authenticates the Sentinel handshake, and each is applied to its own connection. For Predis, the Sentinel credentials are applied to the Sentinel hosts, as they are on 7.4.
```php
// master gets "master-pass", the Sentinel handshake gets no credentials
RedisAdapter::createConnection('redis://:master-pass@127.0.0.1:26379?redis_sentinel=mymaster');
// master gets "master-pass", the Sentinel handshake gets "sentinel-pass"
RedisAdapter::createConnection('redis://:master-pass@127.0.0.1:26379?redis_sentinel=mymaster&auth=sentinel-pass');
// no userinfo: both get "shared-pass", as before
RedisAdapter::createConnection('redis://127.0.0.1:26379?redis_sentinel=mymaster&auth=shared-pass');
```
The tests come from symfony#63391, with the same names, so the merge-up into 7.4 resolves by keeping the 7.4 version. They cover the resolution for the master and for the Sentinel, from the userinfo, from the query string and from the options.
While doing that, the `auth` shape check added in symfony#65421 was chained with `elseif` to the check that reports missing Sentinel support. That made `Redis Sentinel support requires one of: ...` reachable for any DSN, not only Sentinel ones, when neither predis, `RedisSentinel` nor `Relay\Sentinel` exists. Both checks now stand on their own, as they do on 7.4. The shape check also covers the Sentinel credentials now.
Checks run: the new tests fail on 6.4 for the five Sentinel cases and pass with the patch; `./phpunit src/Symfony/Component/Cache` reports the same failures with and without the patch on my machine; php-cs-fixer is clean. The fix was also verified end to end against a local master with `requirepass` and an unauthenticated Sentinel, with ext-redis 6.3 and with Predis: `NOAUTH Authentication required` before, `PONG` after. The phpredis below 6 path is fixed by the same change but was not run, since that version is not installed here.
Commits
-------
c365648 [Cache] Fix authenticating to the master when using Redis Sentinel2 files changed
+187-8Lines changed: 187 additions & 8 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- src/Symfony/Component/Cache
- Tests/Traits
- Traits
Expand file treeCollapse file tree
Open diff view settings
Collapse file
src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php
Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php+155Lines changed: 155 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
210 | 210 | |
211 | 211 | |
212 | 212 | |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | + |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | + |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | + |
| 235 | + |
| 236 | + |
| 237 | + |
| 238 | + |
| 239 | + |
| 240 | + |
| 241 | + |
| 242 | + |
| 243 | + |
| 244 | + |
| 245 | + |
| 246 | + |
| 247 | + |
| 248 | + |
| 249 | + |
| 250 | + |
| 251 | + |
| 252 | + |
| 253 | + |
| 254 | + |
| 255 | + |
| 256 | + |
| 257 | + |
| 258 | + |
| 259 | + |
| 260 | + |
| 261 | + |
| 262 | + |
| 263 | + |
| 264 | + |
| 265 | + |
| 266 | + |
| 267 | + |
| 268 | + |
| 269 | + |
| 270 | + |
| 271 | + |
| 272 | + |
| 273 | + |
| 274 | + |
| 275 | + |
| 276 | + |
| 277 | + |
| 278 | + |
| 279 | + |
| 280 | + |
| 281 | + |
| 282 | + |
| 283 | + |
| 284 | + |
| 285 | + |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | + |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | + |
| 294 | + |
| 295 | + |
| 296 | + |
| 297 | + |
| 298 | + |
| 299 | + |
| 300 | + |
| 301 | + |
| 302 | + |
| 303 | + |
| 304 | + |
| 305 | + |
| 306 | + |
| 307 | + |
| 308 | + |
| 309 | + |
| 310 | + |
| 311 | + |
| 312 | + |
| 313 | + |
| 314 | + |
| 315 | + |
| 316 | + |
| 317 | + |
| 318 | + |
| 319 | + |
| 320 | + |
| 321 | + |
| 322 | + |
| 323 | + |
| 324 | + |
| 325 | + |
| 326 | + |
| 327 | + |
| 328 | + |
| 329 | + |
| 330 | + |
| 331 | + |
| 332 | + |
| 333 | + |
| 334 | + |
| 335 | + |
| 336 | + |
| 337 | + |
| 338 | + |
| 339 | + |
| 340 | + |
| 341 | + |
| 342 | + |
| 343 | + |
| 344 | + |
| 345 | + |
| 346 | + |
| 347 | + |
| 348 | + |
| 349 | + |
| 350 | + |
| 351 | + |
| 352 | + |
| 353 | + |
| 354 | + |
| 355 | + |
| 356 | + |
| 357 | + |
| 358 | + |
| 359 | + |
| 360 | + |
| 361 | + |
| 362 | + |
| 363 | + |
| 364 | + |
| 365 | + |
| 366 | + |
| 367 | + |
213 | 368 | |
Collapse file
src/Symfony/Component/Cache/Traits/RedisTrait.php
Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/RedisTrait.php+32-8Lines changed: 32 additions & 8 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
194 | 194 | |
195 | 195 | |
196 | 196 | |
197 | | - |
198 | | - |
199 | | - |
200 | | - |
| 197 | + |
201 | 198 | |
202 | 199 | |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | + |
203 | 209 | |
204 | 210 | |
205 | 211 | |
| ||
234 | 240 | |
235 | 241 | |
236 | 242 | |
237 | | - |
| 243 | + |
238 | 244 | |
239 | 245 | |
240 | 246 | |
241 | 247 | |
242 | 248 | |
243 | 249 | |
244 | | - |
| 250 | + |
245 | 251 | |
246 | 252 | |
247 | 253 | |
| ||
264 | 270 | |
265 | 271 | |
266 | 272 | |
267 | | - |
| 273 | + |
268 | 274 | |
269 | 275 | |
270 | 276 | |
| ||
273 | 279 | |
274 | 280 | |
275 | 281 | |
276 | | - |
| 282 | + |
277 | 283 | |
278 | 284 | |
279 | 285 | |
| ||
405 | 411 | |
406 | 412 | |
407 | 413 | |
| 414 | + |
| 415 | + |
| 416 | + |
| 417 | + |
| 418 | + |
| 419 | + |
| 420 | + |
| 421 | + |
| 422 | + |
| 423 | + |
| 424 | + |
| 425 | + |
| 426 | + |
| 427 | + |
| 428 | + |
| 429 | + |
| 430 | + |
| 431 | + |
408 | 432 | |
409 | 433 | |
410 | 434 | |
|
0 commit comments