Skip to content

Commit

Permalink
Fix masking of non-sensitive environment variables (#28802)
Browse files Browse the repository at this point in the history
Environment variables are hidden even when we set expose-config to non-sensitive-only.
This PR changes it to work like every other source, the items are only
hidden when they are sensitive

(cherry picked from commit 0a8d0ab)
  • Loading branch information
ephraimbuddy committed Jan 12, 2023
1 parent 292592c commit 7b3d591
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions airflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,8 +1142,8 @@ def _include_envs(
if not display_sensitive and env_var != self._env_var_name("core", "unit_test_mode"):
# Don't hide cmd/secret values here
if not env_var.lower().endswith("cmd") and not env_var.lower().endswith("secret"):
opt = "< hidden >"

if (section, key) in self.sensitive_config_values:
opt = "< hidden >"
elif raw:
opt = opt.replace("%", "%%")
if display_source:
Expand Down
8 changes: 5 additions & 3 deletions tests/core/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def restore_env():
"os.environ",
{
"AIRFLOW__TESTSECTION__TESTKEY": "testvalue",
"AIRFLOW__CORE__FERNET_KEY": "testvalue",
"AIRFLOW__TESTSECTION__TESTPERCENT": "with%percent",
"AIRFLOW__TESTCMDENV__ITSACOMMAND_CMD": 'echo -n "OK"',
"AIRFLOW__TESTCMDENV__NOTACOMMAND_CMD": 'echo -n "NOT OK"',
Expand Down Expand Up @@ -136,15 +137,16 @@ def test_conf_as_dict(self):
assert cfg_dict["core"]["percent"] == "with%inside"

# test env vars
assert cfg_dict["testsection"]["testkey"] == "< hidden >"
assert cfg_dict["kubernetes_environment_variables"]["AIRFLOW__TESTSECTION__TESTKEY"] == "< hidden >"
assert cfg_dict["testsection"]["testkey"] == "testvalue"
assert cfg_dict["kubernetes_environment_variables"]["AIRFLOW__TESTSECTION__TESTKEY"] == "nested"

def test_conf_as_dict_source(self):
# test display_source
cfg_dict = conf.as_dict(display_source=True)
assert cfg_dict["core"]["load_examples"][1] == "airflow.cfg"
assert cfg_dict["database"]["load_default_connections"][1] == "airflow.cfg"
assert cfg_dict["testsection"]["testkey"] == ("< hidden >", "env var")
assert cfg_dict["testsection"]["testkey"] == ("testvalue", "env var")
assert cfg_dict["core"]["fernet_key"] == ("< hidden >", "env var")

def test_conf_as_dict_sensitive(self):
# test display_sensitive
Expand Down

0 comments on commit 7b3d591

Please sign in to comment.