forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to mask sensitive data in UI configuration page (apache#25346
) * Add option to mask sensitive data in UI configuration page This PR adds an option to mask sensitive data in the UI configuration page, making it possible to view the page with redated data
- Loading branch information
1 parent
c587831
commit 283b3d2
Showing
5 changed files
with
177 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import html | ||
|
||
from airflow.configuration import SENSITIVE_CONFIG_VALUES, conf | ||
from tests.test_utils.config import conf_vars | ||
from tests.test_utils.www import check_content_in_response, check_content_not_in_response | ||
|
||
|
||
@conf_vars({("webserver", "expose_config"): 'False'}) | ||
def test_user_cant_view_configuration(admin_client): | ||
resp = admin_client.get('configuration', follow_redirects=True) | ||
check_content_in_response( | ||
"Your Airflow administrator chose not to expose the configuration, " | ||
"most likely for security reasons.", | ||
resp, | ||
) | ||
|
||
|
||
@conf_vars({("webserver", "expose_config"): 'True'}) | ||
def test_user_can_view_configuration(admin_client): | ||
resp = admin_client.get('configuration', follow_redirects=True) | ||
for section, key in SENSITIVE_CONFIG_VALUES: | ||
value = conf.get(section, key, fallback='') | ||
if not value: | ||
continue | ||
check_content_in_response(html.escape(value), resp) | ||
|
||
|
||
@conf_vars({("webserver", "expose_config"): 'non-sensitive-only'}) | ||
def test_configuration_redacted(admin_client): | ||
resp = admin_client.get('configuration', follow_redirects=True) | ||
for section, key in SENSITIVE_CONFIG_VALUES: | ||
value = conf.get(section, key, fallback='') | ||
if not value or value == 'airflow': | ||
continue | ||
if value.startswith('db+postgresql'): # this is in configuration comment | ||
continue | ||
check_content_not_in_response(value, resp) | ||
|
||
|
||
@conf_vars({("webserver", "expose_config"): 'non-sensitive-only'}) | ||
def test_configuration_redacted_in_running_configuration(admin_client): | ||
resp = admin_client.get('configuration', follow_redirects=True) | ||
for section, key in SENSITIVE_CONFIG_VALUES: | ||
value = conf.get(section, key, fallback='') | ||
if not value or value == 'airflow': | ||
continue | ||
check_content_not_in_response("<td class='code'>" + html.escape(value) + '</td', resp) | ||
|
||
|
||
@conf_vars({("webserver", "expose_config"): 'non-sensitive-only'}) | ||
@conf_vars({("database", "# sql_alchemy_conn"): 'testconn'}) | ||
@conf_vars({("core", " # secret_key"): 'core_secret'}) | ||
@conf_vars({("core", "fernet_key"): 'secret_fernet_key'}) | ||
def test_commented_out_config(admin_client): | ||
resp = admin_client.get('configuration', follow_redirects=True) | ||
check_content_in_response("testconn", resp) | ||
check_content_in_response("core_secret", resp) | ||
check_content_not_in_response("secret_fernet_key", resp) |