11. Security
Redis was designed to run inside a trusted network, so a fresh server answers anyone who can reach its port and lets them read, delete or replace every key, rewrite its configuration and, on older versions, write files to disk. This chapter covers the layers that close those doors: protected mode, passwords, ACL users with command, key and channel permissions, TLS, network binding and firewalls, the safeguards around dangerous commands and Lua scripts, and the misconfigurations that real attacks against Redis have exploited.
All examples in this chapter were run against Redis Open Source 8.10.3 (the official redis:8.10 Docker image, with Redis 7.2 for comparisons) and redis-py 8.1.0. Measurements were taken on a 12-core development machine with client and server in containers on the same Docker network. Treat them as orders of magnitude, not as benchmarks for your hardware.
<a id="111-access-control"></a>
11.1 Access Control
Access control decides who may connect and what each connection may do. This subchapter goes from the coarsest mechanism (protected mode) to the finest (per-user rules on commands, keys and Pub/Sub channels).
Protected Mode
Before Redis 3.2, a server started with default settings listened on every network interface and required no password. Anyone who installed Redis on a cloud VM with a public IP had, without knowing it, published a database that accepts any command from anyone. Scanners found these servers within hours, and many were wiped or used to plant SSH keys. Protected mode was added in 3.2 as a safety net for this case: an "unsafe by accident" configuration that the operator never chose on purpose.
The rule
Protected mode is like a front door that locks itself when nobody has set a key. When protected-mode is yes and the default user has no password, the server accepts connections only from the loopback addresses (127.0.0.1, ::1) and from Unix sockets. Every other client receives a DENIED error and is disconnected. Setting a password for the default user, or turning protected mode off, removes the restriction.
protected-mode yes?
│no │yes
▼ ▼
accept default user has a password?
│yes │no
▼ ▼
accept client is loopback / Unix socket?
│yes │no
▼ ▼
accept -DENIED, disconnect
The bind setting does not change the rule. In both Redis 7.2 and 8.10, a server started with --protected-mode yes --bind 0.0.0.0 still refused a client on another container with DENIED.
Seeing it in action
# Server with protected mode on and no password (the source-code default)
docker run -d --name r-pm --network demo redis:8.10 redis-server --protected-mode yes
# From another container on the same network
docker run --rm --network demo redis:8.10 redis-cli -h r-pm PING
# DENIED Redis is running in protected mode because protected mode is enabled and no
# password is set for the default user. In this mode connections are only accepted from
# the loopback interface. ...
# From inside the server's own container (loopback): allowed
docker exec r-pm redis-cli PING
# PONG
# After a password is set, remote clients are no longer denied, but must authenticate
docker exec r-pm redis-cli CONFIG SET requirepass 's3cret-pass'
docker run --rm --network demo redis:8.10 redis-cli -h r-pm PING
# NOAUTH Authentication required.
Where protected mode is not active
Protected mode is on by default in the Redis source code and in the sample redis.conf, but several popular ways of running Redis turn it off:
| How Redis is started | protected-mode | bind | Reachable without password from other hosts? |
|---|---|---|---|
redis-server (no config file), built from source | yes | all interfaces | No (DENIED) |
Sample redis.conf / distribution packages | yes | 127.0.0.1 -::1 | No (not even listening) |
Official Docker image redis:8.10 | no | * -::* | Yes |
Explicit --protected-mode no | no | as configured | Yes, if bound to a reachable interface |
The official Docker image disables protected mode because a container is reached through Docker's network, never through loopback, so a protected server would refuse every client. This was confirmed with CONFIG GET protected-mode on a plain docker run redis:8.10, which returned no while a client in another container ran PING without any credentials. Combined with docker run -p 6379:6379, which publishes the port on all host interfaces, this is one of the most common ways Redis ends up open on the internet.
When the server starts without authentication and without protected mode, it logs a warning that is easy to miss:
# WARNING: Redis does not require authentication and is not protected by network
# restrictions. Redis will accept connections from any IP address on any network interface.
Protected mode is a safety net, not access control. It does nothing once any password is set, it cannot tell a trusted remote client from an attacker, and it is often disabled. Real deployments need authentication (next topics) and network restrictions (11.2).
Key Takeaways
- Protected mode refuses non-loopback clients only when it is on and the default user has no password.
- It does not depend on
bindin current versions. A password, orprotected-mode no, disables the restriction. - The official Docker image runs with
protected-mode noand listens on all interfaces, so publish its port carefully. - Watch for the startup warning about missing authentication, and treat protected mode as a last line of defense, not the first.
Practice
- (Beginner) Start
redis:8.10with--protected-mode yeson a Docker network, connect from a second container, and read theDENIEDmessage. Then fix it in two different ways (a password, thenCONFIG SET protected-mode nofrom inside the container) and note which one you would use in production and why.- (Intermediate) Run
docker run -d -p 6379:6379 redis:8.10on a test VM and check from another machine whether you can connect. Then change the command so the port is reachable only from the VM itself, and verify again.- (Interview) "Redis has had protected mode since 3.2, yet tens of thousands of unauthenticated instances are still reachable from the internet. How can that be?" Hint: think about container images, configuration management templates, and what an operator does when they see the
DENIEDmessage.
Password Authentication
The simplest way to stop strangers from using a server is to ask for a secret. Redis has done this since its early versions with the requirepass directive: a single shared password, like one key that every resident of a building uses. Since Redis 6, this mechanism sits on top of the ACL system: requirepass simply sets the password of the built-in user called default.
Setting and using a password
# redis.conf
requirepass "Tr0ub4dor&3" # example only: use a long random password (see below)
redis-cli GET x
# NOAUTH Authentication required.
redis-cli --no-auth-warning -a wrong GET x
# AUTH failed: WRONGPASS invalid username-password pair or user is disabled.
redis-cli ACL LIST # after authenticating: the default user now stores a SHA-256 hash
# user default on sanitize-payload #48486e1514e842346ff405b1e45f4405... ~* &* +@all
A client authenticates with AUTH, either in the legacy one-argument form or with an explicit username. RESP3 clients usually authenticate during the HELLO handshake:
AUTH Tr0ub4dor&3 # legacy form: user "default"
AUTH default Tr0ub4dor&3 # explicit username (Redis 6+)
HELLO 3 AUTH default Tr0ub4dor&3 # switch to RESP3 and authenticate in one round trip
Facts worth knowing (verified on 8.10)
| Behavior | Consequence |
|---|---|
CONFIG GET requirepass returns the password in plain text | Anyone allowed to run CONFIG GET can read it: restrict CONFIG with ACLs |
Changing the password with CONFIG SET requirepass does not affect connections that are already authenticated | After a leak, also disconnect existing clients (CLIENT KILL USER default) |
Failed attempts are counted in INFO stats (acl_access_denied_auth) and recorded in ACL LOG | Alert on a growing counter |
| There is no lockout and no delay after failed attempts | Guessing speed is limited only by the network and the server |
The last row is the important one. One million wrong AUTH commands sent through one pipelined connection (redis-cli --pipe) took 34.9 s, about 29,000 guesses per second. Four connections in parallel made 4 million guesses in 46.7 s, about 86,000 per second or roughly 7 billion per day. The server answered every one of them and recorded them as a single ACL LOG entry whose count field reached 1,000,000. A dictionary word, a name plus a year, or any password a human can remember falls to this rate in minutes.
So a Redis password must be long and random, like an API key. ACL GENPASS returns 256 random bits as 64 hex characters:
redis-cli ACL GENPASS
# bd09789de947fb0af093428b906c1e61bfde0ee6939e7436f9a367c0fdfbe7af
Keeping the password secret on the client side
# -a puts the password in shell history and in the process list (ps), hence the warning
redis-cli -a "$PW" PING
# Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
export REDISCLI_AUTH="$PW" # read by redis-cli, not visible in the process list
redis-cli PING
redis-cli --askpass PING # prompt interactively
import os
import redis
r = redis.Redis(
host="cache.internal",
port=6379,
username="default", # optional for the default user
password=os.environ["REDIS_PASSWORD"], # from a secret store, never from source code
decode_responses=True,
)
r.ping()
Replication needs the password too
A replica connects to its primary like any other client. If the primary requires a password, the replica must be told which one with masterauth (and masteruser if it should authenticate as a specific ACL user). Sentinel has equivalent settings (sentinel auth-pass, sentinel auth-user). Forgetting them makes replication fail with authentication errors in the replica's log (chapter 7.1).
Limits of a single shared password
Every client that knows the password can do everything: read every key, run FLUSHALL, change the configuration. A leak from the least important service compromises all of them, and rotating the password means changing every client at the same moment. ACL users, described next, solve both problems.
Key Takeaways
requirepasssets the password of thedefaultuser. Clients sendAUTH [user] passwordorHELLO 3 AUTH user password.- Redis does not slow down or block password guessing: tens of thousands of guesses per second are possible. Use long random passwords (
ACL GENPASS). CONFIG GET requirepassreveals the password, and changing it does not log out existing connections.- Keep passwords out of command lines and source code: use
REDISCLI_AUTH,--askpassand secret stores. - Configure
masterauth(andmasteruser) on replicas of a password-protected primary.
Practice
- (Beginner) Set a password with
CONFIG SET requirepass, then connect withredis-cliusing-a,REDISCLI_AUTHand--askpass. Runps aux | grep redis-cliduring a long-running command (for exampleredis-cli -a pw --stat) to see what the warning is about.- (Intermediate) Open one authenticated connection, change the password from a second connection, and check that the first connection still works. Then write the sequence of commands an operator should run after a password leak so that no client keeps using the old password.
- (Interview) "Our Redis password is an eight-character mixed-case word with a digit. The server is only reachable from the company VPN. Is that good enough?" Hint: estimate guesses per second without lockout, and think about who is on a VPN.
ACL Users and Permissions
A single password gives every client the same powers. In practice, a web application needs to read and write its own keys, a reporting job only needs to read, a monitoring agent needs INFO, and only an administrator should be able to change the configuration. Access Control Lists (ACLs), added in Redis 6.0, give each of them a user with its own passwords and its own permissions. The idea is the principle of least privilege: like giving the cleaning staff a key to the offices but not to the safe.
Anatomy of a user
A user is defined by a list of rules, applied from left to right:
ACL SETUSER app on >app-pass ~app:* &events:app:* +@all -@dangerous
│ │ │ │ │ │
name enabled password keys channels commands
| Rule | Meaning |
|---|---|
on / off | Enable or disable logins as this user |
>secret / <secret | Add / remove a password (stored as a SHA-256 hash) |
#<sha256-hex> / !<sha256-hex> | Add / remove a password given directly as its hash |
nopass / resetpass | Accept any password / remove all passwords and nopass |
~pattern, %R~pattern, %W~pattern | Allow keys matching the glob pattern (all access, read only, write only) |
allkeys / resetkeys | Same as ~* / remove all key patterns |
&pattern, allchannels, resetchannels | Allow Pub/Sub channels (covered in the key and channel topic) |
+command, -command, +command|sub | Allow or deny a command or a single subcommand |
+@category, -@category | Allow or deny a whole category (next topic) |
allcommands / nocommands | Same as +@all / -@all |
(rules) | A selector: an extra, independent set of permissions |
reset | Back to a new user's state: off, no passwords, no permissions |
Because rules are applied in order, +@all -@dangerous and -@dangerous +@all are different users. On 8.10, ACL DRYRUN o1 FLUSHALL refused the first and accepted the second, whose stored rules had collapsed to just +@all.
Creating and inspecting a user
redis-cli ACL SETUSER app on '>app-pass' '~app:*' '+@all' '-@dangerous'
redis-cli ACL GETUSER app
# flags: on sanitize-payload | passwords: e8d2ce... | commands: +@all -@dangerous
# keys: ~app:* | channels: (empty) | selectors: (empty)
A="redis-cli --user app --pass app-pass --no-auth-warning"
$A GET app:1 # hello
$A GET other:1 # NOPERM No permissions to access a key
$A FLUSHALL # NOPERM User app has no permissions to run the 'flushall' command
redis-cli ACL DRYRUN app GET other:1 # test a rule without running the command
# User app has no permissions to access the 'other:1' key
redis-cli ACL LOG 5 # recent denials: reason, user, command, client address
redis-cli ACL WHOAMI # which user is this connection?
ACL LOG and the acl_access_denied_* counters in INFO stats (auth, cmd, key, channel, tls_cert) are the main tools for debugging a user whose rules are too strict, and for spotting a client that probes what it is not allowed to do.
What happens to connections that are already open
ACL changes take effect at once, but not every change affects existing connections the same way. The following was observed on 8.10 with a client that stayed connected while an administrator changed its user:
Change to user svc | Effect on an open connection authenticated as svc |
|---|---|
Add or remove a permission (-get) | Applies to the next command (NOPERM) |
Remove the password it logged in with (<old-pass) | None: the connection stays authenticated |
Disable the user (off) | None: existing connections keep working, new logins fail |
Delete the user (ACL DELUSER svc) | The server closes the connection |
CLIENT KILL USER svc | The server closes the connection |
To lock out a user immediately, combine off (or DELUSER) with CLIENT KILL USER.
Zero-downtime password rotation
Because a user may have several passwords, rotation does not need a synchronized switch:
1. ACL SETUSER svc >new-pass # user now accepts old-pass and new-pass
2. deploy clients with new-pass # gradually, at any pace
3. ACL SETUSER svc <old-pass # old-pass is refused for new logins
4. CLIENT KILL USER svc (optional) # force reconnects, now with new-pass
Persisting users: redis.conf or an ACL file
Users created with ACL SETUSER live in memory and disappear at restart unless they are saved. There are two mutually exclusive places to keep them:
Users in redis.conf | ACL file (aclfile /etc/redis/users.acl) | |
|---|---|---|
| Syntax | user app on #... ~app:* +@all lines in the config | The same user ... lines in a separate file |
| Save runtime changes | CONFIG REWRITE | ACL SAVE |
| Reload without restart | No | ACL LOAD |
| Typical use | Small, static setups | Anything managed by automation |
Redis 8.10 refuses to start if both are used: "Configuring Redis with users defined in redis.conf and at the same setting an ACL file path is invalid...". ACL LOAD is atomic: when one line of the file was invalid (+@nonexistent), it replied ERR /data/users.acl:4: ... no change to the previously active ACL rules was performed and kept the old users. A file written by ACL SAVE looks like this:
user admin on sanitize-payload #10960d2c75b9...c2da ~* &* +@all
user default off nopass sanitize-payload ~* &* +@all
user reporting on sanitize-payload #95a8af3515ef...60cd ~report:* resetchannels -@all +@read +@connection
Passwords appear only as SHA-256 hashes, so the file can be generated by configuration management without storing plain-text secrets: printf '%s' 'the-password' | sha256sum gives the value to put after #. SHA-256 is fast to compute, so a hash taken from a leaked ACL file is only as strong as the random password behind it. This is one more reason to use ACL GENPASS.
Disabling the default user
Clients that never call AUTH run as default. A hardened server turns it off, so that every client must log in as a named user:
redis-cli ACL SETUSER admin on '>admin-pass' '~*' '&*' '+@all' # create an admin FIRST
redis-cli ACL SETUSER default off
redis-cli PING
# NOAUTH Authentication required.
The order matters. During testing, disabling default before an administrator existed left a server where nobody could run ACL SAVE or create users, not even from inside the container. Only a restart, which reloaded the old ACL file, recovered it.
Example: provisioning users from application code
import redis
admin = redis.Redis(host="redis.internal", username="admin", password=ADMIN_PW, decode_responses=True)
admin.acl_setuser(
"orders-api",
enabled=True,
passwords=["+" + ORDERS_PW], # "+" adds a password, "-" removes one
keys=["orders:*", "idempotency:*"], # becomes ~orders:* ~idempotency:*
channels=["orders.events"], # becomes &orders.events
commands=["+@all", "-@dangerous", "-@scripting"],
)
admin.acl_save() # persist to the ACL file
print(admin.acl_getuser("orders-api")["commands"]) # '+@all -@dangerous -@scripting'
Key Takeaways
- ACL users have their own passwords and their own permissions on commands, keys and channels. Rules are applied left to right.
- Use
ACL DRYRUN,ACL LOGandACL WHOAMIto test and debug permissions. - Permission changes apply immediately. Removing a password or disabling a user does not log out open connections: use
CLIENT KILL USERorACL DELUSER. - Rotate passwords by adding the new one before removing the old one.
- Persist users with an ACL file (
ACL SAVE/ACL LOAD) or inredis.conf, never both. Create an admin before turning thedefaultuser off.
Practice
- (Beginner) Create three users,
web(read and write onweb:*, no dangerous commands),report(read-only on all keys) andadmin(everything), and check each one withACL DRYRUNagainstGET web:1,SET web:1 x,CONFIG GET maxmemoryandFLUSHALL.- (Intermediate) Configure a server with an ACL file, rotate the password of
webwith zero downtime while a script connects every second with the old password, then the new one. Make sure the old password stops working and that no connection still uses it at the end.- (Interview) "A contractor's Redis credentials leaked. You run
ACL SETUSER contractor off. Is the incident contained?" Hint: look at the table of effects on open connections.
Command Categories
Listing every allowed command for every user would be long, and would break each time Redis adds commands. ACL categories group commands by what they do, so a rule like +@read or -@dangerous covers many commands at once, including ones added in future releases.
The categories in Redis 8.10
ACL CAT returned 30 categories on Redis 8.10.3, eight of which come from the modules bundled with Redis 8 (the Query Engine, JSON, time series and probabilistic structures):
redis-cli ACL CAT
# keyspace read write set sortedset list hash string array bitmap hyperloglog geo stream
# pubsub admin fast slow blocking dangerous connection transaction scripting
# bloom cuckoo cms topk tdigest search timeseries json
redis-cli ACL CAT dangerous # list the commands in one category
| Category | Entries | What it groups |
|---|---|---|
@read | 166 | Commands that read data |
@write | 191 | Commands that modify data |
@keyspace | 35 | Type-independent key operations (DEL, EXPIRE, SCAN, ...) |
@admin | 81 | Administration (CONFIG, DEBUG, REPLICAOF, ACL SETUSER, ...) |
@dangerous | 93 | Commands that can harm availability, durability or security, or reveal information |
@fast / @slow | 154 / 313 | O(1) or O(log N) commands vs. the rest |
@connection | 38 | AUTH, HELLO, CLIENT SETNAME, PING, ... |
@pubsub / @scripting | 13 / 21 | Publish/Subscribe and Lua / functions |
@search / @json | 46 / 25 | Module commands (FT.*, JSON.*) |
The counts include subcommands such as config|get, which is why they do not add up to the 447 top-level commands reported by COMMAND COUNT. A command belongs to several categories: KEYS is @read @slow @dangerous, and FT.SEARCH is @read @search.
@dangerous is broader, and narrower, than it sounds
Some members are obvious: FLUSHALL, FLUSHDB, CONFIG SET, DEBUG, MODULE LOAD, REPLICAOF, SHUTDOWN, MIGRATE, RESTORE, ACL SETUSER. Others are there because they reveal information or are expensive:
| Command | Categories on 8.10 | Notes |
|---|---|---|
INFO | @dangerous @slow | Reveals versions, memory, replication topology |
KEYS | @read @slow @dangerous | O(N), can block the server |
SORT | @write @slow @dangerous | Can be expensive, and BY/GET read arbitrary keys |
CONFIG GET | @admin @slow @dangerous | Reveals requirepass and masterauth |
CLIENT LIST, SLOWLOG GET | @admin @slow @dangerous | Reveal other clients' addresses and commands |
SCAN | @read @slow | Not dangerous |
EVAL, SCRIPT FLUSH | @slow (plus @scripting) | Not dangerous |
FUNCTION FLUSH | @write @slow (plus @scripting) | Not dangerous, yet deletes all functions |
ACL WHOAMI, HELLO | @slow / @fast | Safe for everyone |
A user with +@all -@dangerous therefore cannot run INFO (a monitoring agent needs +info added back) but can still run EVAL and FUNCTION FLUSH. Remove @scripting explicitly when a user does not need scripts (11.2 explains why).
Common recipes
# Application: everything except dangerous commands and scripting, on its own keys
ACL SETUSER app on >... ~app:* resetchannels +@all -@dangerous -@scripting
# Read-only analyst: allow-list instead of deny-list
ACL SETUSER analyst on >... ~* -@all +@read +@connection -keys
# Monitoring agent: no data access at all
ACL SETUSER metrics on >... resetkeys -@all +@connection +info +ping +latency|latest +slowlog|get +config|get
# Queue worker: only the commands it uses
ACL SETUSER worker on >... ~jobs:* -@all +@connection +brpop +lpush +xreadgroup +xack +xadd
Allow-lists vs. deny-lists
+@all -@dangerous is a deny-list: everything not explicitly removed is allowed, including every command a future Redis version or module adds. When Redis 8 bundled the Query Engine and JSON, users defined as +@all gained FT.* and JSON.* commands, FT.DROPINDEX among them. -@all +@read +... is an allow-list: new commands stay forbidden until someone adds them. Prefer allow-lists for users that need a small, stable set of commands, and review deny-list users after every upgrade.
Key Takeaways
- Categories (
@read,@write,@admin,@dangerous, ...) group commands. A command belongs to several categories, and modules add their own. - Inspect categories with
ACL CATandACL CAT <category>on your own version: membership changes between releases. @dangerousincludes informative commands likeINFOandCONFIG GET, but notEVAL,SCANorFUNCTION FLUSH.- Subcommands can be allowed individually (
+config|get). - Allow-lists are safer over time than deny-lists like
+@all -@dangerous.
Practice
- (Beginner) Run
ACL CAT dangerousand sort the output into three groups: commands that destroy data, commands that change the server, and commands that only reveal information.- (Intermediate) Write an allow-list user for a Prometheus exporter, run the exporter with it, and use
ACL LOGto add only the commands it actually needs until no denials remain.- (Interview) "Why might
+@all -@dangerousbe a reasonable default today and an unsafe one after the next upgrade?" Hint: think about modules and new commands, and which categories they land in.
Key and Channel Patterns in ACLs
Command permissions decide what a user can do. Key and channel patterns decide where. They make it possible to share one Redis server between several applications or tenants, each confined to its own namespace.
Key patterns
Key patterns are glob patterns (the same syntax as KEYS and SCAN MATCH). Since Redis 7.0 they can grant read access, write access, or both:
| Rule | Access to matching keys |
|---|---|
~app:* (same as %RW~app:*) | Read and write |
%R~src:* | Read only |
%W~dst:* | Write only |
allkeys (same as ~*) | All keys |
resetkeys | No keys |
Redis checks every key a command touches. A command that both reads and deletes a key needs both permissions on it. With %R~src:* %W~dst:*, ACL DRYRUN on 8.10 gave:
| Command | Result | Why |
|---|---|---|
COPY src:1 dst:1 | Allowed | Reads src:1, writes dst:1 |
COPY dst:1 src:1 | Denied on dst:1 | Cannot read dst:1 |
SET src:1 x | Denied | Cannot write src:1 |
GET dst:1 | Denied | Cannot read dst:1 |
DEL src:1 | Denied | Deleting is a write |
RENAME src:1 dst:9 | Denied on src:1 | Rename deletes the source key |
Key patterns protect values, not key names
The checks apply to commands that name keys as arguments. Commands that discover keys are not filtered. A user restricted to ~app:* on a server that also held other:1 observed:
$A GET other:1 # NOPERM No permissions to access a key
$A SCAN 0 # 0, app:1, other:1 <- names of other tenants' keys
$A RANDOMKEY # returned other:1 in 2 of 6 calls
$A KEYS '*' # NOPERM ... only because KEYS is in @dangerous
If key names carry sensitive information (e-mail addresses, customer IDs), remove scan and randomkey from users that do not need them, or use separate databases or servers for separate tenants.
Keys inside scripts
Scripts run with the permissions of the user who calls them. Keys declared in KEYS[] are checked before the script runs. Keys accessed without being declared are checked when the script calls redis.call:
$A EVAL "return redis.call('GET', KEYS[1])" 1 other:1
# NOPERM No permissions to access a key
$A EVAL "return redis.call('GET', 'other:1')" 0
# ERR ACL failure in script: No permissions to access a key script: b03d3e8c..., on @user_script:1.
Selectors
Sometimes one user needs different command permissions on different key spaces: for example, read-only on reports but read-write on a cache. Root permissions combine commands and keys with a logical OR, so +@read +@write ~report:* ~cache:* would allow writes to reports too. Selectors (Redis 7.0) are independent sets of permissions in parentheses. A command is allowed if the root permissions or any selector allows it:
redis-cli ACL SETUSER rep on '>rep-pass' '~report:*' '+@read' '(~cache:* +@read +@write)'
redis-cli ACL DRYRUN rep GET report:1 # OK (root permissions)
redis-cli ACL DRYRUN rep SET cache:1 x # OK (selector)
redis-cli ACL DRYRUN rep SET report:1 x # User rep has no permissions to access the 'report:1' key
Channel patterns
Pub/Sub channels have their own patterns, prefixed with &:
| Rule | Meaning |
|---|---|
&events:app:* | Allow channels matching the pattern |
allchannels (same as &*) | All channels |
resetchannels | No channels (the default for new users since Redis 7.0) |
Since 7.0, the setting acl-pubsub-default is resetchannels, so new users cannot publish or subscribe anywhere until channels are granted. With &events:app:*:
$A PUBLISH events:app:1 hi # (integer) 0
$A PUBLISH events:other hi # NOPERM No permissions to access a channel
$A PSUBSCRIBE 'events:*' # NOPERM No permissions to access a channel
PSUBSCRIBE is checked against the pattern text itself, not against the channels it could match: events:* would also receive events:other, so it is refused even though some of its matches are allowed.
Example: a multi-tenant layout
user tenant-a ~tenant:a:* &tenant:a:* -@all +@read +@write +@connection -scan -randomkey
user tenant-b ~tenant:b:* &tenant:b:* -@all +@read +@write +@connection -scan -randomkey
user ops ~* &* +@all
user default off
keyspace: tenant:a:user:17 tenant:a:cart:9 tenant:b:user:3 tenant:b:cart:4
└──── tenant-a only ────────────┘ └──── tenant-b only ───────────┘
In a cluster, add a hash tag to the tenant prefix (tenant:{a}:*) if a tenant's multi-key commands must run on one shard (chapter 7.3). ACLs are not a substitute for resource isolation: a tenant can still fill memory or run slow commands that delay everyone. Use separate servers when tenants must not affect each other's performance.
Key Takeaways
~,%R~and%W~grant read-write, read-only and write-only access to keys matching a glob pattern. Every key a command touches is checked.- Key patterns do not hide key names:
SCANandRANDOMKEYlist keys outside the pattern. - Scripts run with the caller's permissions, for declared and undeclared keys alike.
- Selectors express "read here, write there" rules that root permissions cannot.
- Channels are denied by default for new users (
acl-pubsub-default resetchannels). Grant them with&pattern.
Practice
- (Beginner) Create a user that can read
config:*and read-writesession:*, then check withACL DRYRUNthatGET config:x,SET session:1 vandSET config:x vbehave as expected.- (Intermediate) Build the two-tenant layout above. As
tenant-a, try to discovertenant-b's key names with every command you can think of, and close each leak you find with a rule.- (Interview) "Can ACLs make a single Redis server safe to share between untrusted customers?" Hint: separate confidentiality (keys, names, channels) from availability (memory, CPU, slow commands).
<a id="112-network-and-hardening"></a>
11.2 Network and Hardening
Access control assumes that the attacker talks to Redis through its normal interface. This subchapter covers the layers around and beneath it: encrypting the traffic, limiting who can reach the port at all, limiting what the most powerful commands and scripts can do, and the attacks that have hit real servers when these layers were missing.
TLS Encryption
RESP is a plain-text protocol (chapter 1.3). Anyone who can observe the network between a client and Redis (another tenant on a shared network, a compromised router, a misconfigured traffic mirror) sees every key, every value and the password in every AUTH command. TLS encrypts the connection and lets each side prove its identity with certificates, like a sealed envelope with a verified sender. Redis supports TLS natively since 6.0. Builds must include it (BUILD_TLS=yes), which the official Docker image does.
Certificates
TLS needs a certificate authority (CA) that both sides trust, a server certificate signed by it, and optionally client certificates. For testing, OpenSSL is enough. In production, use your organization's PKI or a tool such as cert-manager.
# Certificate authority
openssl genrsa -out ca.key 4096
openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 -subj "/CN=Example Redis CA" -out ca.crt
# Server certificate: the SAN must contain the names clients use to connect
openssl genrsa -out redis.key 2048
openssl req -new -key redis.key -subj "/CN=redis.internal" -out redis.csr
printf "subjectAltName=DNS:redis.internal,DNS:localhost,IP:127.0.0.1\n" > san.ext
openssl x509 -req -in redis.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
-days 365 -sha256 -extfile san.ext -out redis.crt
# Client certificate: its CN can become the Redis user name (see tls-auth-clients-user)
openssl genrsa -out client.key 2048
openssl req -new -key client.key -subj "/CN=checkout-api" -out client.csr
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 365 -sha256 -out client.crt
Server configuration
port 0 # disable the plain-text port entirely
tls-port 6379 # TLS on the standard port
tls-cert-file /etc/redis/tls/redis.crt
tls-key-file /etc/redis/tls/redis.key
tls-ca-cert-file /etc/redis/tls/ca.crt # CA used to verify client certificates
tls-auth-clients yes # yes (default): client certificate required
# optional: verified if sent; no: not requested
tls-auth-clients-user CN # log in as the user named in the certificate's CN
tls-protocols "TLSv1.2 TLSv1.3" # the default; never enable TLSv1 or TLSv1.1
tls-replication yes # replicas connect to this primary over TLS
tls-cluster yes # encrypt the cluster bus as well
port 0 matters: a server with both port 6379 and tls-port 6380 still accepts unencrypted connections on 6379.
What clients see (verified on 8.10)
| Client situation | Result |
|---|---|
| Plain-text client on the TLS port | Error: Connection reset by peer |
| TLS client without the CA certificate | SSL_connect failed: certificate verify failed |
No client certificate, tls-auth-clients yes | Error: Server closed the connection |
No client certificate, tls-auth-clients optional | Connected as default |
Client certificate with CN=checkout-api, tls-auth-clients-user CN, user checkout-api exists | ACL WHOAMI returned checkout-api without any AUTH |
redis-cli --tls to an IP address not in the server certificate's SAN | Connected (PONG) |
| redis-py to the same IP address | Refused: certificate verify failed: IP address mismatch |
The last two rows show that redis-cli (8.10.3) verified the certificate chain but not the host name, while redis-py checks both by default. Do not disable hostname checks in application clients (ssl_check_hostname=False in redis-py). Without them, any certificate signed by the same CA, including one issued for a different service, is accepted.
With tls-auth-clients-user CN, a client whose certificate names no existing user is connected as the unauthenticated default user. Keep default disabled or restricted so that this fallback grants nothing.
For replication and the cluster bus, Redis 8.10 also offers tls-expected-peer-name: every node's certificate must carry the configured name in its SAN. This stops a certificate from another service signed by a shared CA from joining the cluster or acting as a primary.
Client examples
redis-cli -h redis.internal -p 6379 --tls \
--cacert ca.crt --cert client.crt --key client.key \
ACL WHOAMI
import redis
r = redis.Redis(
host="redis.internal", # must match a SAN entry in the server certificate
port=6379,
ssl=True,
ssl_ca_certs="/etc/app/tls/ca.crt",
ssl_certfile="/etc/app/tls/client.crt",
ssl_keyfile="/etc/app/tls/client.key",
# ssl_check_hostname stays True (the default)
)
# Equivalent URL form: rediss://user:password@redis.internal:6379/0 (two s's = TLS)
What TLS costs
redis-benchmark in a container on the same Docker network as the server, against the plain and TLS ports of one Redis 8.10 server:
| Workload | Plain text | TLS | Difference |
|---|---|---|---|
SET/GET, 50 clients, no pipelining | ~92,000 req/s | ~58,000 to 69,000 req/s | about 25 to 35% fewer |
SET/GET, 50 clients, pipeline of 16 | ~746,000 to 766,000 req/s | ~569,000 to 676,000 req/s | about 10 to 25% fewer |
New connection for every PING (-k 0) | 1,089 req/s, p50 2.6 ms | 493 req/s, p50 11.2 ms | handshakes are expensive |
Encryption costs CPU on the server's main thread, so it is felt most by small commands, and least by pipelined ones. The handshake is the most expensive part, which makes connection reuse (chapter 10.2) even more important with TLS.
Key Takeaways
- Without TLS, keys, values and passwords cross the network in plain text.
- Configure
tls-port, certificates and a CA, and setport 0to close the plain-text port. Enabletls-replicationandtls-clusterfor internal links. tls-auth-clients yesrequires client certificates.tls-auth-clients-user CNmaps a certificate to an ACL user.- Keep hostname verification on in clients.
redis-clidid not check host names in testing. - TLS cost about a quarter to a third of throughput for small unpipelined commands, and made new connections about 4 times slower: reuse connections.
Practice
- (Beginner) Generate a CA and a server certificate, start Redis with
port 0andtls-port 6379, and connect withredis-cli --tls. Then try to connect without--tlsand without--cacert, and explain each error.- (Intermediate) Add client certificates with
tls-auth-clients-user CN, create an ACL user matching the CN, and check withACL WHOAMIthat the client is logged in without a password. Then measure the throughput loss of TLS on your hardware withredis-benchmark, with and without-P 16.- (Interview) "We run Redis inside a private VPC. Do we still need TLS?" Hint: think about who else can observe traffic inside a VPC, compliance requirements, and what an attacker who is already inside gains from plain-text
AUTH.
Binding and Firewalling
Authentication and TLS protect a server that attackers can reach. Network controls decide whether they can reach it at all. They are the outer walls of the building, and they work even if a password is weak or a bug lets someone skip authentication. Defense in depth means using all the layers at once:
internet ──▶ [ cloud security group / perimeter firewall ] who can reach the host
│
▼
[ host firewall (nftables, ufw) / NetworkPolicy ] which sources may use port 6379
│
▼
[ bind: listening addresses ] which interfaces Redis listens on
│
▼
[ protected mode / AUTH / TLS client certs ] who is this client?
│
▼
[ ACL user permissions ] what may this client do?
The bind directive
bind lists the local addresses Redis listens on. A client can only connect through one of those addresses:
| Setting | Listens on |
|---|---|
bind 127.0.0.1 -::1 | IPv4 and IPv6 loopback only (sample redis.conf). The - prefix means "skip this address if it is not available" |
bind 10.0.1.15 127.0.0.1 | One private interface plus loopback |
bind * -::* | All IPv4 and IPv6 interfaces (official Docker image) |
No bind line | All interfaces |
port 0 plus unixsocket /run/redis/redis.sock | No TCP at all: local processes only |
Since Redis 7.0, bind can be changed at runtime. A server started with --bind 127.0.0.1 -::1 refused a client in another container (Connection refused). After CONFIG SET bind "* -::*", the same client got PONG immediately.
For a Unix socket, restrict access with file permissions, for example unixsocketperm 770, and add the application's user to the socket's group. Unix sockets are also faster than loopback TCP for co-located clients.
Host firewalls
Bind to a private interface and still filter by source address: other machines on the same private network should not all be able to talk to Redis.
# nftables: allow 6379 only from the application subnet
nft add rule inet filter input ip saddr 10.0.2.0/24 tcp dport 6379 accept
nft add rule inet filter input tcp dport 6379 drop
# ufw equivalent
ufw allow from 10.0.2.0/24 to any port 6379 proto tcp
ufw deny 6379/tcp
Remember all the ports a deployment uses: 6379 for clients, 16379 for the cluster bus (client port + 10000, chapter 7.3), and 26379 for Sentinel (chapter 7.2). The cluster bus must be reachable only by other cluster nodes.
Containers
Docker inserts its own iptables rules for published ports, and they are evaluated before rules that tools like ufw add. docker run -p 6379:6379 therefore exposes Redis on all host interfaces even when ufw deny 6379 is active. Publish only where needed:
# Reachable only from the host itself
docker run -d -p 127.0.0.1:6379:6379 redis:8.10 redis-server /etc/redis/redis.conf
# Better: no published port; application containers share a private Docker network
docker network create backend
docker run -d --name redis --network backend redis:8.10 redis-server /etc/redis/redis.conf
docker run -d --network backend my-app # connects to redis:6379
In Kubernetes, a Service of type ClusterIP is not reachable from outside the cluster, but every pod in the cluster can reach it. A NetworkPolicy limits it to the pods that need it:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: redis-allow-app
spec:
podSelector:
matchLabels:
app: redis # applies to the Redis pods
policyTypes: ["Ingress"]
ingress:
- from:
- podSelector:
matchLabels:
role: checkout-api # only these pods may connect
ports:
- protocol: TCP
port: 6379
Key Takeaways
- Network controls are the outer layers: if an attacker cannot reach the port, weak passwords and authentication bugs do not matter.
bindselects listening interfaces. Prefer loopback, a private interface or a Unix socket, and never a public interface.- Filter by source address with host firewalls, cloud security groups or Kubernetes NetworkPolicies, including the cluster bus and Sentinel ports.
- Docker's published ports bypass
ufw. Publish on127.0.0.1or use private container networks.
Practice
- (Beginner) Start Redis with
bind 127.0.0.1 -::1and confirm withss -ltnp(or/proc/net/tcp) which address it listens on. Change it at runtime withCONFIG SET bindand check again.- (Intermediate) On a test VM with
ufwenabled and port 6379 denied, startdocker run -p 6379:6379 redis:8.10and test from another machine whether the port is reachable. Fix it two ways and verify both.- (Interview) "Draw the layers of protection between the internet and a Redis key in your last project. Which layer would have stopped an attacker who had stolen an application server's credentials?" Hint: network controls stop outsiders. Least-privilege ACLs and audit logs limit insiders.
Renaming and Disabling Dangerous Commands
A handful of commands can do far more damage than ordinary data commands: FLUSHALL deletes everything, CONFIG SET changes where files are written, DEBUG can crash the server, MODULE LOAD runs native code. Before ACLs existed, the only way to keep them from ordinary clients was to hide them. Today there are three tools, and the oldest one is deprecated.
rename-command (deprecated)
rename-command changes a command's name, or removes it with an empty name. It works only in the configuration file:
rename-command FLUSHALL "" # removed for everyone
rename-command CONFIG ops-config-7f3a9c # only clients that know the new name can use it
The sample redis.conf of 8.10 marks it as deprecated: "avoid using this option if possible. Instead use ACLs...". Testing on 8.10.3 shows why:
| Observation | Problem |
|---|---|
FLUSHALL → ERR unknown command 'FLUSHALL', also inside Lua scripts | Applies to every user, administrators included |
COMMAND LIST still lists config, and COMMAND INFO ops-config-7f3a9c reports the name config | The secret name is not hidden from introspection tools |
ACL SETUSER u1 +ops-config-7f3a9c → Unknown command or category name in ACL. ACL rules use the original name | Renaming and ACLs mix badly |
Cannot be changed with CONFIG SET | Requires a restart |
| Commands in the AOF or sent to replicas use the server's names | Renaming differently on primary and replicas breaks replication or AOF loading |
A renamed command is a secret shared by every tool that needs it, and it cannot be rotated without a restart. ACLs achieve the same effect per user:
# Instead of renaming FLUSHALL and CONFIG for everybody:
redis-cli ACL SETUSER app on '>...' '~app:*' '+@all' '-@dangerous' # cannot run them
redis-cli ACL SETUSER admin on '>...' '~*' '&*' '+@all' # can
redis-cli ACL SETUSER default off
Protected configs and blocked commands (Redis 7.0+)
Since Redis 7.0, three settings block the most abused features by default, regardless of the user's ACL permissions:
Setting (default no) | Blocks |
|---|---|
enable-protected-configs | CONFIG SET of settings that choose where files are written, such as dir and dbfilename |
enable-debug-command | DEBUG |
enable-module-command | MODULE LOAD, MODULE UNLOAD and related subcommands |
Each one accepts no (blocked for all connections), local (allowed from loopback and Unix sockets) or yes. They are immutable at runtime, so an attacker cannot turn them back on:
redis-cli CONFIG SET dir /root/.ssh
# ERR CONFIG SET failed (possibly related to argument 'dir') - can't set protected config
redis-cli DEBUG SLEEP 0
# ERR DEBUG command not allowed. If the enable-debug-command option is set to "local", ...
redis-cli MODULE LOAD /tmp/x.so
# ERR MODULE command not allowed. If the enable-module-command option is set to "local", ...
redis-cli CONFIG SET enable-protected-configs yes
# ERR CONFIG SET failed (possibly related to argument 'enable-protected-configs') - can't set immutable config
These blocks applied even to a loopback connection as the all-powerful default user. Several other file settings (appendfilename, appenddirname, aclfile, logfile, pidfile, unixsocket) are simply immutable at runtime. But not everything is protected: requirepass, masterauth, save and replica-announce-ip could still be changed with CONFIG SET. A client that can run CONFIG SET can still lock everyone out by changing the password, so CONFIG remains an administrator-only command.
Set enable-module-command local (or yes) only on servers that load modules at runtime, and prefer loading modules from the configuration file (loadmodule) instead.
Key Takeaways
rename-commandis deprecated: it applies to all users, confuses ACLs and introspection, and requires a restart to change.- Use ACLs to keep dangerous commands away from application users, and a separate admin user for operators.
- Since 7.0,
enable-protected-configs,enable-debug-commandandenable-module-commanddefault tono, block abused features for everyone, and cannot be changed at runtime. CONFIG SETcan still change passwords and other settings, soCONFIGmust stay restricted.
Practice
- (Beginner) Start a server with
rename-command FLUSHDB ""and tryFLUSHDBdirectly, insideEVAL, and throughACL SETUSER x +flushdb. Record what each attempt returns.- (Intermediate) Migrate a configuration that uses
rename-commandforCONFIG,FLUSHALL,FLUSHDBandKEYSto an ACL-based setup withapp,opsand a disableddefaultuser. Write a short checklist that proves nothing broke for the application.- (Interview) "An attacker has an authenticated connection with
+@allon Redis 8. What can they still do, given thatdirandMODULE LOADare blocked?" Hint: look at whatCONFIG SETstill accepts, and atREPLICAOF,FLUSHALLand scripting.
Lua Sandbox Security
EVAL and functions (chapter 4.4) run user-supplied Lua code inside the server process. That is powerful, and risky: a script runs with the full privileges of the Redis process and blocks the server while it runs. Redis therefore runs Lua inside a sandbox, a restricted environment where scripts can call Redis commands but not touch the operating system. The sandbox is like a workshop with the tools bolted to the bench: you can work, but you cannot take a tool out of the room.
What the sandbox removes (verified on 8.10)
Listing the global environment from inside a script shows what is available:
redis-cli EVAL "local t={} for k,v in pairs(_G) do t[#t+1]=k end table.sort(t) return t" 0
# ARGV KEYS _G _VERSION assert bit cjson cmsgpack collectgarbage coroutine error gcinfo
# getmetatable ipairs load loadstring math next os pairs pcall rawequal rawget rawset
# redis select setmetatable string struct table tonumber tostring type unpack xpcall
| Attempt | Result |
|---|---|
os.execute('id') | attempt to call field 'execute' (a nil value): os only contains clock |
io.open('/etc/passwd') | Script attempted to access nonexistent global variable 'io' |
require, dofile, loadfile, package.loadlib, debug, getfenv | Same: not present |
x = 1 (create a global) | Attempt to modify a readonly table |
redis = nil, string.upper = nil, setmetatable(_G, nil) | Attempt to modify a readonly table |
loadstring(string.dump(f)) (load precompiled bytecode) | Returns nil: bytecode is rejected |
redis.call('CONFIG', 'GET', 'maxmemory') | This Redis command is not allowed from script |
Scripts also run with the caller's ACL permissions (11.1), so a user restricted to ~app:* cannot reach other keys through Lua.
What the sandbox does not limit: time
A script runs atomically, so while it runs, no other client is served. Redis cannot preempt it. Once it has run longer than busy-reply-threshold (5,000 ms by default, formerly lua-time-limit), the server starts answering other clients with an error, and offers two ways out:
redis-cli EVAL "while true do end" 0 & # runs forever
redis-cli PING # no reply until the 5 s threshold, then:
# BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
redis-cli SCRIPT KILL
# OK (the script's client receives: ERR Script killed by user with SCRIPT KILL...)
# A script that has already written cannot be killed: stopping it would break atomicity
redis-cli EVAL "redis.call('SET','k','v') while true do end" 0 &
redis-cli SCRIPT KILL
# UNKILLABLE Sorry the script already executed write commands against the dataset. You can
# either wait the script termination or kill the server in a hard way using the SHUTDOWN NOSAVE command.
SHUTDOWN NOSAVE loses every write since the last persistence point. A single bad script from an authorized user is therefore a denial-of-service risk. Review scripts like code, prefer functions loaded by an administrator over ad-hoc EVAL, and mark read-only scripts with #!lua flags=no-writes so they can always be killed.
When the sandbox itself breaks
The sandbox is only as strong as the Lua interpreter and the way it is built:
| Vulnerability | Cause | Impact | Fixed in |
|---|---|---|---|
| CVE-2022-0543 | Debian's and Ubuntu's redis packages linked Lua dynamically and left the package library reachable, so package.loadlib could load any shared library | Remote code execution for anyone able to run EVAL. Exploited by botnets such as Muhstik | Distribution package updates (DSA-5081, USN-5316-1). Upstream Redis was not affected |
| CVE-2025-49844 ("RediShell") | A use-after-free in the Lua parser, present for about 13 years, triggered by a crafted script that manipulates the garbage collector | Escape from the sandbox and native code execution. Rated CVSS 10.0 by its finders, 9.9 by NVD | Redis 8.2.2, 8.0.4, 7.4.6, 7.2.11 and 6.2.20 (October 3, 2025) |
Both required the ability to run a script. That is why the advisory for RediShell recommended, as a workaround, removing EVAL and EVALSHA from users with ACLs.
# Users that do not need scripting should not have it
redis-cli ACL SETUSER app on '>...' '~app:*' '+@all' '-@dangerous' '-@scripting'
redis-cli ACL CAT scripting # eval, evalsha, eval_ro, fcall, function|load, script|..., ...
Key Takeaways
- The Lua sandbox removes file, process, module-loading and debug facilities, makes globals read-only, rejects bytecode, and blocks commands such as
CONFIG. - Scripts run with the caller's ACL permissions.
- The sandbox does not limit CPU time: a long script blocks the server, and one that has written can only be stopped with
SHUTDOWN NOSAVE. - Sandbox escapes have happened (CVE-2022-0543, CVE-2025-49844). Patch promptly and remove
@scriptingfrom users who do not need it.
Practice
- (Beginner) Run the
_Glisting script on your Redis version and compare it with a plain Lua 5.1 interpreter. List five functions the sandbox removes and explain what each could be used for by an attacker.- (Intermediate) Write a read-only script with
#!lua flags=no-writesthat loops for 10 seconds, load it as a function, and check thatFUNCTION KILLstops it. Repeat with a script that writes first, and explain the difference.- (Interview) "A critical Lua vulnerability is announced, but you cannot upgrade Redis for two weeks. What do you do in the meantime?" Hint: who can run scripts today, which applications actually use them, and how ACLs and network controls reduce exposure.
Common Vulnerabilities and Misconfigurations
Almost every large-scale attack on Redis has started the same way: a server reachable from the internet that accepts commands without a password. Wiz counted about 330,000 internet-exposed Redis instances in October 2025, about 60,000 of them without authentication. This topic explains how such servers are abused, which defaults stop which steps, and how to check your own servers.
How exposed servers are abused
The attacks below are described at the level of mechanism so that you know what to defend against.
| Technique | What the attacker needs | Defense on Redis 8.10 |
|---|---|---|
Read, delete or ransom data: dump keys, FLUSHALL, leave a "pay to get your data back" key | Any unauthenticated access | Authentication, network controls, ACLs without @dangerous |
Lock out the owner: CONFIG SET requirepass ... | CONFIG permission | ACLs (not blocked by protected configs) |
Write files to disk: point dir and dbfilename at ~/.ssh or a cron directory, then SAVE, so that the RDB file is parsed as an SSH key or a cron job | CONFIG SET dir | Blocked by enable-protected-configs no since 7.0, and by running Redis as an unprivileged user |
Rogue primary plus module: REPLICAOF an attacker-controlled server that sends a malicious module file, then MODULE LOAD it. Used by HeadCrab (2023), which infected at least 1,200 servers to mine cryptocurrency | REPLICAOF, CONFIG SET, MODULE LOAD | MODULE LOAD blocked by enable-module-command no, dir blocked by protected configs. REPLICAOF is still allowed and replaces the whole dataset: ACLs |
| Lua sandbox escape: CVE-2022-0543, CVE-2025-49844 | EVAL permission and an unpatched server | Patching, ACLs without @scripting |
Denial of service: KEYS * on a large dataset, endless scripts, DEBUG SLEEP, memory exhaustion | Ordinary permissions | ACLs, maxmemory, busy-reply-threshold, DEBUG blocked by default |
Note the pattern: the 7.0 defaults remove the paths to code execution on the host, but an attacker with unrestricted access can still steal, destroy or replace all data. Only authentication, network controls and least-privilege ACLs prevent that.
Common misconfigurations
| Misconfiguration | How to detect it | Fix |
|---|---|---|
Port published to the internet (-p 6379:6379, bind * on a public VM, a cloud security group open to 0.0.0.0/0) | Scan the public IP from outside: redis-cli -h <public-ip> PING | Bind to private addresses, firewall, private container networks |
default user with nopass | ACL LIST shows user default on nopass | Set a password or ACL SETUSER default off |
| Short or reused password | Password policy review | ACL GENPASS, one user per service |
| Every service shares one all-powerful user | CLIENT LIST shows every client as user=default | Per-service ACL users with least privilege |
CONFIG, REPLICAOF, FLUSHALL available to applications | ACL DRYRUN <user> CONFIG GET requirepass | -@dangerous or allow-lists |
| Plain-text traffic across untrusted networks | CONFIG GET port is non-zero, tls-port is 0 | TLS with port 0 |
enable-*-command yes left from debugging | CONFIG GET enable-* | Set to no or local and restart |
| Redis running as root | ps -o user= -p $(pidof redis-server) | Dedicated redis user (packages and the Docker image do this) |
| Outdated version with known CVEs | INFO server → redis_version | Upgrade to the latest patch release of your line |
| Secrets in logs, backups or fixtures | Review where RDB/AOF files and logs go | Encrypt and restrict backups. hide-user-data-from-log yes keeps user data, such as key names and values, out of the server log |
Example: a quick audit script
#!/usr/bin/env bash
# redis-audit.sh: basic security checks for one server. Needs an admin user.
# Usage: REDISCLI_AUTH=... ./redis-audit.sh host port admin-user
H=$1; P=$2; U=$3
R="redis-cli -h $H -p $P --user $U"
echo "version: $($R INFO server | grep -o 'redis_version:[0-9.]*')"
echo "protected-mode: $($R CONFIG GET protected-mode | tail -1)"
echo "bind: $($R CONFIG GET bind | tail -1)"
echo "plain port: $($R CONFIG GET port | tail -1) (0 = TLS only)"
echo "tls-port: $($R CONFIG GET tls-port | tail -1)"
$R CONFIG GET 'enable-*' | paste - - | sed 's/^/blocked cmds: /'
# Users that log in without a password, or that can run dangerous commands
$R ACL LIST | grep -E ' on .*nopass' | sed 's/^/NO PASSWORD: /'
for u in $($R ACL USERS); do
$R ACL DRYRUN "$u" CONFIG SET maxmemory 0 | grep -q '^OK' && echo "CONFIG allowed: $u"
$R ACL DRYRUN "$u" EVAL "return 1" 0 | grep -q '^OK' && echo "EVAL allowed: $u"
done
echo "auth failures: $($R INFO stats | grep -o 'acl_access_denied_auth:[0-9]*')"
Run it from outside the network as well (without credentials). From there, the only acceptable answers are a refused connection, a timeout or NOAUTH.
Hardened baseline configuration
# Network
bind 10.0.1.15 127.0.0.1 -::1 # private interface and loopback only
protected-mode yes # safety net in case the default user loses its password
port 0 # no plain text
tls-port 6379
tls-cert-file /etc/redis/tls/redis.crt
tls-key-file /etc/redis/tls/redis.key
tls-ca-cert-file /etc/redis/tls/ca.crt
tls-replication yes
# Access control
aclfile /etc/redis/users.acl # default user off, one user per service, admin separate
# Dangerous features stay blocked (these are the defaults, written out for reviewers)
enable-protected-configs no
enable-debug-command no
enable-module-command no
# Limits that turn abuse into errors instead of outages
maxmemory 4gb
maxclients 10000
busy-reply-threshold 5000
hide-user-data-from-log yes
Key Takeaways
- Most real attacks start from an exposed server without authentication. Hundreds of thousands are reachable on the internet.
- Redis 7.0+ defaults block the classic paths to host compromise (writing files with
CONFIG SET dir,MODULE LOAD), but not data theft, destruction orREPLICAOFreplacement. - Check for exposed ports,
nopassusers, shared all-powerful users, plain-text traffic, enabled debug or module commands, root processes and outdated versions. - Audit from inside (configuration and ACLs) and from outside (what an unauthenticated client sees), and repeat after every change and upgrade.
Practice
- (Beginner) Run the audit script against a default
redis:8.10container and against a server built from the hardened baseline. List every difference and the attack each one prevents.- (Intermediate) Set up a lab with two containers: an open Redis 8.10 and a "rogue" Redis acting as a primary. Run
REPLICAOFon the open one and observe what happens to its data. Then write the ACL rules and network rules that would have prevented it.- (Interview) "You found a Redis server open on the internet without a password, and it has been like that for a month. Walk me through your response." Hint: contain first (network, credentials), then check for persistence (ACL users,
CONFIG GET replicaof, loaded modules, files written to disk, SSH keys and cron jobs on the host), then decide whether to rebuild the host and rotate all secrets.
<a id="12-operations-and-performance"></a>