Skip to content

Commit

Permalink
[AIRFLOW-3137] Make ProxyFix middleware optional.
Browse files Browse the repository at this point in the history
The ProxyFix middleware should only be used when airflow is running
behind a trusted proxy. This patch adds a `USE_PROXY_FIX` flag that
defaults to `False`.
  • Loading branch information
jmcarp committed Oct 2, 2018
1 parent c7be7af commit 96c8e5b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions airflow/config_templates/default_airflow.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ navbar_color = #007A87
# Default dagrun to show in UI
default_dag_run_display_number = 25

# Enable werkzeug `ProxyFix` middleware
enable_proxy_fix = False


[email]
email_backend = airflow.utils.email.send_email_smtp
Expand Down
3 changes: 2 additions & 1 deletion airflow/www/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def create_app(config=None, testing=False):
log = LoggingMixin().log

app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)
if configuration.conf.getboolean('webserver', 'ENABLE_PROXY_FIX'):
app.wsgi_app = ProxyFix(app.wsgi_app)
app.secret_key = configuration.conf.get('webserver', 'SECRET_KEY')
app.config['LOGIN_DISABLED'] = not configuration.conf.getboolean(
'webserver', 'AUTHENTICATE')
Expand Down
3 changes: 2 additions & 1 deletion airflow/www_rbac/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
def create_app(config=None, session=None, testing=False, app_name="Airflow"):
global app, appbuilder
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)
if conf.getboolean('webserver', 'ENABLE_PROXY_FIX'):
app.wsgi_app = ProxyFix(app.wsgi_app)
app.secret_key = conf.get('webserver', 'SECRET_KEY')

airflow_home_path = conf.get('core', 'AIRFLOW_HOME')
Expand Down
9 changes: 9 additions & 0 deletions docs/integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ Your reverse proxy (ex: nginx) should be configured as follow:
}
}

To ensure that Airflow generates URLs with the correct scheme when
running behind a TLS-terminating proxy, you should configure the proxy
to set the `X-Forwarded-Proto` header, and enable the `ProxyFix`
middleware in your `airflow.cfg`::

enable_proxy_fix = True

Note: you should only enable the `ProxyFix` middleware when running
Airflow behind a trusted proxy (AWS ELB, nginx, etc.).

.. _Azure:

Expand Down

0 comments on commit 96c8e5b

Please sign in to comment.