Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Redis password #53

Open
Yasser opened this issue Dec 19, 2022 · 1 comment
Open

Add Redis password #53

Yasser opened this issue Dec 19, 2022 · 1 comment

Comments

@Yasser
Copy link

Yasser commented Dec 19, 2022

This is not an issue, but it would be nice to get people thinking about security by adding authentication to the Redis container. This can be done easily through the compose/.env files and minimal changes to the application, Redis, and Sidekiq configs.

.env.example:
#export REDIS_URL=redis://redis:6379/1 #export REDIS_PASSWORD=password

docker-compose.yml:
services: redis: command: > --requirepass ${REDIS_PASSWORD:-password}

application.rb:
config.cache_store = :redis_cache_store, { url: ENV.fetch("REDIS_URL") { "redis://redis:6379/1" }, namespace: "cache", password: ENV.fetch("REDIS_PASSWORD") { "password" } }

redis.rb:
@redis ||= Redis.new(url: ENV.fetch("REDIS_URL") { "redis://redis:6379/1" }, password: ENV.fetch("REDIS_PASSWORD") { "password" })

sidekiq.rb:
sidekiq_config = { url: ENV.fetch("REDIS_URL") { "redis://redis:6379/1" }, password: ENV.fetch("REDIS_PASSWORD") { "password" } }

cable.yml:
default: &default password: "<%= ENV.fetch("REDIS_PASSWORD") { "password"} %>"

Even though ACLs are the preferred method for authentication in Redis 6+, best practice should probably be to use some form of authentication, even in development.

@nickjj
Copy link
Owner

nickjj commented Dec 20, 2022

Yep that's a good idea to document, thanks!

In our case the Docker Compose file doesn't publish any Redis ports so technically Redis is only accessible within the Docker Compose network, but running with no password could be dangerous for folks if they publish - "6379:6379" because then the internet would be able to redis-cli into EXTERNAL_SERVER_IP:6379 freely unless you put a cloud firewall in front of your server to block that port.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants