diff --git a/caravel/__init__.py b/caravel/__init__.py index 97bd567f7ac1..b01a8e59cf10 100644 --- a/caravel/__init__.py +++ b/caravel/__init__.py @@ -14,6 +14,7 @@ from flask_appbuilder.baseviews import expose from flask_cache import Cache from flask_migrate import Migrate +from werkzeug.contrib.fixers import ProxyFix APP_DIR = os.path.dirname(__file__) @@ -77,6 +78,9 @@ def checkout(dbapi_con, con_record, con_proxy): from flask_cors import CORS CORS(app, **app.config.get('CORS_OPTIONS')) +if app.config.get('ENABLE_PROXY_FIX'): + app.wsgi_app = ProxyFix(app.wsgi_app) + class MyIndexView(IndexView): @expose('/') diff --git a/caravel/config.py b/caravel/config.py index 46eb55936f8e..b2bcb3d929d8 100644 --- a/caravel/config.py +++ b/caravel/config.py @@ -56,6 +56,9 @@ # Whether to show the stacktrace on 500 error SHOW_STACKTRACE = True +# Extract and use X-Forwarded-For/X-Forwarded-Proto headers? +ENABLE_PROXY_FIX = False + # ------------------------------ # GLOBALS FOR APP Builder # ------------------------------ diff --git a/docs/installation.rst b/docs/installation.rst index 0d94baa7f5e3..83e5856a9636 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -108,6 +108,10 @@ load balancer knows if your caravel instance is running. This is provided at ``/health`` which will return a 200 response containing "OK" if the webserver is running. +If the load balancer is inserting X-Forwarded-For/X-Forwarded-Proto headers, you +should set `ENABLE_PROXY_FIX = True` in the caravel config file to extract and use +the headers. + Configuration -------------