Skip to content

Commit 0d9053d

Browse files
jmcarpAlice Berard
authored and
Alice Berard
committed
[AIRFLOW-3137] Make ProxyFix middleware optional. (apache#3983)
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`.
1 parent 7676c48 commit 0d9053d

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

airflow/config_templates/default_airflow.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ navbar_color = #007A87
314314
# Default dagrun to show in UI
315315
default_dag_run_display_number = 25
316316

317+
# Enable werkzeug `ProxyFix` middleware
318+
enable_proxy_fix = False
319+
317320

318321
[email]
319322
email_backend = airflow.utils.email.send_email_smtp

airflow/www/app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def create_app(config=None, testing=False):
4747
log = LoggingMixin().log
4848

4949
app = Flask(__name__)
50-
app.wsgi_app = ProxyFix(app.wsgi_app)
50+
if configuration.conf.getboolean('webserver', 'ENABLE_PROXY_FIX'):
51+
app.wsgi_app = ProxyFix(app.wsgi_app)
5152
app.secret_key = configuration.conf.get('webserver', 'SECRET_KEY')
5253
app.config['LOGIN_DISABLED'] = not configuration.conf.getboolean(
5354
'webserver', 'AUTHENTICATE')

airflow/www_rbac/app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
def create_app(config=None, session=None, testing=False, app_name="Airflow"):
4242
global app, appbuilder
4343
app = Flask(__name__)
44-
app.wsgi_app = ProxyFix(app.wsgi_app)
44+
if conf.getboolean('webserver', 'ENABLE_PROXY_FIX'):
45+
app.wsgi_app = ProxyFix(app.wsgi_app)
4546
app.secret_key = conf.get('webserver', 'SECRET_KEY')
4647

4748
airflow_home_path = conf.get('core', 'AIRFLOW_HOME')

docs/integration.rst

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ Your reverse proxy (ex: nginx) should be configured as follow:
6565
}
6666
}
6767

68+
To ensure that Airflow generates URLs with the correct scheme when
69+
running behind a TLS-terminating proxy, you should configure the proxy
70+
to set the `X-Forwarded-Proto` header, and enable the `ProxyFix`
71+
middleware in your `airflow.cfg`::
72+
73+
enable_proxy_fix = True
74+
75+
Note: you should only enable the `ProxyFix` middleware when running
76+
Airflow behind a trusted proxy (AWS ELB, nginx, etc.).
6877

6978
.. _Azure:
7079

0 commit comments

Comments
 (0)