Difficulty: Intermediate
What security feature did Redis 6 introduce with ACLs, and how would you set up users with least-privilege access for different services?
Redis 6 introduced Access Control Lists (ACLs): named users, each with its own password and a precise set of allowed commands, key patterns and Pub/Sub channels. Before ACLs there was a single shared password (requirepass) that gave every client full power, including FLUSHALL and CONFIG. With ACLs, a reporting service can be limited to reading report:* keys while only an admin user can run dangerous commands.
| Rule | Meaning |
|---|---|
on / off | Enable or disable the user |
>password | Add a password (stored as SHA-256) |
~pattern | Allow keys matching the glob, e.g. ~cache:* |
%R~pattern / %W~pattern | Read-only or write-only key access (7.0+) |
&pattern | Allow Pub/Sub channels (6.2+) |
+command / -command | Allow or deny one command |
+@category / -@category | Allow or deny a category like @read, @write, @dangerous, @admin |
nopass, resetkeys, reset | Special helpers |
Rules are applied left to right, so +@all -@dangerous means everything except dangerous commands. ACL CAT lists categories and ACL CAT dangerous shows the commands in one.
Every server has a user called default. On a fresh install it has nopass and full permissions, which is why older clients that never authenticate still work. requirepass simply sets the default user's password. In production you should either give default a strong password and restricted rights or disable it with ACL SETUSER default off, and have every service authenticate as its own user with AUTH <username> <password>.
cart: and session:, no admin commands.+@read on report:* only.queue:, publish to events:.aclfile /etc/redis/users.acl) and use ACL SAVE / ACL LOAD, or define them with user lines in redis.conf. You cannot mix both methods.ACL LOG shows recent denied commands and failed logins; it is the first place to look when a deploy suddenly gets NOPERM.ACL WHOAMI, ACL LIST and ACL GETUSER name help debug.acl-pubsub-default resetchannels), so grant &channel explicitly.Key patterns are checked against the keys a command declares. ACLs cannot restrict a user to a logical database index. Also, ACLs do not encrypt anything; use TLS (also added in Redis 6) when traffic crosses untrusted networks.
# Application user: cart and session keys, no dangerous commands
ACL SETUSER checkout on >Ch3ckout!Pass ~cart:* ~session:* +@all -@dangerous
# Read-only reporting user
ACL SETUSER analytics on >An4lytics!Pass %R~report:* +@read +@connection
# Worker: list ops on queue keys and publish to events channels
ACL SETUSER worker on >W0rker!Pass ~queue:* &events:* +@list +publish +@connection
# Lock down the default user
ACL SETUSER default off
ACL SAVE
# Test as the analytics user
AUTH analytics An4lytics!Pass
GET report:daily
SET report:daily x
ACL LOG 1
Each service gets only what it needs. The denied SET is recorded in ACL LOG with the user, command and reason. ACL SAVE requires an aclfile to be configured.
ACL, ACL SETUSER, Command categories, Key patterns, Default user