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 ...Inspect and debug them live:
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 appACL LOG is worth monitoring: denials usually mean either a bug or
someone probing. redis_exporter exposes them as
redis_acl_access_denied_*_total.
Give every service its own user with only the key prefixes and
command categories it needs, the same least-privilege idea as
Postgres roles. Disable the default user (user default off) in
production once admin users exist, so a connection without a username
can't do anything at all.
Layer 3: dangerous commands
Some commands should never be run by an application:
| Command | Risk |
|---|---|
FLUSHALL, FLUSHDB | Deletes everything |
KEYS | Blocks the server on a big keyspace |
CONFIG SET | Changes dir/dbfilename (writing files to the host), disables persistence or auth |
DEBUG | Can crash or freeze the server |
MONITOR | Streams every command, including other users' data |
SHUTDOWN, REPLICAOF, FAILOVER | Availability |
MODULE LOAD | Runs 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 busTLS adds CPU cost for encryption and the handshake. Use connection pooling so the handshake isn't paid per request.
Checklist
- Not reachable from the internet; firewalled to its clients.
- ACL users per service, least privilege;
defaultdisabled. @dangerousand@admindenied to applications.- TLS on untrusted networks, including replication and the cluster bus.
- Secrets out of the repo. ACL files can't read environment variables, so generate them at deploy time from a secret store.
- Run as a non-root user (the official image does) with a data directory only Redis can write.
Lab
- As
app, tryFLUSHALL,KEYS *, andGET other:key. Read each error, then readACL LOGasdefault. ACL DRYRUN readonly SET app:x 1. What's the answer?- Create a user at runtime that can only
GETkeys undercache::ACL SETUSER cachereader on >pw ~cache:* +get. Test it, thenACL DELUSER cachereader. - Look at
ACL CAT dangerousand pick three commands from it you'd be most worried about an app having.