Learn Labs
Operations

Security

ACL users, protected mode, TLS, and dangerous commands

Redis was designed for trusted networks, and its defaults show it: no password, every command available, plaintext traffic. An exposed, unauthenticated Redis is one of the most commonly exploited services on the internet. Attackers use CONFIG SET dir and SAVE to write files (SSH keys, cron jobs) onto the host, or simply delete or ransom the data.

Layer 1: the network

  • Never expose Redis to the internet. Bind it to private interfaces and firewall port 6379 to the app servers that need it.
  • Protected mode (on by default) refuses connections from non-loopback addresses when no password is configured, a safety net against the worst misconfiguration.
  • In this repo, port 6379 is published to your machine for convenience. On a server, you'd leave it unpublished and let only containers on the same network connect.

Layer 2: ACL users

Since Redis 6, ACLs define users, each with a password, the commands they can run, and the keys and Pub/Sub channels they can touch. This repo's config/users.acl:

user default on >redis123 ~* &* +@all
user app on >app123 ~app:* ~cache:* ~session:* ~rate:* ~lock:* ~lb:* ~stream:* &* +@all -@admin -@dangerous
user readonly on >readonly123 ~* &* +@read +@connection
user exporter on >exporter123 ~* &* -@all +@connection +info +config|get ...
on / offenabled or disabled>passwordadd a password (stored hashed; #<sha256> works too)~patternkeys the user may access (%R~ / %W~ for read-only / write-only)&patternPub/Sub channels+@category / -@categoryallow / deny a command category (@read, @write, @admin, @dangerous, ...)+command / -commanda single command; +config|get allows one subcommand

Inspect and debug them live:

ACL WHOAMIwho am I connected asACL LISTevery user, passwords shown as hashesACL CAT dangerouscommands in a category: FLUSHALL, KEYS, MONITOR, CONFIG, DEBUG, ...ACL DRYRUN app FLUSHALLwould this user be allowed to run this?ACL LOGrecent denials: who, which command or key, whenACL SAVE / ACL LOADwrite runtime changes to / reload from the aclfile
docker exec redis redis-cli --user app --pass app123 FLUSHALL
(error) NOPERM User app has no permissions to run the 'flushall' command

docker exec redis redis-cli --user default --pass redis123 ACL LOG 1
reason   command
object   flushall
username app

ACL LOG is worth monitoring: denials usually mean either a bug or someone probing. redis_exporter exposes them as redis_acl_access_denied_*_total.

Layer 3: dangerous commands

Some commands should never be run by an application:

CommandRisk
FLUSHALL, FLUSHDBDeletes everything
KEYSBlocks the server on a big keyspace
CONFIG SETChanges dir/dbfilename (writing files to the host), disables persistence or auth
DEBUGCan crash or freeze the server
MONITORStreams every command, including other users' data
SHUTDOWN, REPLICAOF, FAILOVERAvailability
MODULE LOADRuns arbitrary native code

ACL categories (-@dangerous, -@admin) are the modern way to block them per user. Older setups used rename-command FLUSHALL "" in the config, which removes the command for everyone, including admins. Redis 7 also adds enable-protected-configs, enable-debug-command, and enable-module-command, which default to no, blocking those operations from non-local connections even for admin users.

Layer 4: TLS

Without TLS, passwords and data cross the network in plaintext. Redis supports TLS natively:

port 0                                 # disable the plaintext port
tls-port 6379
tls-cert-file /tls/redis.crt
tls-key-file /tls/redis.key
tls-ca-cert-file /tls/ca.crt
tls-auth-clients optional              # 'yes' requires client certificates (mutual TLS)
tls-replication yes                    # encrypt primary -> replica traffic
tls-cluster yes                        # encrypt the cluster bus

TLS adds CPU cost for encryption and the handshake. Use connection pooling so the handshake isn't paid per request.

Checklist

  1. Not reachable from the internet; firewalled to its clients.
  2. ACL users per service, least privilege; default disabled.
  3. @dangerous and @admin denied to applications.
  4. TLS on untrusted networks, including replication and the cluster bus.
  5. Secrets out of the repo. ACL files can't read environment variables, so generate them at deploy time from a secret store.
  6. Run as a non-root user (the official image does) with a data directory only Redis can write.

Lab

  1. As app, try FLUSHALL, KEYS *, and GET other:key. Read each error, then read ACL LOG as default.
  2. ACL DRYRUN readonly SET app:x 1. What's the answer?
  3. Create a user at runtime that can only GET keys under cache:: ACL SETUSER cachereader on >pw ~cache:* +get. Test it, then ACL DELUSER cachereader.
  4. Look at ACL CAT dangerous and pick three commands from it you'd be most worried about an app having.

On this page