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

AIRFLOW-45: Support Hidden Airflow Variables #1530

Merged
merged 1 commit into from
May 25, 2016
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
9 changes: 8 additions & 1 deletion airflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ def run_command(command):
},
'github_enterprise': {
'api_rev': 'v3'
}
},
'admin': {
'hide_sensitive_variable_fields': True,
},
}

DEFAULT_CONFIG = """\
Expand Down Expand Up @@ -386,6 +389,10 @@ def run_command(command):
# default_principal = admin
# default_secret = admin

[admin]
# UI to hide sensitive variable fields when set to True
hide_sensitive_variable_fields = True

"""

TEST_CONFIG = """\
Expand Down
36 changes: 35 additions & 1 deletion airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@
logout_user = airflow.login.logout_user

FILTER_BY_OWNER = False

DEFAULT_SENSITIVE_VARIABLE_FIELDS = (
'password',
'secret',
'passwd',
'authorization',
'api_key',
'apikey',
'access_token',
)

if conf.getboolean('webserver', 'FILTER_BY_OWNER'):
# filter_by_owner if authentication is enabled and filter_by_owner is true
FILTER_BY_OWNER = not current_app.config['LOGIN_DISABLED']
Expand Down Expand Up @@ -265,6 +276,11 @@ def recurse_tasks(tasks, task_ids, dag_ids, task_id_to_dag):
task_id_to_dag[tasks.task_id] = tasks.dag


def should_hide_value_for_key(key_name):
return any(s in key_name for s in DEFAULT_SENSITIVE_VARIABLE_FIELDS) \
and conf.getboolean('admin', 'hide_sensitive_variable_fields')


class Airflow(BaseView):

def is_visible(self):
Expand Down Expand Up @@ -2015,11 +2031,17 @@ class DagPickleView(SuperUserMixin, ModelView):
class VariableView(wwwutils.LoginMixin, AirflowModelView):
verbose_name = "Variable"
verbose_name_plural = "Variables"

def hidden_field_formatter(view, context, model, name):
if should_hide_value_for_key(model.key):
return Markup('*' * 8)
return getattr(model, name)

form_columns = (
'key',
'val',
)
column_list = ('key', 'is_encrypted',)
column_list = ('key', 'val', 'is_encrypted',)
column_filters = ('key', 'val')
column_searchable_list = ('key', 'val')
form_widget_args = {
Expand All @@ -2028,6 +2050,18 @@ class VariableView(wwwutils.LoginMixin, AirflowModelView):
'rows': 20,
}
}
column_sortable_list = (
'key',
'val',
'is_encrypted',
)
column_formatters = {
'val': hidden_field_formatter
}

def on_form_prefill(self, form, id):
if should_hide_value_for_key(form.key.data):
form.val.data = '*' * 8


class JobModelView(ModelViewOnly):
Expand Down
Binary file added docs/img/variable_hidden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions docs/ui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ dependencies and their current status for a specific run.

------------

Variable View
.............
The variable view allows you to list, create, edit or delete the key-value pair
of a variable used during jobs. Value of a variable will be hidden if the key contains
any words in ('password', 'secret', 'passwd', 'authorization', 'api_key', 'apikey', 'access_token')
by default, but can be configured to show in clear-text.

------------

.. image:: img/variable_hidden.png

------------

Gantt Chart
...........
The Gantt chart lets you analyse task duration and overlap. You can quickly
Expand Down