Documentation Index
Fetch the complete documentation index at: https://mintlify.com/redis/redis/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Redis provides multiple security layers including network isolation, authentication, Access Control Lists (ACL), and protected mode. This guide covers security configuration and best practices.Protected Mode
Protected mode is a security layer that prevents Redis instances from being accessed when left open on the internet.How Protected Mode Works
When protected mode is enabled and the default user has no password:- Redis only accepts connections from:
- IPv4 loopback (127.0.0.1)
- IPv6 loopback (::1)
- Unix domain sockets
Configuration
Network Security
Bind Directive
Limit which network interfaces Redis listens on:Unix Domain Sockets
For local connections, Unix sockets provide better security than TCP:Authentication
Legacy Password Authentication (requirepass)
Starting with Redis 6,
requirepass is a compatibility layer on top of ACL. Consider using ACL for new deployments.Password Best Practices
- Use passwords at least 32 characters long
- Generate from cryptographically secure random sources
- Rotate passwords regularly
- Never commit passwords to version control
- Use environment variables or secrets management systems
Access Control Lists (ACL)
ACL provides fine-grained access control, introduced in Redis 6.0.ACL Concepts
ACL allows you to:- Create multiple users
- Define command permissions per user
- Restrict key access patterns
- Control pub/sub channel access
- Enable/disable users
ACL Commands
ACL SETUSER
Create or modify a user:ACL Syntax
ACL rules format:on- Enable user (can authenticate)off- Disable user (cannot authenticate)nopass- No password required (use with caution!)
>password- Add password to user#<hash>- Add hashed password<password- Remove password!<hash>- Remove hashed passwordresetpass- Remove all passwords
~*orallkeys- Access all keys~pattern- Access keys matching glob pattern%R~pattern- Read access to pattern%W~pattern- Write access to patternresetkeys- Remove all key patterns
+@<category>- Allow command category-@<category>- Deny command category+<command>- Allow specific command-<command>- Deny specific command+@allorallcommands- Allow all commands-@allornocommands- Deny all commands
&*orallchannels- Access all pub/sub channels&pattern- Access channels matching patternresetchannels- Remove all channel patterns
@admin- Administrative commands@dangerous- Potentially dangerous commands@keyspace- Key operations@read- Read operations@write- Write operations@set- Set commands@sortedset- Sorted set commands@list- List commands@hash- Hash commands@string- String commands@pubsub- Pub/sub commands@transaction- Transaction commands@scripting- Script commands@stream- Stream commands
ACL GETUSER
View user permissions:ACL LIST
List all users in ACL format:ACL USERS
Get list of usernames:ACL WHOAMI
Get the current authenticated username:ACL DELUSER
Delete a user:ACL LOG
View security events (failed authentications, rejected commands):ACL Configuration File
Define users in a separate ACL file:The ACL file cannot be used together with
requirepass. Choose one authentication method.ACL Examples
Example 1: Read-Only User
- Execute all read commands
- Access all keys
- Execute write commands
- Execute admin commands
Example 2: Cache-Only User
- GET, SET, DEL keys matching
cache:* - Check TTL and set expiration
- Access other keys
- Execute other commands
Example 3: Pub/Sub User
- Publish to channels matching
notifications:* - Subscribe to matching channels
- Access keys
- Use other channels
Example 4: Multi-Pattern Read/Write Separation
- Can read keys matching
read:* - Can write keys matching
write:* - Has all command permissions
Command Renaming
For backward compatibility:Protected Configuration Directives
Redis has security directives to control dangerous operations:no- Block for all connectionsyes- Allow for all connectionslocal- Allow only for local connections (127.0.0.1, ::1, Unix socket)
Security Hardening Steps
# Use ACL for fine-grained control
ACL SETUSER default on >strong_default_password ~* +@all
# Or use requirepass for simple authentication
CONFIG SET requirepass strong_password_here
# Create application user with limited permissions
ACL SETUSER myapp on >app_password ~myapp:* +@read +@write -@dangerous -@admin
See TLS Configuration for encrypting client-server communication.
# Regularly check ACL log
ACL LOG
# Monitor authentication failures in logs
CONFIG SET loglevel notice
# Example iptables rule
sudo iptables -A INPUT -p tcp --dport 6379 -s 192.168.1.0/24 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 6379 -j DROP
Security Checklist
- Configure
binddirective to limit network interfaces - Enable
protected-modeunless using ACL or requirepass - Set strong passwords (32+ characters)
- Use ACL to create application-specific users
- Restrict command access using ACL categories
- Enable TLS for client-server communication
- Configure firewall rules
- Regularly audit ACL LOG
- Keep Redis updated with security patches
- Use Unix sockets for local connections
- Disable or restrict dangerous commands
- Monitor authentication attempts in logs