-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Validate VCS urls in hash-checking mode using their commit hashes #6469
Comments
I think you (and others) make a good case that stonewalling SHA1 VCS URLs as unhashable is counterproductive in a lot of practical cases, like when using secure internal git servers. The obvious options I see are…
However, I will put this here for everyone's evaluation. Seems like SHA1 collisions are about to get another notch cheaper: https://www.zdnet.com/article/sha-1-collision-attacks-are-now-actually-practical-and-a-looming-danger/. In my ideal world, git would release SHA256 support, and we'd have no reservations at all. |
How about a special --hash value, like:
or
|
That also occurred to me, but I thought it'd be best to make it clear to the runner of pip rather than just the author of the requirements file. But, now that you mention it, a package author doesn't (ideally) include hashes, as that would frustrate downstream integrators. So it's fine. |
hello pleas help what the hash is hier ??????? |
I've run into this same problem. I just want to point out another limitation with using an artifact url like |
I would be in favor of having In #6851 I added |
Why not just hash the whole VCS directory and use whatever hash algorithm the user wants? This would probably have to exclude things like the |
Yes, let's just fix this in a backwards compatible way by start supporting a hash of a VCS checked out directory. I do not see why it is so hard to recursively compute hash of a directory in a deterministic way and this is it. |
It is not hard to compute a directory’s hash, but to compute reliably. |
Another way to do this is to stick with only checking artifact hashes. There has been talks about pip should build an sdist for source tree installations (to solve unrelated issues), and pip can use the built sdist’s hash here. That would be consistent. |
Commit ID sadly is not complete. For example if you use git LFS to pull some data but that is not installed on the target system. Then git LFS will not pull data and your checkout of the repository will not really contain expected files. I do not think it is maintenance hell. You do not compute hash on the file system, you compute it on git's view of the filesystem. So, And the way to achieve this is simply to call
+1 on that one. Yes, hashes should probably not be computed on repository directory, but on what is being seen as source to be installed from. |
In reply to @uranusjr, that's been brought up before, but we'd have to do some work to make sure the building of sdists are deterministic. For starters, modification timestamps make their way into tarballs. |
This is preventing us in moneymeets/python-poetry-buildpack#19 to enable hashes - people use private repositories as requirements a lot for deployment - I'm not really concerned about SHA1 weaknesses, as it seems to me, that not using hashes at all is less secure as using SHA1 for private VCS dependencies, but I like the idea of |
We would like to migrate away from Pipenv to pip-compile from pip-tools with --generate-hashes which uses normal pip under the hood, but have a number of git dependencies due to forking libraries and making custom patches. Has anything changed since the issue was created two years ago that could allow for this feature to move forward now? |
Not that I'm aware of. It would need someone to come up with a proposal and PR, and so far no-one has been sufficiently motivated to do so. |
I'd personally be happy to review a PR doing that. I think it will involve our existing Also VCS references that point an immutable ref cause wheels built from them to be cached, and subsequently reused. So the question of whether the pip wheel cache can be trusted might come up, as we can't hash check wheels coming from there. |
Seems like handling all the edge cases has made this bug prohibitive for anyone to take on. Given how long it's been open, I wonder if anyone is up for trying a simpler PR that just supports the per-requirement opt-out I suggested up-thread:
I imagine that's a much simpler PR to write, and it lets projects move forward that are better off with 99% hashing than none (in particular because the requirements where they're skipping hashing are likely to be ones they control). [Edit: and it doesn't interfere with a more complete solution if-and-when someone is able to write one.] |
This is our case! Our git deps are mainly for forked repos where we have a handful of patches. Right now i worked around this restriction by adding patchfiles directly to our project, and git apply'ing them into our virtualenv after install has completed. |
Currently when installing pip dependencies via the `<REPO>_PIP_REQUIREMENTS` environment variable, `run-task` explicitly passes in the `--require-hashes` option. This makes it difficult to test against pre-release versions of Taskgraph since VCS urls do not support hashes (pypa/pip#6469). Luckily when `pip` encounters a requirements with `--hash`, the `--require-hashes` flag is implied. This means that if `run-task` doesn't explicitly pass it in, we'll be able to test against pre-release versions of taskgraph by adding the git URL and then simply *not* using the `--generate-hashes` flag in `pip-compile`. But in production we'd still get hash verification. This does loosen restrictions a bit, since previously a repo would have no choice other than to use hashes. But now they could opt not to. Personally I feel like this is a trade-off that should be left to repo owners anyway.
Currently when installing pip dependencies via the `<REPO>_PIP_REQUIREMENTS` environment variable, `run-task` explicitly passes in the `--require-hashes` option. This makes it difficult to test against pre-release versions of Taskgraph since VCS urls do not support hashes (pypa/pip#6469). Luckily when `pip` encounters a requirements with `--hash`, the `--require-hashes` flag is implied. This means that if `run-task` doesn't explicitly pass it in, we'll be able to test against pre-release versions of taskgraph by adding the git URL and then simply *not* using the `--generate-hashes` flag in `pip-compile`. But in production we'd still get hash verification. This does loosen restrictions a bit, since previously a repo would have no choice other than to use hashes. But now they could opt not to. Personally I feel like this is a trade-off that should be left to repo owners anyway.
Currently when installing pip dependencies via the `<REPO>_PIP_REQUIREMENTS` environment variable, `run-task` explicitly passes in the `--require-hashes` option. This makes it difficult to test against pre-release versions of Taskgraph since VCS urls do not support hashes (pypa/pip#6469). To work around this, a `PIP_DISABLE_REQUIRE_HASHES` environment variable is being introduced. When set, `run-task` will not pass down `--require-hashes` to the `pip install` command. Allowing consumers to test against URL specifiers.
Currently when installing pip dependencies via the `<REPO>_PIP_REQUIREMENTS` environment variable, `run-task` explicitly passes in the `--require-hashes` option. This makes it difficult to test against pre-release versions of Taskgraph since VCS urls do not support hashes (pypa/pip#6469). To work around this, a `PIP_DISABLE_REQUIRE_HASHES` environment variable is being introduced. When set, `run-task` will not pass down `--require-hashes` to the `pip install` command. Allowing consumers to test against URL specifiers.
workaround:
|
Do I have to run one |
I plan to work on this for pip 23.2 (July). My plan is to accept VCS URLs which point to immutable (git) commit hashes when pip is in Granted git's sha1 may be considered weaker than the sha256 hashes we require for archives. On the other hand I think rejecting it as it is now forces users of VCS URLs into a more insecure situation than they deserve as they can use hash validation at all for other requirements. If this is controversial I'm happy to enable this new behaviour with an option. |
How does this apply to other VCS? |
I plan to rely on our |
A draft PR is at #11968. I'll very much welcome tests by interested users. |
Please put comments on a specific pull request in the pull request thread instead. Commenting here may cause confusion in the future if more than one pull request is associated with the issue. |
What's the problem this feature will solve?
It is often useful to temporarily switch a requirement to a VCS URL, for example to refer to a pull request in a fork prior to release, and then switch back once the feature is released.
This practice is incompatible with --require-hashes, however. If any requirements are hashed, then the VCS URL requirement is rejected with "The editable requirement cannot be installed when requiring hashes, because there is no single file to hash" or "Can't verify hashes for these requirements because we don't have a way to hash version control repositories."
This makes it more difficult to use hashes, which ultimately discourages secure pip use.
Describe the solution you'd like
Many VCS URLs contain sha1 hashes in the refspec. (sha1 is not a great hash -- more discussion below.) A requirement like
git+https://github.com/requests/requests.git@e52932c427438c30c3600a690fb8093a1d643ef3#egg=requests
could be accepted with --require-hashes as long as the commit validates.Support on the pip side would help to encourage use of hashes by pip-tools users. A user could include
git+https://github.com/requests/requests.git@master#egg
in requirements.in, and usepip-compile --generate-hashes
to write a pinned VCS URL along with other hashed requirements to requirements.txt. Currentlypip-compile --generate-hashes
necessarily generates an uninstallable requirements.txt with VCS URLs, which discourages use of --generate-hashes.Alternative Solutions
Don't require hashes for VCS URLs, on the grounds that some hashes are better than none. (I believe this is the approach taken by pipenv, though I haven't verified.) This still checks hashes for most requirements, and the security risk of allowing some unhashed URLs is "attacker has compromised communications with a specific VCS server", which for many users would not significantly change their risk profile.
(Provide option to disable hash-checking #4344) Same as above, but as an opt-in flag, either with a global flag or a --hash=skip flag per line.
Keep VCS URLs in a separate requirements file, as recommended on editable cannot be installed when requiring hashes #4995. This adds complexity to the install process without any additional security over the flag option.
Some VCS URLs can be converted to artifact URLs, like
https://github.com/requests/requests/archive/e52932c427438c30c3600a690fb8093a1d643ef3.zip#egg=requests
, which allows them to be hashed. This doesn't work for other packages, however, such as those that usesetuptools_scm
to set their version. For example,pip install https://github.com/jazzband/pip-tools/archive/f97e62ecb0d9b70965c8eff952c001d8e2722e94.zip
will fail with "setuptools-scm was unable to detect version".Additional context
This feature request was discussed when --require-hashes was first added and ultimately rejected by the author because of the insecurity of sha1:
Since then, there's been a lot more discussion of the risks of using sha1 for refspecs following the ShAttered attack (where Google paid to create a PDF hash collision, and could have done the same for a git commit).
After that attack:
In short, a sha1 collision attack requires attackers to first issue a specially-crafted, suspicious benign commit, at great expense, and then replace it with a malicious one. So a security model that is concerned with sha1 attacks assumes that an attacker has already crafted a seemingly-benign commit and had it distributed -- by which point, the Mercurial page argues, there are cheaper, easier, and more deniable ways to succeed in the attacker's aim.
That argument is certainly debatable! So I'm hoping to discuss it here: would it be worth counting sha1 refspecs as "hashed" for now, in order to encourage use of
pip install --require-hashes
andpip-compile --generate-hashes
?The text was updated successfully, but these errors were encountered: