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

Heroku - Default Redis connection uses TSLS #5500

Closed
sumith opened this issue Oct 29, 2024 · 6 comments · Fixed by #5526
Closed

Heroku - Default Redis connection uses TSLS #5500

sumith opened this issue Oct 29, 2024 · 6 comments · Fixed by #5526

Comments

@sumith
Copy link

sumith commented Oct 29, 2024

What happened?

Heroku is now using default TLS connection for Redis. The current settings parameter only supports non-secure connection.

What should've happened instead?

The settings for production Heroku deployment should default to secure TLS connection using rediss://

Additional details

Adding
broker_use_ssl = {
"cert_reqs": ssl.CERT_NONE,
}
still throws raise ValueError(E_REDIS_SSL_CERT_REQS_MISSING_INVALID)

  • Host system configuration:

    • Version of cookiecutter CLI (get it with cookiecutter --version):

    • OS name and version:

      On Linux, run

      lsb_release -a 2> /dev/null || cat /etc/redhat-release 2> /dev/null || cat /etc/*-release 2> /dev/null || cat /etc/issue 2> /dev/null

      On MacOs, run

      sw_vers

      On Windows, via CMD, run

      systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
      
      # Insert here the OS name and version
      
    • Python version, run python3 -V: 3.11.10

    • Docker version (if using Docker), run docker --version: N/A

    • docker compose version (if using Docker), run docker compose --version:

    • ...

  • Options selected and/or replay file:
    On Linux and macOS: cat ${HOME}/.cookiecutter_replay/cookiecutter-django.json
    (Please, take care to remove sensitive information)

Logs:
$ cookiecutter https://github.com/cookiecutter/cookiecutter-django
project_name [Project Name]: ...
@sumith sumith added the bug label Oct 29, 2024
@qwerrrqw
Copy link
Contributor

qwerrrqw commented Nov 6, 2024

I'm a beginner, but I'm interested in this issue, may i work on this issue?

@dqunbp
Copy link

dqunbp commented Nov 14, 2024

I have fixed the problem with this changes in production.py

REDIS_URL = env("REDIS_TLS_URL")
...
CELERY_REDIS_BACKEND_USE_SSL = {"ssl_cert_reqs": ssl.CERT_NONE}
CELERY_BROKER_USE_SSL = {"ssl_cert_reqs": ssl.CERT_NONE}
REDIS_SSL = env.bool("REDIS_SSL", default=False)
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True

if REDIS_SSL:
    CACHES["default"]["OPTIONS"]["CONNECTION_POOL_CLASS"] = (
        "redis.connection.SSLConnection"
    )
    CACHES["default"]["OPTIONS"]["SSL_CERT_REQS"] = None

@qwerrrqw
Copy link
Contributor

I have fixed the problem with this changes in production.py

REDIS_URL = env("REDIS_TLS_URL")
...
CELERY_REDIS_BACKEND_USE_SSL = {"ssl_cert_reqs": ssl.CERT_NONE}
CELERY_BROKER_USE_SSL = {"ssl_cert_reqs": ssl.CERT_NONE}
REDIS_SSL = env.bool("REDIS_SSL", default=False)
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True

if REDIS_SSL:
    CACHES["default"]["OPTIONS"]["CONNECTION_POOL_CLASS"] = (
        "redis.connection.SSLConnection"
    )
    CACHES["default"]["OPTIONS"]["SSL_CERT_REQS"] = None

Thanks for the suggestion! I'd like to test and implement these changes.
Would it be okay if I add them to PR after testing?

@qwerrrqw
Copy link
Contributor

qwerrrqw commented Nov 15, 2024

``

I have fixed the problem with this changes in production.py

REDIS_URL = env("REDIS_TLS_URL")
...
CELERY_REDIS_BACKEND_USE_SSL = {"ssl_cert_reqs": ssl.CERT_NONE}
CELERY_BROKER_USE_SSL = {"ssl_cert_reqs": ssl.CERT_NONE}
REDIS_SSL = env.bool("REDIS_SSL", default=False)
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True

if REDIS_SSL:
    CACHES["default"]["OPTIONS"]["CONNECTION_POOL_CLASS"] = (
        "redis.connection.SSLConnection"
    )
    CACHES["default"]["OPTIONS"]["SSL_CERT_REQS"] = None
# Redis
# ------------------------------------------------------------------------------
REDIS_URL = env("REDIS_TLS_URL", default="redis://localhost:6379/0")
REDIS_SSL = env.bool("REDIS_SSL", default=False)

# Celery
# ------------------------------------------------------------------------------
CELERY_REDIS_BACKEND_USE_SSL = {"ssl_cert_reqs": ssl.CERT_NONE}
CELERY_BROKER_USE_SSL = {"ssl_cert_reqs": ssl.CERT_NONE}
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True

if REDIS_SSL:
    CACHES["default"]["OPTIONS"].update(
        {
            "CONNECTION_POOL_CLASS": "redis.connection.SSLConnection",
            "SSL_CERT_REQS": None,
        }
    )

From what you suggested, I modified it a little for readability and maintenance
Will it be okay?

@dqunbp
Copy link

dqunbp commented Nov 19, 2024

@qwerrrqw Sorry, these settings work partially; they do not work with Redis caches.
These are my final edits inspired by Heroku docs: https://devcenter.heroku.com/articles/connecting-heroku-redis#using-the-built-in-redis-backend-support.
They work for Celery and Django's built-in Redis cache.

REDIS_URL = env("REDIS_TLS_URL")
CELERY_REDIS_BACKEND_USE_SSL = {"ssl_cert_reqs": ssl.CERT_NONE}
CELERY_BROKER_USE_SSL = {"ssl_cert_reqs": ssl.CERT_NONE}
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True

# CACHES
# ------------------------------------------------------------------------------
CACHES = {
    "default": {
        "BACKEND": "django.core.cache.backends.redis.RedisCache",
        "LOCATION": REDIS_URL,
        "OPTIONS": {"ssl_cert_reqs": None},
    },
}

@nigfinch
Copy link

My Heroku celery scheduled tasks stopped working on October 14th ~ 5am
This was in the Heroku activity log:

heroku-redis: Update REDIS by heroku-redis
Oct 14 at 6:00 AM · v308

Is there any official fix ?
Thanks

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

Successfully merging a pull request may close this issue.

6 participants
@browniebroke @sumith @nigfinch @dqunbp @qwerrrqw and others