Skip to content
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

Secret masker ignores passwords with special chars #36692

Merged
merged 3 commits into from
Jan 29, 2024
Merged

Conversation

aritra24
Copy link
Collaborator

@aritra24 aritra24 commented Jan 9, 2024

Connection uri's get connection uses quote to change the password and certain other fields to escape special chars due to this, when the connection object is passed through the masker this changed string is skipped.

closes: #36688


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@aritra24
Copy link
Collaborator Author

aritra24 commented Jan 9, 2024

Wasn't entirely sure how to add testing for this since it needs to pass through the masker? 🤔 If anyone has ideas let me know. Nvm, I think the tests do already test for this, they just didn't have any special chars. I've added special chars into a few of them.

Copy link
Member

@hussein-awala hussein-awala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I duplicated the updated tests on the main branch, and they passed without your change. Could you check if your change is really necessary, or you need to create a new test that fail on main and works with your change?

@aritra24
Copy link
Collaborator Author

@hussein-awala I see the test failing on main

=========================== short test summary info ============================
FAILED tests/always/test_connection.py::TestConnection::test_masking_from_db - AssertionError: assert equals failed
                                   [
                                     call('s3cr3t!'),
                                     call('s3cr3t%21'),
  [call('s3cr3t!'), call({'apikey    call({'apikey': 'masked too'}
  ': 'masked too'})]               ),
                                   ]
======================= 1 failed, 13 warnings in 20.21s ========================

@aritra24
Copy link
Collaborator Author

@hussein-awala could I get a re-review on this.

@hussein-awala
Copy link
Member

@hussein-awala I see the test failing on main

=========================== short test summary info ============================
FAILED tests/always/test_connection.py::TestConnection::test_masking_from_db - AssertionError: assert equals failed
                                   [
                                     call('s3cr3t!'),
                                     call('s3cr3t%21'),
  [call('s3cr3t!'), call({'apikey    call({'apikey': 'masked too'}
  ': 'masked too'})]               ),
                                   ]
======================= 1 failed, 13 warnings in 20.21s ========================

That's because you check if the mock is called with quote method, which is not currently the case.

Could you add a test that checks if the final result is correct?

@aritra24
Copy link
Collaborator Author

aritra24 commented Jan 17, 2024

Added a secret_masker test which tests that the logs do get redacted. @hussein-awala if you could re-review.

@aritra24 aritra24 requested a review from potiuk January 17, 2024 11:26
@amoghrajesh
Copy link
Contributor

@aritra24 I personally think this should be the case by design, aligning with the postgres documentation too.
Check my comment: #36688 (comment)

cc @hussein-awala

@aritra24
Copy link
Collaborator Author

@amoghrajesh made a comment on the issue. Could you take a look again?

@potiuk potiuk added this to the Airflow 2.8.2 milestone Jan 20, 2024
tests/utils/log/test_secrets_masker.py Outdated Show resolved Hide resolved
Connection uri's get connection uses quote to change the
password and certain other fields to escape special chars
due to this, when the connection object is passed through
the masker this changed string is skipped.
Copy link
Contributor

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes, @aritra24
LGTM +1

tests/utils/log/test_secrets_masker.py Show resolved Hide resolved
@potiuk
Copy link
Member

potiuk commented Jan 21, 2024

@hussein-awala - I run the tests in main now and they nicely fail there. I think this one is ready to go.

@amoghrajesh
Copy link
Contributor

Ping @hussein-awala, I think this one is ready, can you take a look?

@potiuk
Copy link
Member

potiuk commented Jan 25, 2024

Yep. for me looks good too.

@aritra24
Copy link
Collaborator Author

@hussein-awala pinging you for a re-review. This commits ready to merge.

@hussein-awala hussein-awala dismissed their stale review January 28, 2024 11:36

I'm a bit busy this week, I'll let the other committers test it and merge it if they think it's ready.

@aritra24
Copy link
Collaborator Author

@amoghrajesh / @potiuk could you please have a look and merge if you believe it's done.

@amoghrajesh
Copy link
Contributor

amoghrajesh commented Jan 29, 2024

The changes look fine to me. @potiuk WDYT on a last review prior to merge?

@potiuk potiuk merged commit e853849 into apache:main Jan 29, 2024
56 checks passed
@potiuk
Copy link
Member

potiuk commented Jan 29, 2024

Nice!

@aritra24 aritra24 deleted the 36688 branch January 29, 2024 12:26
@jedcunningham jedcunningham added the type:bug-fix Changelog: Bug Fixes label Feb 9, 2024
jedcunningham pushed a commit that referenced this pull request Feb 9, 2024
* Secret masker ignores passwords with special chars #36688

Connection uri's get connection uses quote to change the
password and certain other fields to escape special chars
due to this, when the connection object is passed through
the masker this changed string is skipped.

* Added a test for the logging change

(cherry picked from commit e853849)
potiuk pushed a commit that referenced this pull request Feb 13, 2024
* Secret masker ignores passwords with special chars #36688

Connection uri's get connection uses quote to change the
password and certain other fields to escape special chars
due to this, when the connection object is passed through
the masker this changed string is skipped.

* Added a test for the logging change

(cherry picked from commit e853849)
ephraimbuddy pushed a commit that referenced this pull request Feb 22, 2024
* Secret masker ignores passwords with special chars #36688

Connection uri's get connection uses quote to change the
password and certain other fields to escape special chars
due to this, when the connection object is passed through
the masker this changed string is skipped.

* Added a test for the logging change

(cherry picked from commit e853849)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Airflow does not mask secrets in Database URI's when secret has a special character.
6 participants