|
| 1 | +--- |
| 2 | +name: redis-security |
| 3 | +description: Redis security guidance covering authentication (requirepass and ACL users), TLS, ACL-based least-privilege access control, restricting network exposure via bind and protected-mode, firewall rules, and disabling dangerous commands. Use when deploying Redis to production, defining ACL users for an application, configuring TLS connections, locking down a Redis instance behind a firewall, or auditing a Redis deployment for security hardening. |
| 4 | +license: MIT |
| 5 | +metadata: |
| 6 | + author: Redis, Inc. |
| 7 | + version: "0.1.0" |
| 8 | +--- |
| 9 | + |
| 10 | +# Redis Security |
| 11 | + |
| 12 | +Production hardening for Redis: authentication, ACL-based access control, and network exposure. Cover all three together — any one of them on its own leaves an exploitable gap. |
| 13 | + |
| 14 | +## When to apply |
| 15 | + |
| 16 | +- Deploying or reviewing a Redis instance destined for production. |
| 17 | +- Setting up application credentials beyond a shared password. |
| 18 | +- Auditing a Redis deployment against a security checklist. |
| 19 | +- Receiving "Redis exposed to the internet" findings from a scanner. |
| 20 | + |
| 21 | +## 1. Always authenticate (and use TLS) |
| 22 | + |
| 23 | +Never run a production Redis without a password. Pair authentication with TLS so credentials and data aren't sent in clear text. |
| 24 | + |
| 25 | +``` |
| 26 | +# redis.conf |
| 27 | +requirepass your-strong-password |
| 28 | +tls-port 6380 |
| 29 | +tls-cert-file /path/to/redis.crt |
| 30 | +tls-key-file /path/to/redis.key |
| 31 | +``` |
| 32 | + |
| 33 | +```python |
| 34 | +r = redis.Redis( |
| 35 | + host="localhost", |
| 36 | + port=6380, |
| 37 | + password="your-strong-password", |
| 38 | + ssl=True, |
| 39 | + ssl_cert_reqs="required", |
| 40 | +) |
| 41 | +``` |
| 42 | + |
| 43 | +If you can use ACL users (next section) instead of the single `requirepass`, do — `requirepass` is effectively the legacy "default user" shortcut. |
| 44 | + |
| 45 | +See [references/auth.md](references/auth.md). |
| 46 | + |
| 47 | +## 2. ACLs for least-privilege access |
| 48 | + |
| 49 | +The `default` user with a shared password is fine for development. For production, give each application a dedicated ACL user with only the commands and key patterns it actually needs. |
| 50 | + |
| 51 | +``` |
| 52 | +# Cache-only reader |
| 53 | +ACL SETUSER app_readonly on >password ~cache:* +get +mget +scan |
| 54 | +
|
| 55 | +# Writer that can't run dangerous ops |
| 56 | +ACL SETUSER app_writer on >password ~* +@all -@dangerous |
| 57 | +
|
| 58 | +# Admin (use sparingly, never for application traffic) |
| 59 | +ACL SETUSER admin on >strong-password ~* +@all |
| 60 | +``` |
| 61 | + |
| 62 | +Useful command categories: |
| 63 | + |
| 64 | +| Category | What it covers | |
| 65 | +|---|---| |
| 66 | +| `@read` | Read commands (`GET`, `MGET`, `HGET`, ...) | |
| 67 | +| `@write` | Write commands (`SET`, `DEL`, `XADD`, ...) | |
| 68 | +| `@dangerous` | `FLUSHALL`, `DEBUG`, `KEYS`, etc. | |
| 69 | +| `@admin` | Administrative commands | |
| 70 | + |
| 71 | +If app credentials leak, a tight ACL bounds the blast radius — the attacker can't `FLUSHALL` your DB just because they grabbed a cache reader's password. |
| 72 | + |
| 73 | +See [references/acls.md](references/acls.md). |
| 74 | + |
| 75 | +## 3. Restrict network access |
| 76 | + |
| 77 | +The most common Redis breach is a public-internet Redis with no auth. Avoid that with three layers: |
| 78 | + |
| 79 | +``` |
| 80 | +# redis.conf — bind to specific interfaces, keep protected-mode on |
| 81 | +bind 127.0.0.1 192.168.1.100 |
| 82 | +protected-mode yes |
| 83 | +``` |
| 84 | + |
| 85 | +```bash |
| 86 | +# Firewall — allow only application subnets |
| 87 | +iptables -A INPUT -p tcp --dport 6379 -s 192.168.1.0/24 -j ACCEPT |
| 88 | +iptables -A INPUT -p tcp --dport 6379 -j DROP |
| 89 | +``` |
| 90 | + |
| 91 | +Anti-pattern: `bind 0.0.0.0` + `protected-mode no` — exposes Redis to the whole network without protection. |
| 92 | + |
| 93 | +Optional but recommended: rename or disable destructive commands so a compromised client can't trash the DB: |
| 94 | + |
| 95 | +``` |
| 96 | +rename-command FLUSHALL "" |
| 97 | +rename-command DEBUG "" |
| 98 | +rename-command CONFIG "" |
| 99 | +``` |
| 100 | + |
| 101 | +See [references/network.md](references/network.md). |
| 102 | + |
| 103 | +## References |
| 104 | + |
| 105 | +- [Redis: Security](https://redis.io/docs/latest/operate/oss_and_stack/management/security/) |
| 106 | +- [Redis: ACL](https://redis.io/docs/latest/operate/oss_and_stack/management/security/acl/) |
0 commit comments