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 support ssl connections to redis #3848

Merged
merged 7 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion redash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ def create_redis_connection():

client = redis.StrictRedis(unix_socket_path=redis_url.path, db=db)
else:
use_ssl = redis_url.scheme == 'rediss'

if redis_url.path:
redis_db = redis_url.path[1]
else:
redis_db = 0
# Redis passwords might be quoted with special characters
redis_password = redis_url.password and urllib.unquote(redis_url.password)
client = redis.StrictRedis(host=redis_url.hostname, port=redis_url.port, db=redis_db, password=redis_password)
client = redis.StrictRedis(
host=redis_url.hostname, port=redis_url.port, db=redis_db, password=redis_password,
ssl=use_ssl)

return client

Expand Down
8 changes: 8 additions & 0 deletions redash/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import importlib
import ssl
from funcy import distinct, remove
from flask_talisman import talisman

Expand Down Expand Up @@ -30,6 +31,13 @@
CELERY_RESULT_EXPIRES = int(os.environ.get(
"REDASH_CELERY_RESULT_EXPIRES",
os.environ.get("REDASH_CELERY_TASK_RESULT_EXPIRES", 3600 * 4)))
CELERY_BROKER_USE_SSL = CELERY_BROKER.startswith('rediss')
CELERY_SSL_CONFIG = {
Copy link
Contributor Author

@nason nason Jun 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rauchy thank you for the feedback! How does this look as far as settings now?

I'll try this change out on our self-hosted setup later today

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Settings look fine to me. However, the build is failing and requires your attention.

'ssl_cert_reqs': int(os.environ.get("REDASH_CELERY_BROKER_SSL_CERT_REQS", ssl.CERT_OPTIONAL)),
'ssl_ca_certs': os.environ.get("REDASH_CELERY_BROKER_SSL_CA_CERTS"),
'ssl_certfile': os.environ.get("REDASH_CELERY_BROKER_SSL_CERTFILE"),
'ssl_keyfile': os.environ.get("REDASH_CELERY_BROKER_SSL_KEYFILE"),
} if CELERY_BROKER_USE_SSL else None

# The following enables periodic job (every 5 minutes) of removing unused query results.
QUERY_RESULTS_CLEANUP_ENABLED = parse_boolean(os.environ.get("REDASH_QUERY_RESULTS_CLEANUP_ENABLED", "true"))
Expand Down
3 changes: 2 additions & 1 deletion redash/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
from redash import create_app, extensions, settings
from redash.metrics import celery as celery_metrics # noqa


logger = get_logger(__name__)


celery = Celery('redash',
broker=settings.CELERY_BROKER,
broker_use_ssl=settings.CELERY_SSL_CONFIG,
redis_backend_use_ssl=settings.CELERY_SSL_CONFIG,
include='redash.tasks')

# The internal periodic Celery tasks to automatically schedule.
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ psycopg2==2.7.3.2
python-dateutil==2.7.5
pytz==2016.7
PyYAML==3.12
redis==3.0.1
redis==3.2.1
requests==2.21.0
six==1.11.0
SQLAlchemy==1.2.12
Expand All @@ -36,8 +36,8 @@ SQLAlchemy-Utils==0.33.11
sqlparse==0.2.4
statsd==2.1.2
gunicorn==19.7.1
celery==4.2.1
kombu==4.2.2.post1
celery==4.3.0
kombu==4.5.0
jsonschema==2.4.0
RestrictedPython==3.6.0
pysaml2==4.5.0
Expand Down