-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Allow users to override default PyPI index URL with PyPI mirror URLs (without modifying Pipfile) #2075
Comments
I am persuaded that this is a thing that happens commonly (corporate FW / caching proxy) -- I feel we need an override setting to specify a mirror to use instead of pypi if we find it in the pipfile-- like Does that seem like it accomplishes the goal? If so, we can tag in the implementation genie to tell us why this is good or bad (@ncoghlan) |
I'll start with a note of caution: until PyPI has implemented a package signing mechanism akin to PEP 458 to provide a TLS-independent way for Unfortunately, that particular attack vector is already open by way of Beyond that, I think a general purpose repository URL rewriting mechanism could actually be easier to document and explain than something PyPI specific, at least at the base capability layer. Something like:
(The only PyPI specific bit there would be using "default" to refer to pip's default download source, as specific in Spelling out the entire source URL override map every time would be unwieldy to use in practice though, so a couple of options for CLI sugar might look like:
Whether or not to expose the |
A general
|
@njsmith See the |
Ah, right, I missed that :-) Is there a general rule mapping command line arguments to some kind of more persistent configuration? I imagine that most users of this would want to set it up once and then forget it. |
@ncoghlan wrote:
If I'm reading my |
Changing the default index URL (or adding an extra index URL) in There are good reasons why organisations with strict security requirements execute builds on locked down servers with only limited access to the internet at large, or otherwise monitor for these kinds of problems at the network level :) |
Note also if you use multiple indexes and a package comes from the non-primary index it will be indicated in the lockfile. The pep 458 concerns were essentially what I had in mind, since things that are different urls but in actuality point at pypi are different than if you just locally copied pypi and claimed it was the same. |
If this is your threat model, then I don't see how anything pipenv can do will effect it much. Someone who can modify your home directory config can also do things like insert a new directory on |
@njsmith this is also pip’s threat model, because package installation requires the execution of arbitrary code from sdist I guess what I’m saying is, if your local machine is compromised there is nothing pip or pipenv is going to do to save you. But we can ensure that the package you’re downloading is the one you were looking for, from the place you were supposed to search for it, which can provide one element in the chain of security. |
@ncoghlan @njsmith how does this all factor in with the move to push back against |
@techalchemy I don't see any connection to this topic at all? I think the conclusion of all the above is that letting users override which mirror pipenv uses for PyPI doesn't introduce any additional threats, and doing |
@njsmith no I don't think anyone should use
If a defense at least in some capacity relies on keys being stored in a privileged location, but we are advising against using privileged python installs, I think it's possibly worth discussing. Maybe I'm wrong. But it definitely seems related to @ncoghlan's comment (but not Yeah that probably seemed like it came out of nowhere, just a random thought. Hopefully the additional context clears it up some |
I vote we keep this issue on the topic of helping folks who need to use PyPI mirrors, rather than getting into a speculative discussion of how we might implement TUF. (Anyway, I don't think there's much we can or should do to try to defend against an attacker who has arbitrary write access to the the user's home directory.) |
Okay, so lets define the behavior that we would expect or prefer. My current working understanding is that:
|
It should override PyPI only, not other URLs. I guess there are probably only a few different PyPI URLs in use, so they can be listed, and if we miss one then someone will file a bug, it'll get added, and pretty soon we'll have all of them. |
Seems like the right approach to me. |
What @njsmith said matches my perspective as well. The 3 repo URLs I'd suggest replacing in an initial PR would be:
The trailing-slash-or-not is likely better handled as a URL normalisation step, rather than by listing the URLs separately. |
Note that the requests Pipfile does have a trailing slash (at time of writing), so we probably do need to handle this one way or another. |
Right, my thought was:
|
Awesome. I think this is enough to work with and simple enough to build. Thanks all! |
Hope mirror feature could be added soon~ |
Adds support for the --pypi-mirror command line parameter and the PIPENV_PYPI_MIRROR environment variable for most pipenv operations. This permits pipenv to function without pypi.org, which is necessary for users: 1. behind restrictive networks 2. facing strict artifact sourcing policies 3. experiencing poor performance connecting to pypi.org 4. who've configured a local cache for performance reasons When specified, the value of this parameter replaces all instances of pypi.org and pypi.python.org within pipenv operations without modifying or requring the modification of Pipfiles. - Resolves pypa#2075
Adds support for the --pypi-mirror command line parameter and the PIPENV_PYPI_MIRROR environment variable for most pipenv operations. This permits pipenv to function without pypi.org, which is necessary for users: 1. behind restrictive networks 2. facing strict artifact sourcing policies 3. experiencing poor performance connecting to pypi.org 4. who've configured a local cache for performance reasons When specified, the value of this parameter replaces all instances of pypi.org and pypi.python.org within pipenv operations without modifying or requring the modification of Pipfiles. - Resolves pypa#2075
Adds support for the --pypi-mirror command line parameter and the PIPENV_PYPI_MIRROR environment variable for most pipenv operations. This permits pipenv to function without pypi.org, which is necessary for users: 1. behind restrictive networks 2. facing strict artifact sourcing policies 3. experiencing poor performance connecting to pypi.org 4. who've configured a local cache for performance reasons When specified, the value of this parameter replaces all instances of pypi.org and pypi.python.org within pipenv operations without modifying or requring the modification of Pipfiles. - Resolves pypa#2075
Adds support for the --pypi-mirror command line parameter and the PIPENV_PYPI_MIRROR environment variable for most pipenv operations. This permits pipenv to function without pypi.org, which is necessary for users: 1. behind restrictive networks 2. facing strict artifact sourcing policies 3. experiencing poor performance connecting to pypi.org 4. who've configured a local cache for performance reasons When specified, the value of this parameter replaces all instances of pypi.org and pypi.python.org within pipenv operations without modifying or requring the modification of Pipfiles. - Resolves pypa#2075
Adds support for the --pypi-mirror command line parameter and the PIPENV_PYPI_MIRROR environment variable for most pipenv operations. This permits pipenv to function without pypi.org, which is necessary for users: 1. behind restrictive networks 2. facing strict artifact sourcing policies 3. experiencing poor performance connecting to pypi.org 4. who've configured a local cache for performance reasons When specified, the value of this parameter replaces all instances of pypi.org and pypi.python.org within pipenv operations without modifying or requring the modification of Pipfiles. - Resolves pypa#2075
I presume you're talking about using devpi as caching proxy for official PyPi. For pip itself, you would need to modify However, it looks like pipenv ignores these system-wide settings, so you are forced to modify the I think that pipenv should just respect the global settings from |
Nexus Repository, but yeah, same idea.
As @techalchemy mentioned, I believe that pipenv (11.6.0) used to respect
Agreed - though personally I haven't had to modify |
IIRC there was a resolution to not respect pip.conf, but you’ll need to dig deep into the issue tracker to find it. In any case, the ship has sailed, and with PyPI mirroring almost done, this is unlikely to change in near future. |
I'm fairly confident this feature will ship in the next release (which will ship in the next day or two with luck) |
Also I'm not sure about this, but it's possible we might just need to call https://github.com/pypa/pipenv/blob/master/pipenv/project.py#L573-#L577 |
@uranusjr as long as the mirroring configuration works (i.e. doesn't use that hardcoded pypi.org URL I mentioned), I don't see any problem with pipenv having its own configuration for this and ignoring pip's. |
@JacobHenner yep, thanks. My initial testing with the I'm a bit concerned, though, that hardcoded URLs to pypi.org still appear scattered across the pipenv sources. I can't be sure which ones are correctly overridden from |
Yeah following this release I am planning a major code cleanup. Cli stuff moving to the cli, bubbling exceptions there and handling all the exits there, deduping duplicated code, etc. It’s going to be a lot of work and help will be appreciated if anyone wants to volunteer :p |
Just pulled the recent version and it is still hardcoding the pypi.org in the sources. Is the goal to take the environmental variable or the pypi-mirror and put that as the default for [[source]]? edit: Just dug through the code.. Looks like you have if PIPENV_TEST_INDEX:
DEFAULT_SOURCE = {
u"url": PIPENV_TEST_INDEX,
u"verify_ssl": True,
u"name": u"custom",
}
else:
DEFAULT_SOURCE = {
u"url": u"https://pypi.org/simple",
u"verify_ssl": True,
u"name": u"pypi",
} I think if you changed that If PIPENV_TEST_INDEX to the environmental variable PIPENV_PYPI_MIRROR it would be a good start |
The solution discussed here has long been implemented. The snippet you quoted is a default, i.e. used if you do not provide a source when creating the Pipfile. |
No, the source should not change in the Pipfile. The goal of this change
was to allow users to override PyPI URLs with a mirror, _without_ changing
the Pipfile.
|
@JacobHenner The mirror handling code postprocesses the source list and replaces That's what allows the mirror override to work even if there is an explicit If there are currently cases where that postprocessing isn't being applied correctly, that's a new bug report against the already implemented feature, rather than a feature request. |
I think that last comment was intended for @kylecribbs? |
@JacobHenner Ah, sorry - I misinterpreted your comment as saying that this change hadn't achieved its original goal, rather than as a response to Kyle that aimed to clarify what that outcome actually was. |
Hello all,
The situation
Currently, there is no easy way to override the default PyPI index URL to use a URL pointed at a mirror. In corporate environments, requiring developers to use a repository mirror is quite common:
Unfortunately, this doesn't appear to be easily accommodated by pipenv. Although the mirror could be explicitly added to the Pipfile as the source for these packages, this breaks portability.
There should be a way to override the location of the PyPI index, by specifying a (true) mirror. This would only be applicable to PyPI, and not to other third-party repositories (these would still be specified explicitly in the Pipfile).
General proposal
Docker accommodates this situation by allowing the user to specify a registry mirror in the daemon's configuration file. Likewise, it'd be great if the pipenv user could specify a (true) mirror for PyPI, via an environment variable, configuration file, or command line parameter. If this value is set, pipenv should use the mirror for all PyPI packages, even if a connection to PyPI is available. In some corporate environments, PyPI remains unblocked, but policy dictates that the mirror is used for the other reasons mentioned above.
Implementation considerations
Related discussion
#1451
#1783
This has been discussed in #python and #pypa on Freenode. After some constructive back-and-forth, it was decided that it'd be helpful to open an issue here for discussion. I appreciate everyone's effort towards resolving this issue.
The text was updated successfully, but these errors were encountered: