- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 935
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace password in URI by stars if present to avoid leaking secrets in logs #1198
Conversation
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. |
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? |
Thanks for the update! The failing test mentions the entire command-line, here it is:
It looks like a replacement has happened even though I would expect an additional Something you could try is to reassign |
There was a problem hiding this 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.
28b8a76
to
ab1f86e
Compare
ab1f86e
to
50cbafc
Compare
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. |
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. |
2a23db3
to
12692e1
Compare
12692e1
to
ffddedf
Compare
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. |
There was a problem hiding this comment.
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:[email protected]/mercierm/test_git_python", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 the gitpython-developers
account in order to keep the responsibility in the same place?
There was a problem hiding this comment.
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.
You're right! :)
No problem, I know that sometimes it's a matter of beauty ;)
Thanks a lot for all you feedback!! 🏁 |
There was a problem hiding this 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!
Currently, if you use a git URI containing a password like
https://username:[email protected]/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 (
******
).