-
Notifications
You must be signed in to change notification settings - Fork 16.7k
[v3-1-test] Prevent client secrets and proxy credentials from being logged in Microsoft Graph hook logs (#59688) #59792
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
potiuk
merged 1 commit into
apache:v3-1-test
from
astronomer:backport-a9dea6d-v3-1-test
Dec 25, 2025
Merged
[v3-1-test] Prevent client secrets and proxy credentials from being logged in Microsoft Graph hook logs (#59688) #59792
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions
airflow-core/newsfragments/59688.improvement.rst
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 @@ | ||
| Add ``proxy`` and ``proxies`` to ``DEFAULT_SENSITIVE_FIELDS`` in secrets_masker to treat proxy configurations as sensitive by default |
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 |
|---|---|---|
|
|
@@ -63,6 +63,8 @@ | |
|
|
||
| from airflow.models import Connection | ||
|
|
||
| from airflow_shared.secrets_masker import redact | ||
|
|
||
|
|
||
| class DefaultResponseHandler(ResponseHandler): | ||
| """DefaultResponseHandler returns JSON payload or content in bytes or response headers.""" | ||
|
|
@@ -272,16 +274,16 @@ def _build_request_adapter(self, connection) -> tuple[str, RequestAdapter]: | |
| self.log.info("Host: %s", host) | ||
| self.log.info("Base URL: %s", base_url) | ||
| self.log.info("Client id: %s", client_id) | ||
| self.log.info("Client secret: %s", client_secret) | ||
| self.log.info("Client secret: %s", redact(client_secret, name="client_secret")) | ||
| self.log.info("API version: %s", api_version) | ||
| self.log.info("Scope: %s", scopes) | ||
| self.log.info("Verify: %s", verify) | ||
| self.log.info("Timeout: %s", self.timeout) | ||
| self.log.info("Trust env: %s", trust_env) | ||
| self.log.info("Authority: %s", authority) | ||
| self.log.info("Allowed hosts: %s", allowed_hosts) | ||
| self.log.info("Proxies: %s", proxies) | ||
| self.log.info("HTTPX Proxies: %s", httpx_proxies) | ||
| self.log.info("Proxies: %s", redact(proxies, name="proxies")) | ||
| self.log.info("HTTPX Proxies: %s", redact(httpx_proxies, name="proxies")) | ||
| credentials = self.get_credentials( | ||
| login=connection.login, | ||
| password=connection.password, | ||
|
|
@@ -391,7 +393,7 @@ def get_credentials( | |
| self.log.info("Certificate data: %s", certificate_data is not None) | ||
| self.log.info("Authority: %s", authority) | ||
| self.log.info("Disable instance discovery: %s", disable_instance_discovery) | ||
| self.log.info("MSAL Proxies: %s", msal_proxies) | ||
| self.log.info("MSAL Proxies: %s", redact(msal_proxies, name="proxies")) | ||
| if certificate_path or certificate_data: | ||
| return CertificateCredential( | ||
| tenant_id=tenant_id, | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -387,6 +387,27 @@ async def test_throw_failed_responses_with_application_json_content_type(self): | |
| error_code = actual.get_child_node("error").get_child_node("code").get_str_value() | ||
| assert error_code == "TenantThrottleThresholdExceeded" | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_build_request_adapter_masks_secrets(self): | ||
| """Test that sensitive data is masked when building request adapter.""" | ||
| with patch( | ||
| f"{BASEHOOK_PATCH_PATH}.get_connection", | ||
| side_effect=lambda conn_id: get_airflow_connection( | ||
| conn_id=conn_id, | ||
| password="my_secret_password", | ||
| proxies={"http": "http://user:pass@proxy:3128"}, | ||
| ), | ||
| ): | ||
| with patch("airflow.providers.microsoft.azure.hooks.msgraph.redac t") as mock_redact: | ||
| mock_redact.side_effect = lambda x, name=None: "***" if x else x | ||
|
|
||
| hook = KiotaRequestAdapterHook(conn_id="msgraph_api") | ||
| await hook.get_async_conn() | ||
|
|
||
| assert mock_redact.call_count >= 3 | ||
| mock_redact.assert_any_call({"http": "http://user:pass@proxy:3128"}, name="proxies") | ||
| mock_redact.assert_any_call("my_secret_password", name="client_secret") | ||
|
|
||
|
|
||
| class TestResponseHandler: | ||
| def test_default_response_handler_when_json(self): | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -58,6 +58,8 @@ def to_dict(self) -> dict[str, Any]: ... | |
| "passwd", | ||
| "password", | ||
| "private_key", | ||
| "proxy", | ||
| "proxies", | ||
| "secret", | ||
| "token", | ||
| "keyfile_dict", | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -36,12 +36,10 @@ | |
| from airflow.sdk.types import Logger, RuntimeTaskInstanceProtocol as RuntimeTI | ||
|
|
||
|
|
||
| __all__ = ["configure_logging", "reset_logging", "mask_secret"] | ||
| from airflow.sdk._shared.secrets_masker import redact | ||
|
|
||
|
|
||
| def mask_logs(logger: Any, method_name: str, event_dict: EventDict) -> EventDict: | ||
| from airflow.sdk._shared.secrets_masker import redact | ||
|
|
||
| event_dict = redact(event_dict) # type: ignore[assignment] | ||
| return event_dict | ||
|
|
||
|
|
||
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.