You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by pi...@apache.org on 2023/01/12 00:41:26 UTC

[airflow] branch v2-5-test updated: Fix masking of non-sensitive environment variables (#28802)

This is an automated email from the ASF dual-hosted git repository.

pierrejeambrun pushed a commit to branch v2-5-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v2-5-test by this push:
     new 3543195633 Fix masking of non-sensitive environment variables (#28802)
3543195633 is described below

commit 3543195633c0fcfe613e0aee8a39c0079fcf4952
Author: Ephraim Anierobi <sp...@gmail.com>
AuthorDate: Mon Jan 9 17:43:51 2023 +0100

    Fix masking of non-sensitive environment variables (#28802)
    
    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 0a8d0ab56689c341e65a36c0287c9d635bae1242)
---
 airflow/configuration.py         | 4 ++--
 tests/core/test_configuration.py | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/airflow/configuration.py b/airflow/configuration.py
index 4cea1a53f6..ce55aa45c6 100644
--- a/airflow/configuration.py
+++ b/airflow/configuration.py
@@ -1142,8 +1142,8 @@ class AirflowConfigParser(ConfigParser):
             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:
diff --git a/tests/core/test_configuration.py b/tests/core/test_configuration.py
index 6cbe0e9076..558634de14 100644
--- a/tests/core/test_configuration.py
+++ b/tests/core/test_configuration.py
@@ -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"',
@@ -136,15 +137,16 @@ class TestConf:
         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