Skip to main content
The AWS ElastiCache dynamic secret creates a user on your ElastiCache cluster each time someone creates a lease, and deletes the user when the lease ends. Use it to give an application or a person their own short-lived username and password for the cluster, instead of sharing one long-lived password. To learn how leases work across providers, see Dynamic secrets.

Prerequisites

  • An ElastiCache cluster running Redis OSS 6.0 or later, with encryption in transit turned on and set to Required
  • A cluster that doesn’t already use a user group of your own (see Cluster access controls)
  • A role in the Infisical project that lets you create dynamic secrets

Cluster access controls

ElastiCache uses user groups to decide who can log in to a cluster. Infisical creates a user group for each cluster, named infisical- followed by a hash of the cluster name, and attaches the group to the cluster:
  • Each lease adds a user to its own cluster’s group, so the lease works only on that cluster
  • The cluster refuses clients that connect without a username and password
  • A cluster can use only one user group, so Infisical can’t use a cluster that already has a user group of your own

Step 1: Create an IAM user for Infisical

Infisical uses an AWS IAM user to create the cluster’s user group and the users for each lease.
1
In AWS, create an IAM user with the following policy. Replace <region> and <account-id> with the region and AWS account ID of your cluster.
2
Create an access key for the IAM user, and copy the access key ID and the secret access key.

Step 2: Create the dynamic secret

1
In your project, go to the environment and folder where you want the dynamic secret, then select Add New > Add Dynamic Secret.
2
Select AWS ElastiCache.
3
Fill in the form:
string
required
The name you use to refer to the dynamic secret.
string
required
How long a lease lasts if the person creating it doesn’t choose a TTL (for example, 1h).
string
The longest TTL anyone can request for a lease (for example, 24h).
string
required
The name of the ElastiCache cluster, as shown in the ElastiCache console.
string
required
The AWS region of the cluster (for example, us-east-1).
string
required
The access key ID of the IAM user from Step 1.
string
required
The secret access key of the IAM user from Step 1.
4
(Optional) Expand Modify ElastiCache Statements to change how Infisical creates each user:
string
default:"{{randomUsername}}"
Specifies a template for generating usernames. This field allows customization of how usernames are automatically created.Allowed template variables are:
  • {{randomUsername}}: Random username string.
  • {{unixTimestamp}}: Current Unix timestamp at the time of lease creation.
  • {{identity.name}}: Name of the identity that is generating the lease.
  • {{dynamicSecret.name}}: Name of the associated dynamic secret.
  • {{dynamicSecret.type}}: Type of the associated dynamic secret.
  • {{random N}}: Random string of N characters.
Allowed template functions are:
  • truncate: Truncates a string to a specified length.
  • replace: Replaces a substring with another value.
  • uppercase: Converts a string to uppercase.
  • lowercase: Converts a string to lowercase.
Examples:
string
The settings Infisical sends to AWS to create each user. To limit what a lease can do on the cluster, change AccessString (for example, on ~app:* +@read allows read commands on keys that start with app:).
string
The settings Infisical sends to AWS to delete each user.
5
Select Submit.Infisical checks that the IAM user can reach the cluster, then creates the cluster’s user group. ElastiCache takes up to a minute to finish creating the group.

Step 3: Create a lease

1
In the row for the dynamic secret, select Generate Lease.
2
Enter a Default TTL for the lease, then select Provision Lease.
3
Copy the DB_USERNAME and DB_PASSWORD values that Infisical shows.
ElastiCache takes about a minute to add a new user to the cluster. Until then, a login with the new password fails, so make your application retry the connection.

Revoke or renew a lease

Select the dynamic secret to see its leases:
  • Select Revoke lease to delete the lease’s user from the cluster before the lease expires
  • Select Renew lease to extend the lease, up to the Max TTL of the dynamic secret
When a lease expires, Infisical deletes its user from the cluster.

Clusters set up by earlier versions of Infisical

Earlier versions of Infisical attached one shared user group, infisical-managed-group-elasticache, to every cluster. If your cluster still uses that group, Infisical keeps using it for new leases, so your existing leases keep working. To give the cluster its own user group, with the cluster access controls:
1
Remove the shared user group from the cluster. Existing leases for the cluster stop working.
2
Create a lease. Infisical creates the cluster’s own user group and asks you to try again in a minute.
3
Create the lease again. Infisical attaches the cluster’s user group to the cluster.
4
Revoke the cluster’s old leases, then create new leases for the applications that used them.
When no cluster uses infisical-managed-group-elasticache anymore, you can delete the group in the ElastiCache console.

Troubleshooting

ElastiCache takes about a minute to create a cluster’s user group, and about a minute to add each new lease’s user. Wait a minute, then create the lease again.
A cluster can use only one user group, and Infisical needs its own group to create leases. Remove your user group from the cluster, or use a different cluster.
The cluster refuses clients that connect without a username and password. Configure the application to log in with the DB_USERNAME and DB_PASSWORD of a lease.