Skip to content

Pluggable wheel verifier #6248

Open
Open
@zooba

Description

@zooba

What's the problem this feature will solve?
Verify the contents of any wheel before it is extracted or installed, according to arbitrary validation rules (such as containing a particular file or being signed with a particular certificate).

Currently it's fairly easy to modify a built wheel before publishing it to a (public or private) index, but it's much more complicated to download a wheel to inspect it before installing. This feature would allow the person doing the installation to determine what validation is necessary, define it as Python code, and have pip call into it between the download and install stages.

A secondary problem that it solves is having to choose one true verification method and bake it into pip.

Describe the solution you'd like
Assume a reliable baseline install exists (Python, pip, arbitrary packages). Hence, pip does not need to validate itself or these packages, but is able to validate any upgrades to itself or these packages.

In a pip.ini, an environment variable, or the command line, the --verify-function option is set to a value module:function (for example mypackage.module:verify) that identifies the entry point to a file verifier.

Once a wheel has been downloaded but before it is extracted, the verifier is imported and called, passing the . In simplified code, it would look like this:

downloaded_file = urlretrieve(uri_to_wheel)
with ZipFile(downloaded_file) as f:
    if options.verifier:
        mod_name, _, func_name = options.verifier.rpartition(':')
        verifier = getattr(importlib.import_module(mod_name), func_name)
        verifier(f)
    f.extract_all(…)

The error handling code is omitted, but the implication that all errors within the options.verifier block are fatal is correct. If the option has been specified, failing to locate or use the verifier should abort the install, as should any errors raised by the verifier itself. If the file is deemed valid, it returns without raising.

This is entirely sufficient to handle the common internal corporate scenario where:

  • there is a baseline OS install that is already trusted (including pip, a verifier and configuration)
  • there is a certificate where the public key is on production machines and private key on build server
  • packages only come from an internal package server

It could further extend to do more complicated tasks, such as static analysis of source code

It is not intended to handle packages from mixed sources, or establishing trust between parties where there currently is none. It probably has no place at all on public PyPI right now, though it could allow for easier experimentation.

Alternative Solutions
There are lots of other proposals that involve all sorts of solutions for implied or transitive trust. I am not interested in solving those problems

Additional context
Previously discussed at #6198, #4705, 1035, (under-)specified in PEP 427,

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions