-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Add option to mask sensitive data in UI configuration page #25346
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6929c68
Add option to mask sensitive data in UI configuration page
ephraimbuddy 465dd2e
Add more tests
ephraimbuddy 54c5269
Add comment that the sensitive keys are marked wherever they are found
ephraimbuddy 1a8ca7c
make display_sensitive work for sources config
ephraimbuddy 2a8f524
String the values to avoid url quoting
ephraimbuddy dfc7c0b
cmd/secret env should not be hidden in include_env but in include_cmd…
ephraimbuddy 0d1476b
apply suggestion from code review
ephraimbuddy 07f1a77
test config with cmd and hide source sensitive values
ephraimbuddy 15c3746
Add test for secrets backend
ephraimbuddy 4a1573e
Explicitly hide the sensitive values
ephraimbuddy 5762251
Escape html in value to compare item in resp
ephraimbuddy 715f523
improve test
ephraimbuddy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It's needed because an example of postgresql connection string was used in the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we should make the test better.
Instead of:
something like this should test that the value isn't showing in the running config section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added another test instead of removing this one because we also hide those in source files