Skip to content

More generic support for Python #492

@itamarst

Description

@itamarst

It seems that trivy supports poetry.lock and Pipfile.lock for Python, but not requirements.txt.

requirements.txt has dual usage:

  1. For some people, it's just high-level dependencies, unpinned to any particular versions.
  2. For other, it's equivalent to a lock file, transitively pinned dependencies often with hashes. For example, the pip-tools package takes an unpinned requirements.in and generates a pinned requirements.txt.

More broadly, there's the issue of people who install packages using unpinned mechanisms, e.g. RUN pip install flask in their Dockerfile.

I can imagine a number of approaches:

  1. Add a parser for requirements.txt, and just give up if it's unpinned. This will miss some vulnerabilities.
  2. Run pip list inside the container to get actually installed packages, and then you don't care how they were installed. The downside is that this is a big difference from your current mode of operation.
  3. Do the equivalent of pip list just by inspecting the contents of any site-packages directories you find in the image. I went and asked a pip developer, and turns out all pip list does is look for <package name>-<version>.dist-info directories and uses that to get package name version. E.g. they look like paramiko-2.7.1.dist-info for package paramiko with version 2.7.1

The third option seems like the easiest and most useful: it works for any Python environment and installation mechanism (it ought to work for Conda too, which is yet another packaging tool), and it's quite simple, just listing directories and parsing their names.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.priority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions