Skip to content
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

More generic support for Python #492

Closed
itamarst opened this issue May 14, 2020 · 9 comments
Closed

More generic support for Python #492

itamarst opened this issue May 14, 2020 · 9 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete.

Comments

@itamarst
Copy link

itamarst commented May 14, 2020

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.

@itamarst itamarst added the kind/feature Categorizes issue or PR as related to a new feature. label May 14, 2020
@mkjpryor-stfc
Copy link

My team uses requirements.txt as a lock file, so support for that would be much appreciated.

More generally, I like the idea of just finding any site-packages directories and scanning the dist-infos.

An alternative approach could be to locate all pip executables and use the output of pip freeze to drive the analysis.

@jithurjacob
Copy link

This would be really helpful as we use conda for ML libs and we are not able to use trivy.

@github-actions
Copy link

This issue is stale because it has been labeled with inactivity.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and will be auto-closed. label Mar 22, 2021
@krol3 krol3 added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and will be auto-closed. labels Mar 22, 2021
@knqyf263 knqyf263 added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. labels Mar 22, 2021
@knqyf263
Copy link
Collaborator

I've added this task to our backlog.

@knqyf263
Copy link
Collaborator

knqyf263 commented Apr 19, 2021

As a first step, we'll support == only.

How it works:

  1. Look for all requirementx.txt.
  2. Parse requirementx.txt and extract package names and versions
  3. Use them for vulnerability detection

How to implement it:

  1. Add a new parser here
  2. Add a new analyzer for requirements.txt here
  3. Update go.mod/go.sum in Trivy

@PratikDhanave
Copy link

@knqyf263 I am working on it. work in progress

@Gerry9000
Copy link

Looks like this issue has the same goal for python and node packages, using approach #3 from this issue, and the contributor mentioned they have code they can submit:
#1039

@knqyf263
Copy link
Collaborator

We finally merged #1169, so Trivy will support requirements.txt in the next version. Note that it detects only == specifier.

@jerbob92
Copy link
Contributor

jerbob92 commented Jan 7, 2022

I have tried adding more generic pip-compile support: aquasecurity/fanal#357
Please let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete.
Projects
None yet
Development

No branches or pull requests

8 participants