3.5 Hours

13. Security: Authentication & Authorization

Security

Securing Your Redis Deployment

Security is essential for any Redis deployment, especially in production. This module covers authentication, network security, encryption, and security best practices. You'll learn to protect your Redis instances from unauthorized access and data breaches.

Redis security includes authentication with passwords, network isolation, TLS/SSL encryption, and access control. Redis 6+ supports ACL (Access Control Lists) for fine-grained permissions. Security is essential for production deployments. Implementing security protects your data and meets compliance requirements. This module covers each security aspect in depth with configuration examples and best practices.

Authentication and ACL

Redis supports password authentication and ACL. Set a password in redis.conf. Use ACL for fine-grained permissions. ACL defines what commands users can execute. This provides defense in depth. Use strong passwords and limit access.

ACL (Access Control List) is the most powerful security feature in Redis 6+. It allows you to create users with specific permissions. Each user can have a password, command categories, key patterns, and read/write permissions. ACL is essential for multi-tenant Redis deployments.

Bash
# redis.conf - Set password
requirepass your_secure_password

# ACL configuration (redis.conf or ACL file)
# Create a user with specific permissions
user default on nopass
user appuser on >password +@read +set +get +mget ~* -@admin -@dangerous
user admin on >adminpass +@all

# ACL commands
ACL LIST                    # List all ACL rules
ACL WHOAMI                  # Show current user
ACL CAT                     # List available command categories
ACL CAT @read              # List read commands
ACL SETUSER <user> <rules>  # Create or modify user

# Connect with authentication
redis-cli -a password
AUTH password

Network Security

Network security protects Redis from network-based attacks. Bind to specific interfaces. Use firewall rules. Use TLS/SSL for encryption. Use a private network for Redis. These measures protect Redis from unauthorized access.

TLS encryption is essential for Redis in production, especially when accessed over the internet. TLS protects data in transit from interception. Use strong cipher suites and certificate validation. Redis supports TLS in version 6+.

Bash
# redis.conf - Bind to specific interfaces
bind 127.0.0.1 10.0.0.1

# Disable protected mode (only when using bind)
protected-mode yes

# TLS configuration
port 0                           # Disable non-TLS port
tls-port 6379                    # TLS port
tls-cert-file /path/to/cert.pem
tls-key-file /path/to/key.pem
tls-ca-cert-file /path/to/ca.pem

# Connect with TLS
redis-cli --tls --cert /path/to/client.pem --key /path/to/client.key

Security Best Practices

Security best practices protect your Redis deployment. Set a strong password. Use ACL for fine-grained permissions. Bind to specific interfaces. Use TLS for encryption. Use firewall rules. Regularly update Redis. Monitor for security incidents. Security is an ongoing process, not a one-time setup.

  • Set Password: Always set a strong password with requirepass.
  • Use ACL: Use ACL for fine-grained permissions and multi-tenant isolation.
  • Bind Interfaces: Bind to specific interfaces to limit exposure.
  • Use TLS: Use TLS for encryption in transit.
  • Firewall: Use firewall rules for network security.
  • Regular Updates: Keep Redis and dependencies updated.
  • Monitoring: Monitor for security incidents and suspicious activity.

Knowledge Check

Ready to test your understanding of 13. Security: Authentication & Authorization?

Back