The Midnight Wake-Up Call: When an Exposed Redis Instance Gets Hijacked
After getting burned by SSH brute-force attacks early in my career, I stopped treating server hardening as an afterthought. That habit paid off a few years ago when a teammate spun up a fresh Redis instance on a cloud VM for staging session caching. Four hours after launch, CPU spiked to 100%, our cache keys vanished, and an unfamiliar SSH public key appeared inside /root/.ssh/authorized_keys.
Our application code wasn’t even the problem. The attacker never touched the web framework or our primary database. They simply scanned the cloud provider’s IPv4 range for port 6379, connected without a password, and turned an in-memory cache into a Remote Code Execution (RCE) backdoor.
Treating Redis as “internal-only” without hardening the service itself is a gamble, whether you run on bare metal, a VM, or inside a private VPC. Here is how those attacks actually work, how common defenses compare, and the exact configuration I use before Redis ever sees production traffic.
Why Default Redis Configurations Lead to RCE
Redis was built for speed inside trusted networks, not hostile environments. Out of the box, a default install favors zero-friction setup over defense-in-depth. When an attacker reaches an unhardened port 6379, three gaps make RCE trivial:
- No identity or permission boundaries: Older Redis setups had no password by default, or relied on a single shared
requirepassstring. Anyone who could authenticate held full administrative control. - Plaintext communication: Standard Redis traffic travels unencrypted over TCP. On shared networks or misconfigured cloud subnets, credentials and cached session tokens can be sniffed in transit.
- Unrestricted administrative commands: Commands like
CONFIG,SAVE,FLUSHALL, andREPLICAOFare enabled by default.
To turn that open port into a root shell, attackers usually abuse CONFIG and SAVE. Because Redis persists its in-memory dataset as an RDB snapshot, an attacker can redirect where that file lands at runtime.
They set dir to /root/.ssh/ or /var/spool/cron/, rename dbfilename to authorized_keys, write a key holding their SSH key padded with newlines, and run SAVE. Seconds later, they log in as root. Alternatively, they use REPLICAOF to sync from a rogue primary and load a malicious shared library (.so) module that executes OS commands.
Comparing Redis Security Approaches in Production
Teams usually reach for one of three fixes when they discover an exposed Redis instance. Looking at the trade-offs shows why a layered setup beats any single control.
- Network isolation alone (firewall +
bind 127.0.0.1): Blocking port 6379 at the firewall or binding to localhost stops external internet scans immediately. However, if your app servers sit on separate hosts, you still have to open port 6379 across your VPC. One Server-Side Request Forgery (SSRF) bug in a web container lets an attacker pivot straight into Redis over the private network. - Legacy
requirepass+rename-command: Setting a strong password withrequirepassand renaming dangerous commands inredis.confworks on older Redis 5 deployments. The downside is operational friction: every microservice shares one master password, rotating credentials causes downtime, and you cannot stop a read-only worker from running write commands. - Redis 6.2+ ACLs + TLS + Command Hardening (Recommended): Access Control Lists (ACLs) let you disable the default user, create per-app accounts with least-privilege permissions, and block entire categories of dangerous commands. Pairing ACLs with mutual TLS keeps credentials and payloads unreadable on the wire, even inside a shared VPC.
Step-by-Step Redis Hardening for Production
On Redis 6.2 or newer (including Redis 7.x), layering network binding, ACLs, command restrictions, and TLS shuts down both direct RCE and lateral movement. Below is the exact configuration for /etc/redis/redis.conf.
1. Bind to Private Interfaces and Enforce Protected Mode
Never leave Redis listening on 0.0.0.0. Restrict bind to localhost if your app shares the host, or to your private VPC interface IP, and pair that with firewall rules limiting which source IPs can reach port 6379. Keep protected-mode yes enabled as a safety fallback: if anyone ever removes both bind and authentication, Redis will reject external connections.
# /etc/redis/redis.conf
bind 127.0.0.1 10.0.1.25
protected-mode yes
2. Replace requirepass with Granular Redis ACLs
Shared passwords force an all-or-nothing trust model. Instead, disable the default user and create dedicated accounts in an external file (aclfile /etc/redis/users.acl), which lets you reload permissions live with ACL LOAD without restarting Redis.
First, generate a 256-bit random password from your terminal:
openssl rand -base64 32
Next, reference the ACL file in redis.conf and define least-privilege rules. Note that Redis evaluates ACL rules left to right, and &* grants Pub/Sub channel access (available in Redis 6.2+):
# Add to /etc/redis/redis.conf
aclfile /etc/redis/users.acl
# /etc/redis/users.acl
# Disable the default unauthenticated user completely
user default off nopass nocommands
# Dedicated admin user (for local maintenance only)
user ops_admin on >YourStrongAdminPasswordHere ~* &* +@all
# Application user: restricted to 'app:' keys, no dangerous or admin commands
user web_app on >YourStrongAppPasswordHere ~app:* +@read +@write +@connection -@dangerous -@admin -config -save -bgsave -flushall -flushdb
Because -@dangerous, -@admin, and the explicit exclusions follow +@read +@write, the web_app user cannot touch disk paths or wipe data. Even if your app’s credentials leak, the attacker is boxed into app:* keys.
3. Disable Dangerous Commands Globally
Even with ACLs in place, a second safety net in redis.conf prevents mistakes. Mapping high-risk commands to an empty string disables them globally for every user, including administrative sessions over the network.
# /etc/redis/redis.conf
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command CONFIG ""
rename-command SHUTDOWN ""
rename-command DEBUG ""
rename-command MODULE ""
If your monitoring agent needs read-only metrics, keep INFO available to a dedicated monitoring ACL user. Blocking MODULE and CONFIG globally ensures no rogue replication or dynamic library loading can happen.
4. Encrypt Traffic with TLS
Plaintext traffic inside a VPC still exposes ACL credentials to anyone sniffing the wire. Disable the plaintext port (port 0) and switch to tls-port with your CA, server certificate, and private key. Note that Redis must be built with TLS support (included in official Docker images like redis:7-alpine and modern Linux packages).
# /etc/redis/redis.conf
port 0
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
# Require clients to present a valid certificate (mutual TLS)
tls-auth-clients yes
tls-protocols "TLSv1.2 TLSv1.3"
With connection pooling enabled in your app, TLS handshakes add only a few milliseconds on initial connect. Also verify that the redis system user owns the certificate files with chmod 600 on the private key, and never run the Redis daemon as root. Running unprivileged guarantees that even a zero-day exploit cannot write to /root/.ssh/ or system cron directories.
5. Verify Your Hardened Setup
Restart Redis (sudo systemctl restart redis-server) and test both failure and success paths. Plaintext connections should fail immediately, and your ACL user should be blocked from administrative commands:
# Test TLS connection with ACL user
redis-cli --tls \
--cert /etc/redis/tls/client.crt \
--key /etc/redis/tls/client.key \
--cacert /etc/redis/tls/ca.crt \
-h 10.0.1.25 -p 6379 \
--user web_app --askpass
# Inside redis-cli, verify dangerous commands are blocked:
10.0.1.25:6379> CONFIG GET dir
(error) NOPERM User web_app has no permissions to run the 'config' command
In Python, a service connects cleanly with redis-py using both ACL credentials and mutual TLS:
import redis
client = redis.Redis(
host="10.0.1.25",
port=6379,
username="web_app",
password="YourStrongAppPasswordHere",
ssl=True,
ssl_certfile="/etc/redis/tls/client.crt",
ssl_keyfile="/etc/redis/tls/client.key",
ssl_ca_certs="/etc/redis/tls/ca.crt",
decode_responses=True,
)
client.set("app:health", "ok", ex=60)
print(client.get("app:health"))
Hardening Redis takes under 15 minutes during server provisioning. Put private binding, least-privilege ACLs, disabled commands, and mutual TLS in place from day one, and port 6379 won’t be the reason your pager wakes you up at midnight.
