Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Replace password in URI by stars if present to avoid leaking secrets in logs#1198

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

mickours
Copy link
Contributor

Currently, if you use a git URI containing a password likehttps://username:pass@git.example.com/project and an exception occurs during a git clone the password is printed in the logs. It also happen when the logging is at debug level.

To avoid secrets to leak in the logs, this patch replace the password by a fix amount of stars (******).

@mickoursmickours marked this pull request as draftMarch 12, 2021 07:39
@Byron
Copy link
Member

Thanks a lot for the initiative, it's much appreciated.

My early feedback is that the URL parsing is probably prone to failures even though it should work for most URLs. To be save, one would probably catch parsing exceptions.
Maybe it would be easier to use an existing URL parser and/or serializer if one exists in the python standard library.

@mickours
Copy link
ContributorAuthor

Thanks for the feedback! I've change the implementation to use urllib and handle parsing errors.

I'm still unable to make the test works on the CI despite the fact that it works locally. It seems that the failing command raise an assert which is not in my test. The problem is that I need the exception to be raise in order to check if the password is inside. Any clue on that?

@Byron
Copy link
Member

Thanks for the update!

The failing test mentions the entire command-line, here it is:

 /usr/bin/git clone -v --progress ***fakerepo.example.com/testrepo /tmp/test_leaking_password_in_clone_logsam5xqh6q'

It looks like a replacement has happened even though I would expect an additional*, the password has been removed but it still seems to see the password in the error message. Sincefinalize_proc is only handed the processproc, this really only works if theargs list is editable. The latter might be the case in some python versions, but not in others.

Something you could try is to reassignproc.args entirely. If that works, I have a few more requests just to be very very safe 😅.

Copy link
Member

@ByronByron left a comment

Choose a reason for hiding this comment

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

Thanks a lot for bearing with me, and good luck with the CI issue. The test succeeds for me as well when running it locally.

@mickoursmickoursforce-pushed thereplace-password-in-uri-by-stars branch 3 times, most recently from28b8a76 toab1f86eCompareMarch 15, 2021 17:45
@mickoursmickoursforce-pushed thereplace-password-in-uri-by-stars branch fromab1f86e to50cbafcCompareMarch 15, 2021 17:48
@mickoursmickours marked this pull request as ready for reviewMarch 15, 2021 17:52
@mickours
Copy link
ContributorAuthor

I track down every occurrence of the command line in the logs and it seems to be OK now. With this patch it will on every commands try to redact password out of the command line before logging it.

@mickoursmickours marked this pull request as draftMarch 16, 2021 06:55
@mickours
Copy link
ContributorAuthor

I just realize that we do not have a succesfull clone test and when I tried it manually it's not working because of the in-place replacement. I've to rework this.

@mickoursmickoursforce-pushed thereplace-password-in-uri-by-stars branch from2a23db3 to12692e1CompareMarch 16, 2021 09:14
@mickoursmickoursforce-pushed thereplace-password-in-uri-by-stars branch from12692e1 toffddedfCompareMarch 16, 2021 09:16
@mickoursmickours marked this pull request as ready for reviewMarch 16, 2021 09:34
@mickours
Copy link
ContributorAuthor

Ok, I've change the in-place password replacement with a copy implementation which avoid side effects on the command line arguments. Also, I've added a successful git clone with a password from an empty project.

Copy link
Member

@ByronByron left a comment
edited
Loading

Choose a reason for hiding this comment

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

Thanks a lot, this looks so much better already, great work! It's particularly helpful to see more tests, as now there is one in particular for redacting passwords in command-lines. I bet this helped during development.

Please excuse the use of the word 'nicer' in the line comments below, I simply lacked a more scientific explanation so I guess it comes down to 'taste'. This is not to be understood as judgement towards your code, it's just as correct and since it's Python you could make a point towards the current version being idiomatic and I would go with it.

Let's get this one to the finishing line :) 🏇

assert password not in str(err), "The error message '%s' should not contain the password" % err
# Working example from a blank private project
Repo.clone_from(
url="https://gitlab+deploy-token-392045:mLWhVus7bjLsy8xj8q2V@gitlab.com/mercierm/test_git_python",
Copy link
Member

Choose a reason for hiding this comment

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

This might be a danger as it breaks the self-isolation even more (after all, GitPythons test rely on its own repository already), but I think it's OK to go with it and fix it when it breaks.
Maybe it never does.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I agree! I simply did not find another way to test the working use case. Maybe we can use a deploy token with the GitPython repository on Github but I think it is not available for public repo. Maybe you can create a private repo inside thegitpython-developers account in order to keep the responsibility in the same place?

Copy link
Member

Choose a reason for hiding this comment

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

I thought about that too and will do that when it breaks. It's certainly the lazy way of doing things and it's basically a mine that is primed to blow sometime in the future, but… it's going to be okay ;).

While writing this I thought to myself that I don't want to be that lazy and took a look at the github ways of doing this. It turns out it only supports repository deploy keys, which indeed are full blown ssh keys that I don't want to deal with right now. This makes your account one of the pillars of the happiness of GitPython's CI, something not everyone can say about themselves :D.

@mickours
Copy link
ContributorAuthor

mickours commentedMar 18, 2021
edited
Loading

Thanks a lot, this looks so much better already, great work! It's particularly helpful to see more tests, as now there is one in particular for redacting passwords in command-lines. I bet this helped during development.

You're right! :)

Please excuse the use of the word 'nicer' in the line comments below, I simply lacked a more scientific explanation so I guess it comes down to 'taste'. This is not to be understood as judgement towards your code, it's just as correct and since it's Python you could make a point towards the current version being idiomatic and I would go with it.

No problem, I know that sometimes it's a matter of beauty ;)

Let's get this one to the finishing line :) horse_racing

Thanks a lot for all you feedback!! 🏁

Copy link
Member

@ByronByron left a comment

Choose a reason for hiding this comment

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

And it's done :)! Thanks again, I think it was worth it, too!

@ByronByron merged commitd1297f6 intogitpython-developers:masterMar 19, 2021
@ByronByron added this to thev3.1.15 - Bugfixes milestoneMar 19, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ByronByronByron approved these changes

Assignees
No one assigned
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
@mickours@Byron

[8]ページ先頭

©2009-2025 Movatter.jp