Skip to content

Commit c2e5bde

Browse files
pratyush0325potiukBasPH
authored
Treat non-sensitive-only as true and always mask sensitive values in public api's (#59880)
* Treat non-sensitive-only as true and always mask sensitive values in public APIs. * Add newsfragment and update docs and client references for config masking * newline error fixed - config.yml * Update clients/python/README.md Co-authored-by: Bas Harenslak <[email protected]> * CI image check resolved * newline error in config.py fixed --------- Co-authored-by: Jarek Potiuk <[email protected]> Co-authored-by: Bas Harenslak <[email protected]>
1 parent c865dde commit c2e5bde

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Always mask sensitive configuration values in public config APIs and treat the deprecated ``non-sensitive-only`` value as ``True``.

airflow-core/src/airflow/api_fastapi/core_api/services/public/config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# under the License.
1717
from __future__ import annotations
1818

19+
import warnings
20+
1921
from fastapi import HTTPException, status
2022
from 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(

airflow-core/src/airflow/config_templates/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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: ~

airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
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
}
6262
MOCK_CONFIG_DICT_SENSITIVE_HIDDEN = {
@@ -102,7 +102,7 @@
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
],

clients/python/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

clients/python/test_python_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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()

0 commit comments

Comments
 (0)