tl;dr: Variant providers will run no untrusted code by default. There will be a shared list of heavily vetted providers for tools to vendor or reimplement. For everything beyond that, user opt-in is required.
The security story of wheel variants was heavily discussed as part of the previous PEP 817 thread. Here we want to propose an updated design that balances security and user experience.
To recap, we want to introduce advanced platform support, especially GPU support. Instead of hardcoding more fields into wheel filenames, we introduce variant properties through which wheels are matched to an installation target. If you’re interested in an overview on the full wheel variants proposal, check PEP 817 out. PEP 825 covers how variants are described, checked and ordered, but not where to obtain them. PEP 850 defines how to obtain them.
Roughly, variant wheels work as follows: The package author defines a variant label for each target and says what each label needs from the target platform using variant properties. The variant labels are attached to wheels behind the platform tag, extending it. The author also writes in the package metadata which variant providers are needed. The variant providers contain the actual platform detection code and emit the variant properties of the host, which the installer compares to the variant properties of the wheels.
We have three seemingly conflicting goals for variant providers: There must never be arbitrary code execution at install time [1], we must be able to perform advanced platform detection (such as GPU detection) at install time, and we need to evolve providers in the future. While package requirements describe variant providers by name and version, the trick is that they don’t work like regular dependencies. Instead, they encode which and what level of platform support a wheel needs, while the actual provider code is shipped with the installer.
How the installer ships the code is left to the tool: It can vendor them, like pip vendors packaging, it can reimplement them, like uv reimplements packages, it can use any secure mechanism of the tool author’s choice. This also gives us flexibility, for example it allows users to opt-in to provider plugins that are actually (internally maintained) packages to support custom hardware and software, users can provide properties through a static file where build and deploy environments are different, and users can opt-in to newer provider plugins while still using an older tool (or alternatively get a good error message about the version mismatch, where we currently have no good reporting).
Using this model has enabled more features we didn’t initially target, for example they can model different BLAS/OpenMP/etc. implementations in the build using static providers, and they can describe ABI dependencies between packages through a built-in provider, both of which can’t currently be modelled at all and require fallbacks to source distributions (and they are static or built-in respectively, so no code execution at all from a provider package). Together, this meets all of our three goals.
Prior Art and Motivation
Python already has a repository for de-facto authoritative advanced platform detection code that is vendored and/or reimplemented by tools, pypa/packaging. The libc detection accesses low-level operating system primitives to determine a more fine-grained platform compatibility marker, manylinux and musllinux. It is vendored or depended on by every major package manager. Initially, each manylinux tag was specified in a PEP, with detailed rules for which libraries and symbols are and aren’t allowed (PEP 513 - manylinux1, PEP 571 - manylinux2010, PEP 599 - manylinux2014). This created a maintenance burden on the Linux maintainers, delays to rollout and mismatches when Linux distributions changed in ways not anticipated by the PEP. To cite directly from PEP 600:
In previous manylinux PEPs (PEP 513, PEP 571, PEP 599), we’ve done this by attempting to write down in the PEP the exact set of libraries, symbol versions, Python configuration, etc. that we believed would lead to wheels that work on all mainstream glibc-based Linux systems. But this created several problems:
First, PEPs are generally supposed to be normative references: if software doesn’t match the PEP, then we fix the software. But in this case, the PEPs are attempting to describe Linux distributions, which are a moving target, and do not consider our PEPs to constrain their behavior. This means that we’ve been taking on an unbounded commitment to keep updating every manylinux PEP whenever the Linux distro landscape changes. This is a substantial commitment for unfunded volunteers to take on, and it’s not clear that this work produces value for our users.
And second, every time we move manylinux forward to a newer range of supported platforms, or add support for a new architecture, we have to go through a fairly elaborate process: writing a new PEP, updating the PyPI and pip codebases to recognize the new tag, waiting for the new pip to percolate to users, etc. None of this happens on Windows/macOS; it’s only a tax on Linux maintainers. This slows deployment of new manylinux versions, and consumes part of our community’s limited PEP review bandwidth, thus slowing progress of the Python packaging ecosystem as a whole. This is especially problematic for less-popular architectures, who have less volunteer resources to overcome these barriers.
Eventually, manylinux switched to the perennial manylinux model: There is one PEP that defines how to build future manylinux, without defining the lists of libraries and symbols. For those who still need those lists, there’s a reference JSON document in auditwheel. Every future manylinux revision can be introduced by computing the new manylinux tag value and updating the JSON policies in auditwheel, without introducing any new PEPs or packaging.python.org updates.
We build upon this experience. The advanced platform support through variants is in this sense very similar to manylinux, its targets are externally defined and updated with a notable burden to maintain in Python specifications. We chose to move the entirety of the platform detection logic into the implementation, but instead of being a mostly hidden part of packaging, they are explicitly named provider plugins. Where manylinux is implicitly available as part of platform tags, variant providers need to be explicitly requested, as they are explicitly versioned.
Auditing
Blessed providers occupy a critical position and must follow a much stricter standard than regular packages:
- No native code, only pure Python (pip allows only pure Python dependencies)
- The code must be written in the most portable way, but can be limited to the platforms of interest (for example, ROCm only supports Linux and Windows, so it can use Linux- and Windows-specific functions and return an empty result otherwise)
- No dependencies, except the two standard packages
packagingandarchspec(which tools also need to vendor) - A permissive open source license, such as Apache 2/MIT, UNLICENSE, CC0 (GPL is not possible)
- Limit the amount of
ctypes,structand similar C-wrapping modules to a minimum. While sometimes unavoidable (it’s e.g. required for manylinux detection), C-style code is notoriously hard to review and audit. - The code must be written in a way that it is trivial to audit for malicious or vulnerable behavior. This imposes a limit on how big a provider plugin can be, if it has too much code, it fails this auditing check.
This is a list of minimal requirements, only focused on security. A blessed provider requires following the highest code quality requirements: If tool maintainers lack confidence in an implementation where they say they can’t justify vendoring it, it cannot land.
These are all security requirements, not correctness requirements, which are outside the scope of this proposal. You can only properly check if such code works by running it on the target platform and hardware, so we avoid imposing validation requirements.
Note that this is not an adversarial process: Only because something is not explicitly banned here does not mean it’s allowed. If something is insecure or in another way a bad idea, it will be rejected in code review, just like it would be rejected as a regular PR to pip, uv, or any other package manager. For example, we haven’t explicitly banned accessing the user’s documents in the list: That is something that pip and uv clearly must not do, so it’s also something that a provider must not do.
Adding a provider to this list is a major commitment for the ecosystem. We’ll propose a list of initial provider plugins in a future proposal. This list will naturally be limited, and there is a high bar for adding new ones. This thread is focused on building confidence in the security story around providers.
Governance
The list and implementations of blessed providers will be maintained in a GitHub repository. Day-to-day, the maintenance will take place in the repository, with decisions being made through the regular code review process, similar to packaging. The PPC will appoint the initial list of maintainers. Experts from the relevant vendors will be involved to ensure we match their software and hardware compatibility. Changes to the list or significant changes to the provider inputs or outputs require consensus between maintainers of the affected tools. Where a consensus cannot be reached that way, the Python Packaging Council (PPC) decides. While the PPC ultimately decides, avoiding both gridlocks and “rogue” decisions, experience shows that most work doesn’t need committee involvement. Historically, there are rather too few than too many people on such projects. A dedicated provider repository also makes vendor involvement easier, which helps with maintenance.
Initially, we suggest this repository lives under https://github.com/pypa or https://github.com/python, this is still up to decision. This may change as the PPC evolves PyPA governance (PEP 772 – Packaging Council governance process | peps.python.org).
Rust and Python
The Python (packaging) ecosystem has evolved to one where Rust tools exist alongside Python tools, the most widely used packaging tools being pip (Python) and uv (Rust). This means we can’t only have Python code or specify std functions to use. Instead, we define a reference Python implementation and allow projects in other languages (or those that simply don’t want to use the reference implementation) to use a reimplementation in Rust or any other language. For ecosystem coherence we require that the platform detection methods and the output variant properties match. From our experience with uv, this is not a compatibility risk, but rather a check for the Python implementation that catches problems in the reference implementation.
Acknowledgements
Thanks to Seth Larson and Mike Fiedler for the helpful discussions on security.
Beyond the existing capabilities such as source distribution builds and arbitrary code execution by side-effect, such as sitecustomize.py, which are outside the scope of this PEP ↩︎