Create a dynamic Redis secret

Give every machine its own Redis ACL user, created when it reads the secret and deleted when its time is up.

9 steps8 min readVideo 3:13Updated

A shared Redis password lives in every app that uses it, and changing it means changing it everywhere at once. A dynamic secret replaces it with a user of its own for each machine: your Burrow creates an ACL user in Redis the moment a machine reads the secret, with only the commands and keys you allow, and deletes it when its time is up.

What you need#

  • Redis 6 or later, reachable from your Burrow, and a role in your Burrow that can write secrets.

  • An admin user in Redis that can manage users, ideally one made for your Burrow.

  • Machines with access to the environment the secret goes in. This guide uses api's prod.

Open a new dynamic secret#

Open the environment in Projects, select the + at the top right of the secrets table and choose Dynamic. The dialog has three steps: Connection, Lease & credential, and Review.

Connect to Redis#

Name the secret, such as CACHE. Machines read it as api/prod/CACHE, like any other secret. Provider starts on the first in the list; set it to Redis.

Then fill in where Redis is and how your Burrow signs in to it:

  • Host and Port: where your Burrow reaches Redis, 6379 by default. Redis has no database to name, so there's no Database field.

  • Admin user and Admin password: the user your Burrow signs in as to create and delete each machine's user. It never leaves your Burrow, and machines never see it.

Choose how the connection is protected:

Connection security

What it checks

Encrypted + verified

Encrypted, and the server's certificate must come from a trusted authority and name the host you entered. Best for a server reached over the internet.

Encrypted + trusted certificate

Encrypted, and the certificate must come from a trusted authority, but its host name isn't checked. For a server reached by an address its certificate doesn't name.

Encrypted

Encrypted, without checking the server's identity. The default; works everywhere.

None

Plaintext. Only for a server on a network you trust.

With either checking option, a CA certificate field appears. If Redis's certificate comes from your own CA, paste that CA's certificate there. A managed Redis's certificate is trusted already, so leave it empty.

Select Test connection. Your Burrow signs in with the admin user and checks it can create users. Nothing is created in Redis until a machine reads the secret. Select Continue.

A Redis server on Northwind's own CA: Encrypted + verified, with that CA pasted in.
A Redis server on Northwind's own CA: Encrypted + verified, with that CA pasted in.

Shape each password#

Every user gets its own random password. Under Password, set its length, from 8 to 64, which of A to Z, a to z, 0 to 9 and symbols it uses, and whether to leave out characters that look alike, such as 0 and O. Or choose UUID. The example shows the shape; each user's real password is made when it's issued.

Write each user's access rules#

On Redis the grants are the user's ACL rules, such as ~app:* +@read +@write. Every user can also run the connection commands, AUTH, PING and SELECT. Without any rules, a user can sign in but can't touch any key. Select Build to make them from a list:

  • Access: Read-only runs read commands, Read / write also writes, and Full adds keyspace commands such as DEL and EXPIRE, transactions and scripting.

  • Commands: tick command groups one by one instead: read, write and keyspace; data types such as hashes, lists and streams; or transactions, scripting and pub/sub. Any mix that isn't a preset is marked Custom.

  • Scope: a glob pattern for the keys a user may touch, such as app:*, and for pub/sub, the channels.

The rule shows as you choose. Use these grants puts it in the grants box. Read / write on app:* writes one rule:

text
~app:* +@read +@write

Then select Test the grants. Your Burrow creates a switched-off user with the rules and deletes it again, so a rule Redis won't take shows up now rather than when a machine reads.

Set the lease policy#

The lease policy decides how each user lives. A new secret starts with sensible defaults, so you may not need to change any of them:

Setting

What it does

Login lasts

How long each user works, from 1 minute to 10 years. 1 hour by default.

Renew on read

A machine that keeps reading keeps its user: a read late in its life extends it by another full lifetime, with the same username and password. The renew window sets how late; at 0, any read after half its life renews it. On by default.

Hard maximum

However often a user is renewed, it gets a fresh password after this long. Off by default.

Revoke when the machine is disabled

Disabling a machine deletes its user at once. On by default.

New login after it ends

The first read after a user ends gets a new password under the same username. Switched off, that read is refused. On by default.

New password on every read

Every read sets a new password, so each password is used once, and the old one stops working at once. Off by default.

Redis can't expire a user at a set time, so your Burrow deletes each user when its lease ends, which also disconnects it. That's why there's no Database expiry setting for Redis.

Review and create#

Select Continue to see everything on one page, then Create dynamic secret. The admin password and CA certificate are saved with the secret, encrypted like any other value.

Read it from a machine#

A machine reads a dynamic secret the way it reads a structured one, and gets its own user as fields: host, port, sslmode, sslrootcert when you gave a CA, username and password. The username starts with rk_ and names the machine and the secret, so you can pick it out in ACL LIST.

ratel run sets one variable per field, so CACHE gives CACHE_HOST, CACHE_USERNAME, CACHE_PASSWORD and so on:

bash
ratel run --env api/prod -- ./server

A machine keeps its user across reads until it ends, and the secret's row counts the logins out. With ratel run --watch, the command restarts when its user gets a new password; a renewal keeps the password, so it restarts nothing.

When Redis restarts#

Redis keeps its users in memory, so a Redis that restarts without them in its own configuration forgets every user your Burrow made. Each time a machine reads its login, your Burrow checks the user is still there as it was issued. If it isn't, it puts it back with the same password and rules, so the login works again from that read on, without a new password. Each time a user is put back is recorded in your audit log.

Change it later#

Choose Configure from the secret's row menu. Each tab saves on its own:

Tab

What you change

Status

Turn issuing off and on. While it's off, machine reads are refused and the row is marked off; users already out keep working until they end or are revoked.

Policy

The password and every lease setting. A change applies to users issued from then on.

Grants

The rules, with Build and Test the grants. Saving deletes the users issued with the old rules, and each machine gets a new one on its next read.

Connection

The connection and admin user, with Test connection. The admin password is never shown again; leave it empty to keep the saved one. Saving replaces the users the same way.

The connection and rules are kept as the secret's value, so Version History lists every change, and reverting to an earlier one replaces the users like any other change.

See and revoke logins#

Choose Logins from the row menu to see every user out: the machine holding it, its username, its state, and when it was issued and ends.

State

Meaning

Issuing

Being created in Redis right now.

Active

In use by its machine.

Revoking

Ended, and being deleted from Redis.

Couldn't remove

Deleting it failed. Point at the state to see why; your Burrow keeps trying.

The bin at the end of a row revokes that user now. Your Burrow deletes it from Redis, which also disconnects every session signed in as it. Its machine gets a new user on its next read.

If a user isn't issued#

Redis refused the admin login

The admin user or password is wrong. Check them on the Connection tab and select Test connection.

The admin login isn't allowed to manage users

Give the admin user +acl, or +@admin.

The rules aren't valid ACL rules

Redis didn't accept a rule as written. Check its spelling, and that command groups start with +@, key patterns with ~ and channels with &, or rebuild them with Build.

The rules can't include …

A rule sets a password or switches the user on or off, which your Burrow does itself. Remove it from the grants.

Couldn't connect to Redis

Your Burrow can't reach the host and port, or the connection security doesn't match how Redis is set up, such as Encrypted on a server without TLS. The message says which.

Every option in one place: Dynamic secrets in the documentation.

More guides

3:13

Create a dynamic MongoDB secret

Give every machine its own MongoDB user, created when it reads the secret and dropped when its time is up.

9 steps8 min readVideo 3:13
3:13

Create a dynamic PostgreSQL secret

Give every machine its own PostgreSQL login, created when it reads the secret and removed when its time is up.

9 steps8 min readVideo 3:13