Skip to content

Redis ACLs — users, roles, and least-privilege access control

Learn how to set up Redis ACLs so every application logs in as its own user with only the commands and keys it needs. This guide covers creating those users, saving them to an aclfile, and rotating a password safely.

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. on activates the user; off disables it. The default user is default and is always present.
  • Authentication. >password adds a plaintext password; #hash adds a SHA256 password hash; nopass allows passwordless auth; resetpass removes all passwords.
  • Commands. +@read allows all read commands; +get allows the GET command; -flushall denies it. Categories are like @read, @write, @admin, @dangerous, @scripting, @pubsub, @hash, @stream. +@all -@dangerous is 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

  1. Enable an aclfile in /etc/redis/redis.conf:

    aclfile /etc/redis/users.acl

    And 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
  2. 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
  3. Create a read-only user for reporting:

    redis-cli -a "$PASS" ACL SETUSER reporter \
      on '>reportpass' \
      '~*' '+@read' '-@dangerous'
    redis-cli -a "$PASS" ACL SAVE
  4. 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
  5. 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
  6. 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"
  7. 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 default user starts with nopass and +@all on a fresh install with no requirepass. Always set default to off or to a strong password before exposing the daemon.
  • Forgetting ~pattern defaults the user to no key access, not all-keys. ~* is the explicit “any key” grant.
  • ACL changes through ACL SETUSER are in-memory only. Without ACL SAVE (or aclfile configured and saved), a restart loses the changes.
  • A grant of +@scripting allows 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-pass and sentinel auth-user for non-default ACL users. Forgetting the auth-user line means Sentinel logs in as default and 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.