Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Redis ACL support with username #14

Merged
merged 1 commit into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public QueueRedisProperties(ConductorProperties conductorProperties) {
/** Database number. Defaults to a 0. Can be anywhere from 0 to 15 */
private int database = 0;

/** The username to be used for connecting to redis if using Auth with ACL */
private String username = null;

/**
* The maximum amount of time to wait for a connection to become available from the connection
* pool
Expand Down Expand Up @@ -268,6 +271,14 @@ public void setDatabase(int database) {
this.database = database;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getQueuePrefix() {
String prefix = getQueueNamespacePrefix() + "." + conductorProperties.getStack();
if (getKeyspaceDomain() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,18 @@ protected JedisPool getJedisPoolStandalone(QueueRedisProperties redisProperties)
redisProperties.isSsl());
Host host = hostSupplier.getHosts().get(0);

if (host.getPassword() != null) {
if (redisProperties.getUsername() != null && host.getPassword() != null) {
log.info("Connecting to Redis Standalone with ACL user AUTH");
return new JedisPool(
config,
host.getHostName(),
host.getPort(),
Protocol.DEFAULT_TIMEOUT,
redisProperties.getUsername(),
host.getPassword(),
redisProperties.getDatabase(),
redisProperties.isSsl());
} else if (host.getPassword() != null) {
log.info("Connecting to Redis Standalone with AUTH");
return new JedisPool(
config,
Expand Down Expand Up @@ -136,7 +147,24 @@ public JedisSentinelPool getJedisPoolSentinel(QueueRedisProperties properties) {
}
// We use the password of the first sentinel host as password and sentinelPassword
String password = getPassword(hostSupplier.getHosts());
if (password != null) {
if (properties.getUsername() != null && password != null) {
return new JedisSentinelPool(
properties.getClusterName(),
sentinels,
genericObjectPoolConfig,
Protocol.DEFAULT_TIMEOUT,
Protocol.DEFAULT_TIMEOUT,
properties.getUsername(),
password,
properties.getDatabase(),
null,
Protocol.DEFAULT_TIMEOUT,
Protocol.DEFAULT_TIMEOUT,
properties.getUsername(),
password,
null);

} else if (password != null) {
return new JedisSentinelPool(
properties.getClusterName(),
sentinels,
Expand Down