Add 'username' auth option to Redis driver#413
Merged
tedivm merged 1 commit intotedious:mainfrom May 28, 2022
Merged
Conversation
Contributor
Author
|
Adding here the code I've used to to do the tests. Redis on port 6379 is the server without authentication. Redis on port 6380 is the server with authentication. Containers were restarted before each test to avoid problems with ACL misconfiguration. <?php
require __DIR__ . '/autoload.php';
require __DIR__ .'/vendor/autoload.php';
$driver_nopass = new Stash\Driver\Redis(
[
'servers' => [
[
'server' => '172.17.0.1',
'port' => 6379
]
]
]
);
$driver_yespass = new Stash\Driver\Redis(
[
'servers' => [
[
'server' => '172.17.0.1',
'port' => 6380
]
],
'password' => 'somepasshere',
'username' => 'someuser'
]
);
$pool_nopass = new Stash\Pool($driver_nopass);
$pool_yespass = new Stash\Pool($driver_yespass);
try {
$item = $pool_nopass->getItem('/someitem');
if($item->isHit()) {
echo "Cache hit.\n";
} else {
echo "Cache miss.\n";
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
try {
$item = $pool_yespass->getItem('/someitem');
if($item->isHit()) {
echo "Cache hit.\n";
} else {
echo "Cache miss.\n";
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
} |
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements an additional option
usernameto be used with Redis clusters that have ACL rules (Redis 6+) with non-default users.I have changed the
authmethod parameters to use associative arrays, because I thought it would be less confusing to someone reading the code. More info on parameter styles here.How I tested it:
Start a Redis container without authentication enabled.
usernameorpassword.passwordoption.Fatal error: Uncaught RedisException: ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct? in /usr/src/src/Stash/Driver/Redis.php:137(followed by a stack trace).usernameandpassword.Fatal error: Uncaught RedisException: WRONGPASS invalid username-password pair or user is disabled. in /usr/src/src/Stash/Driver/Redis.php:133(followed by a stack trace).Start a Redis container and change the authentication password for the default user.
ACL SETUSER default >somepasswordusernameorpassword.Caught exception: NOAUTH Authentication required.(I used atry-catchblock of code).passwordoption.usernameandpassword.Fatal error: Uncaught RedisException: WRONGPASS invalid username-password pair or user is disabled. in /usr/src/src/Stash/Driver/Redis.php:133(followed by a stack trace).Start a Redis container and create a new user, disabling the
defaultuser.ACL SETUSER default offACL SETUSER someuser on allkeys allcommands allchannels >somepasshereusernameorpassword.Caught exception: NOAUTH Authentication required.(I used atry-catchblock of code).passwordoption.Fatal error: Uncaught RedisException: ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct? in /usr/src/src/Stash/Driver/Redis.php:137(followed by a stack trace).usernameandpasswordoptions.Closes #412