This guide shows you how to set up access control lists (ACLs) in Redis, the in-memory data store many applications use for caching and sessions. It is written for anyone running a Redis server that more than one application connects to. Right now those applications probably share a single password set by requirepass, which lets any of them read every key and run FLUSHALL, the command that wipes the whole database. The fix is to give each application its own named user, allowed only the commands it calls and the keys it owns, which Redis 6 and later supports directly. By the end you will have those users saved in an aclfile so they survive a restart, a log of every denied attempt, and a one-line way to rotate a password.
How to verify
# Current users
redis-cli -a "$PASS" ACL LIST
redis-cli -a "$PASS" ACL WHOAMI
redis-cli -a "$PASS" ACL GETUSER appuser
# Category and command catalogs
redis-cli -a "$PASS" ACL CAT
redis-cli -a "$PASS" ACL CAT @write
redis-cli -a "$PASS" ACL LOG | head
# Confirm the aclfile is in use
redis-cli -a "$PASS" CONFIG GET aclfile
What’s happening
A Redis ACL is a string of grant clauses. Each clause adds or removes capabilities for a user. The clauses fall into four kinds:
- State.
onactivates the user;offdisables it. The default user isdefaultand is always present. - Authentication.
>passwordadds a plaintext password;#hashadds a SHA256 password hash;nopassallows passwordless auth;resetpassremoves all passwords. - Commands.
+@readallows all read commands;+getallows theGETcommand;-flushalldenies it. Categories are like@read,@write,@admin,@dangerous,@scripting,@pubsub,@hash,@stream.+@all -@dangerousis the common starting point. - Keys and channels.
~cache:*restricts the user to keys matching that pattern;&events.*restricts Pub/Sub channel patterns.~*and&*are unrestricted.
ACL grants are evaluated left to right — later clauses override earlier ones. +@all -@dangerous +flushdb means everything except dangerous, but flushdb is back in.
Persistence: by default ACLs live in redis.conf as user default on ... lines. The cleaner pattern is aclfile /etc/redis/users.acl — an out-of-band file ACL LOAD and ACL SAVE can sync, easier to manage with Ansible and easier to rotate without touching the main config.
The procedure
-
Enable an
aclfilein/etc/redis/redis.conf:aclfile /etc/redis/users.aclAnd create the initial file with the default user secured:
echo "user default on >$(openssl rand -hex 32) ~* &* +@all" | \ sudo tee /etc/redis/users.acl sudo chown redis:redis /etc/redis/users.acl sudo chmod 0600 /etc/redis/users.acl sudo systemctl restart redis-server -
Create an application user for a service that needs reads and writes on a key prefix:
redis-cli -a "$PASS" ACL SETUSER cartapp \ on '>cartpass' \ '~cart:*' '~session:*' \ '+@read' '+@write' '+@hash' '+@string' '+@set' \ '-flushdb' '-flushall' '-config' redis-cli -a "$PASS" ACL SAVE -
Create a read-only user for reporting:
redis-cli -a "$PASS" ACL SETUSER reporter \ on '>reportpass' \ '~*' '+@read' '-@dangerous' redis-cli -a "$PASS" ACL SAVE -
Create a backup user that needs replication-level access but nothing else:
redis-cli -a "$PASS" ACL SETUSER backup \ on '>backuppass' \ '~*' '+@admin' '+@read' \ '+bgsave' '+bgrewriteaof' '+lastsave' '+replicaof' '+sync' \ '-flushdb' '-flushall' redis-cli -a "$PASS" ACL SAVE -
Connect as the new user to test:
redis-cli --user cartapp --pass cartpass GET cart:42 redis-cli --user cartapp --pass cartpass FLUSHDB # (error) NOPERM this user has no permissions to run the 'flushdb' command -
Review the ACL log to see denied attempts — invaluable for tightening grants:
redis-cli -a "$PASS" ACL LOG # 1) "count" "1" # "reason" "command" # "context" "toplevel" # "object" "flushdb" # "username" "cartapp" -
Rotate a password without touching the rest of the user:
redis-cli -a "$PASS" ACL SETUSER cartapp resetpass '>new-cart-pass' redis-cli -a "$PASS" ACL SAVE
Common pitfalls
- The
defaultuser starts withnopassand+@allon a fresh install with norequirepass. Always setdefaulttooffor to a strong password before exposing the daemon. - Forgetting
~patterndefaults the user to no key access, not all-keys.~*is the explicit “any key” grant. - ACL changes through
ACL SETUSERare in-memory only. WithoutACL SAVE(oraclfileconfigured and saved), a restart loses the changes. - A grant of
+@scriptingallows arbitrary Lua, which can read or write any key the script touches — equivalent to bypass of key patterns. Keep scripting locked to a dedicated user. - Sentinel-managed Redis 7 supports ACLs but requires both
sentinel auth-passandsentinel auth-userfor non-default ACL users. Forgetting theauth-userline means Sentinel logs in asdefaultand confused failures follow.
In the engagements we run, every Redis instance comes up with the default user disabled, application users created via Ansible from a secrets vault, and ACL LOG shipped to Loki. We operate that under Managed Operations — and ACL rotation is on the same cycle as the rest of the credential inventory. For the TLS pairing, see Redis TLS encryption.