Fix secrets masking in Rendered Templates for complex objects#61394
Open
amoghrajesh wants to merge 1 commit intoapache:mainfrom
Open
Fix secrets masking in Rendered Templates for complex objects#61394amoghrajesh wants to merge 1 commit intoapache:mainfrom
amoghrajesh wants to merge 1 commit intoapache:mainfrom
Conversation
Contributor
Author
|
We may be able to get this one in for 3.1.8 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Was generative AI tooling used to co-author this PR?
Problem
Secrets stored in complex objects (e.g., Kubernetes
V1EnvVar, boto3 models) were not masked in the Rendered Templates UI when values contained spaces or exceeded certain lengths.The cause here is that when
_serialize_template_field()encounters non JSON serializable objects, it usesstr()for serialization. Python__repr__for these objects breaks long string values across multiple lines:Now if this value was registered with the masker without new lines in between, redaction wont happen since patterns do not match exactly.
Fix
The fix is to attempt converting such objects to serializable formats by json. To do this, added a
to_serializable()helper function that converts objects with.to_dict()methods (standard in Kubernetes, boto3, and other similar such objects) to plain dictionaries before serialization. Then use json.dumps() instead of str() to produce clean json output.It works because json spec doesn't allow line breaks inside string values and
json.dumps()works on these converted objects. This leads now to secret patterns matching correctly -> masking succeeds.Testing
Use a simple macro like this:
DAG:
Earlier:
Now:
[{"name": "TEST_PHRASE1", "value": "***", "value_from": null}, {"name": "TEST_PHRASE2", "value": "***", "value_from": null}, {"name": "TEST_PHRASE3", "value": "***", "value_from": null}, {"name": "RANDOM_100", "value": "***", "value_from": null}, {"name": "RANDOM_500", "value": "***", "value_from": null}, {"name": "RANDOM_1000", "value": "***", "value_from": null}, {"name": "RANDOM_1500", "value": "***", "value_from": null}, {"name": "RANDOM_2500", "value": "***", "value_from": null}, {"name": "TEST_URL_0", "value": "***", "value_from": null}, {"name": "TEST_URL_1", "value": "***", "value_from": null}, {"name": "TEST_URL_2", "value": "***", "value_from": null}, {"name": "TEST_URL_3", "value": "***", "value_from": null}, {"name": "TEST_URL_4", "value": "***", "value_from": null}, {"name": "TEST_URL_5", "value": "***", "value_from": null}, {"name": "TEST_URL_6", "value": "***", "value_from": null}, {"name": "TEST_URL_7", "value": "***", "value_from": null}, {"name": "TEST_URL_8", "value": "***", "value_from": null}, {"name": "TEST_URL_9", "value": "***", "value_from": null}, {"name": "TEST_URL_10", "value": "***", "value_from": null}, {"name": "TEST_URL_11", "value": "***", "value_from": null}, {"name": "TEST_URL_12", "value": "***", "value_from": null}, {"name": "TEST_URL_13", "value": "***", "value_from": null}, {"name": "TEST_URL_14", "value": "***", "value_from": null}, {"name": "TEST_URL_15", "value": "***", "value_from": null}, {"name": "TEST_URL_16", "value": "***", "value_from": null}, {"name": "TEST_URL_17", "value": "***", "value_from": null}, {"name": "TEST_URL_18", "value": "***", "value_from": null}, {"name": "TEST_URL_19", "value": "***", "value_from": null}, {"name": "TEST_URL_20", "value": "***", "value_from": null}, {"name": "TEST_URL_21", "value": "***", "value_from": null}, {"name": "TEST_URL_22", "value": "***", "value_from": null}, {"name": "TEST_URL_23", "value": "***", "value_from": null}, {"name": "TEST_URL_24", "value": "***", "value_from": null}, {"name": "TEST_URL_25", "value": "***", "value_from": null}, {"name": "TEST_URL_26", "value": "***", "value_from": null}, {"name": "TEST_URL_27", "value": "***", "value_from": null}, {"name": "TEST_URL_28", "value": "***", "value_from": null}, {"name": "TEST_URL_29", "value": "***", "value_from": null}, {"name": "TEST_URL_30", "value": "***", "value_from": null}, {"name": "TEST_URL_31", "value": "***", "value_from": null}, {"name": "TEST_URL_32", "value": "***", "value_from": null}, {"name": "TEST_URL_33", "value": "***", "value_from": null}, {"name": "TEST_URL_34", "value": "***", "value_from": null}, {"name": "TEST_URL_35", "value": "***", "value_from": null}, {"name": "TEST_URL_36", "value": "***", "value_from": null}, {"name": "TEST_URL_37", "value": "***", "value_from": null}, {"name": "TEST_URL_38", "value": "***", "value_from": null}, {"name": "TEST_URL_39", "value": "***", "value_from": null}, {"name": "TEST_URL_40", "value": "***", "value_from": null}, {"name": "TEST_URL_41", "value": "***", "value_from": null}, {"name": "TEST_URL_42", "value": "***", "value_from": null}, {"name": "TEST_URL_43", "value": "***", "value_from": null}, {"name": "TEST_URL_44", "value": "***", "value_from": null}, {"name": "TEST_URL_45", "value": "***", "value_from": null}, {"name": "TEST_URL_46", "value": "***", "value_from": null}, {"name": "TEST_URL_47", "value": "***", "value_from": null}, {"name": "TEST_URL_48", "value": "***", "value_from": null}, {"name": "TEST_URL_49", "value": "***", "value_from": null}]{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.