File tree Expand file tree Collapse file tree 6 files changed +19
-8
lines changed
api_fastapi/core_api/services/public
tests/unit/api_fastapi/core_api/routes/public Expand file tree Collapse file tree 6 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 1+ Always mask sensitive configuration values in public config APIs and treat the deprecated ``non-sensitive-only `` value as ``True ``.
Original file line number Diff line number Diff line change 1616# under the License.
1717from __future__ import annotations
1818
19+ import warnings
20+
1921from fastapi import HTTPException , status
2022from fastapi .responses import Response
2123
@@ -29,9 +31,15 @@ def _check_expose_config() -> bool:
2931 if conf .get ("api" , "expose_config" ).lower () == "non-sensitive-only" :
3032 expose_config = True
3133 display_sensitive = False
34+ warnings .warn (
35+ "The value 'non-sensitive-only' for [api] expose_config is deprecated. "
36+ "Use 'true' instead; sensitive configuration values are always masked." ,
37+ DeprecationWarning ,
38+ stacklevel = 2 ,
39+ )
3240 else :
3341 expose_config = conf .getboolean ("api" , "expose_config" )
34- display_sensitive = True
42+ display_sensitive = False
3543
3644 if not expose_config :
3745 raise HTTPException (
Original file line number Diff line number Diff line change @@ -1443,9 +1443,9 @@ api:
14431443 default : " {SECRET_KEY}"
14441444 expose_config :
14451445 description : |
1446- Expose the configuration file in the web server. Set to ``non-sensitive-only `` to show all values
1447- except those that have security implications. ``True`` shows all values. ``False `` hides the
1448- configuration completely.
1446+ Expose the configuration file in the web server. Set to ``True `` to expose configuration with
1447+ sensitive values always masked. The deprecated value ``non-sensitive-only `` is treated the same as
1448+ ``True`` for backward compatibility. ``False`` hides the configuration completely.
14491449 version_added : ~
14501450 type : string
14511451 example : ~
Original file line number Diff line number Diff line change 5656 OPTION_KEY_SMTP_MAIL_FROM : OPTION_VALUE_SMTP_MAIL_FROM ,
5757 },
5858 SECTION_DATABASE : {
59- OPTION_KEY_SQL_ALCHEMY_CONN : OPTION_VALUE_SQL_ALCHEMY_CONN ,
59+ OPTION_KEY_SQL_ALCHEMY_CONN : OPTION_VALUE_SENSITIVE_HIDDEN ,
6060 },
6161}
6262MOCK_CONFIG_DICT_SENSITIVE_HIDDEN = {
102102 {
103103 "name" : SECTION_DATABASE ,
104104 "options" : [
105- {"key" : OPTION_KEY_SQL_ALCHEMY_CONN , "value" : OPTION_VALUE_SQL_ALCHEMY_CONN },
105+ {"key" : OPTION_KEY_SQL_ALCHEMY_CONN , "value" : OPTION_VALUE_SENSITIVE_HIDDEN },
106106 ],
107107 },
108108 ],
@@ -206,7 +206,7 @@ class TestGetConfig(TestConfigEndpoint):
206206 { OPTION_KEY_SMTP_MAIL_FROM } = { OPTION_VALUE_SMTP_MAIL_FROM }
207207
208208 [{ SECTION_DATABASE } ]
209- { OPTION_KEY_SQL_ALCHEMY_CONN } = { OPTION_VALUE_SQL_ALCHEMY_CONN }
209+ { OPTION_KEY_SQL_ALCHEMY_CONN } = { OPTION_VALUE_SENSITIVE_HIDDEN }
210210 """
211211 ),
212212 ),
@@ -252,7 +252,7 @@ class TestGetConfig(TestConfigEndpoint):
252252 {
253253 "name" : SECTION_DATABASE ,
254254 "options" : [
255- {"key" : OPTION_KEY_SQL_ALCHEMY_CONN , "value" : OPTION_VALUE_SQL_ALCHEMY_CONN },
255+ {"key" : OPTION_KEY_SQL_ALCHEMY_CONN , "value" : OPTION_VALUE_SENSITIVE_HIDDEN },
256256 ],
257257 },
258258 ],
Original file line number Diff line number Diff line change @@ -630,6 +630,7 @@ You can also set it by env variable: `export AIRFLOW__CORE__LOAD_EXAMPLES=True`
630630
631631* optionally expose configuration (NOTE! that this is dangerous setting). The script will happily run with
632632 the default setting, but if you want to see the configuration, you need to expose it.
633+ Note that sensitive configuration values are always masked.
633634 In the ` [api] ` section of your ` airflow.cfg ` set:
634635
635636``` ini
Original file line number Diff line number Diff line change @@ -121,6 +121,7 @@ def test_python_client():
121121
122122 # Get current configuration. Note, this is disabled by default with most installation.
123123 # You need to set `expose_config = True` in Airflow configuration in order to retrieve configuration.
124+ # Sensitive configuration values are always masked in the response.
124125 conf_api_instance = config_api .ConfigApi (api_client )
125126 try :
126127 api_response = conf_api_instance .get_config ()
You can’t perform that action at this time.
0 commit comments