Skip to content

Configure Dynamic Password

Valkey GLIDE introduces the ability to dynamically update the connection-configured password at runtime. This enhancement facilitates seamless password rotations, ensuring uninterrupted access and improved security for your applications.

Below are examples demonstrating how to utilize the dynamic password update feature in different programming languages using GLIDE.

import com.valkey.glide.GlideClusterClient;
import com.valkey.glide.GlideClusterClientConfiguration;
import com.valkey.glide.ServerCredentials;
import com.valkey.glide.NodeAddress;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
// Define the list of node addresses
List<NodeAddress> nodeList = Arrays.asList(
new NodeAddress("localhost", 6379),
new NodeAddress("localhost", 6380),
new NodeAddress("localhost", 6381)
);
// Define your server credentials
ServerCredentials credentials = ServerCredentials.builder()
.username("your-username")
.password("your-password-or-token")
.build();
// Create a configuration for the GlideClusterClient
GlideClusterClientConfiguration config = new GlideClusterClientConfiguration.Builder()
.addresses(nodeList)
.credentials(credentials)
.requestTimeout(5000)
.clientName("my-client")
.build();
// Create the GlideClusterClient instance
GlideClusterClient client = GlideClusterClient.createClient(config);
// Update password dynamically
client.updateConnectionPassword("your-new-password");
// To perform immediate re-authentication, set the second parameter to true
client.updateConnectionPassword("your-new-password", true);
// Resetting password by passing null
client.updateConnectionPassword(null); // Note: This will clear the password from the connection configuration.
System.out.println("GlideClusterClient created and password updated.");
}
}

In scenarios where a username is not required (e.g., IAM authentication), you can omit it or set it to null.

ServerCredentials credentials = ServerCredentials.builder()
.password("your-password-or-token")
.build();

For most scenarios, you can update the password without immediate re-authentication. However, for cases like IAM authentication where tokens need to be refreshed periodically (e.g., every 12 hours), you can utilize the immediateAuth/immediate_auth option to re-authenticate immediately.

GLIDE’s dynamic password update feature supports integration with cloud services like Amazon ElastiCache, MemoryDB, and Google Cloud Memorystore.

  • AWS ElastiCache: Supports password-based and IAM authentication. AWS recommends regular password rotations.
  • Amazon MemoryDB: Uses IAM authentication with short-lived tokens that need regular renewal.
  • Google Cloud Memorystore: Offers IAM authentication with ephemeral tokens requiring periodic renewal.

In all these scenarios, frequently updating passwords or tokens is essential to maintain secure connections and handle fail-overs effectively.

  • Regular Credential Rotation: Frequently update passwords and tokens using the dynamic password update feature to maintain secure connections.
  • Automate Token Refreshing: Implement automated mechanisms to refresh IAM tokens before they expire.
  • Secure Credential Storage: Store passwords and tokens securely using environment variables or secret management tools.
  • Principle of Least Privilege: Use ACLs to assign minimal necessary permissions to users.
  • Monitor Authentication Events: Track authentication attempts and token renewals to detect and respond to potential security threats promptly.