Skip to content

Commit 456dada

Browse files
committed
Merge pull request #1530 from mattuuh7/hidden-fields
2 parents 7332c40 + 3e30941 commit 456dada

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

airflow/configuration.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ def run_command(command):
156156
},
157157
'github_enterprise': {
158158
'api_rev': 'v3'
159-
}
159+
},
160+
'admin': {
161+
'hide_sensitive_variable_fields': True,
162+
},
160163
}
161164

162165
DEFAULT_CONFIG = """\
@@ -386,6 +389,10 @@ def run_command(command):
386389
# default_principal = admin
387390
# default_secret = admin
388391
392+
[admin]
393+
# UI to hide sensitive variable fields when set to True
394+
hide_sensitive_variable_fields = True
395+
389396
"""
390397

391398
TEST_CONFIG = """\

airflow/www/views.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@
8282
logout_user = airflow.login.logout_user
8383

8484
FILTER_BY_OWNER = False
85+
86+
DEFAULT_SENSITIVE_VARIABLE_FIELDS = (
87+
'password',
88+
'secret',
89+
'passwd',
90+
'authorization',
91+
'api_key',
92+
'apikey',
93+
'access_token',
94+
)
95+
8596
if conf.getboolean('webserver', 'FILTER_BY_OWNER'):
8697
# filter_by_owner if authentication is enabled and filter_by_owner is true
8798
FILTER_BY_OWNER = not current_app.config['LOGIN_DISABLED']
@@ -265,6 +276,11 @@ def recurse_tasks(tasks, task_ids, dag_ids, task_id_to_dag):
265276
task_id_to_dag[tasks.task_id] = tasks.dag
266277

267278

279+
def should_hide_value_for_key(key_name):
280+
return any(s in key_name for s in DEFAULT_SENSITIVE_VARIABLE_FIELDS) \
281+
and conf.getboolean('admin', 'hide_sensitive_variable_fields')
282+
283+
268284
class Airflow(BaseView):
269285

270286
def is_visible(self):
@@ -2015,11 +2031,17 @@ class DagPickleView(SuperUserMixin, ModelView):
20152031
class VariableView(wwwutils.LoginMixin, AirflowModelView):
20162032
verbose_name = "Variable"
20172033
verbose_name_plural = "Variables"
2034+
2035+
def hidden_field_formatter(view, context, model, name):
2036+
if should_hide_value_for_key(model.key):
2037+
return Markup('*' * 8)
2038+
return getattr(model, name)
2039+
20182040
form_columns = (
20192041
'key',
20202042
'val',
20212043
)
2022-
column_list = ('key', 'is_encrypted',)
2044+
column_list = ('key', 'val', 'is_encrypted',)
20232045
column_filters = ('key', 'val')
20242046
column_searchable_list = ('key', 'val')
20252047
form_widget_args = {
@@ -2028,6 +2050,18 @@ class VariableView(wwwutils.LoginMixin, AirflowModelView):
20282050
'rows': 20,
20292051
}
20302052
}
2053+
column_sortable_list = (
2054+
'key',
2055+
'val',
2056+
'is_encrypted',
2057+
)
2058+
column_formatters = {
2059+
'val': hidden_field_formatter
2060+
}
2061+
2062+
def on_form_prefill(self, form, id):
2063+
if should_hide_value_for_key(form.key.data):
2064+
form.val.data = '*' * 8
20312065

20322066

20332067
class JobModelView(ModelViewOnly):

docs/img/variable_hidden.png

151 KB
Loading

docs/ui.rst

+13
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ dependencies and their current status for a specific run.
4141

4242
------------
4343

44+
Variable View
45+
.............
46+
The variable view allows you to list, create, edit or delete the key-value pair
47+
of a variable used during jobs. Value of a variable will be hidden if the key contains
48+
any words in ('password', 'secret', 'passwd', 'authorization', 'api_key', 'apikey', 'access_token')
49+
by default, but can be configured to show in clear-text.
50+
51+
------------
52+
53+
.. image:: img/variable_hidden.png
54+
55+
------------
56+
4457
Gantt Chart
4558
...........
4659
The Gantt chart lets you analyse task duration and overlap. You can quickly

0 commit comments

Comments
 (0)