You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix incorrect references to manifest files (#1930)
This KB is about generating lockfiles, defined as files that list specific pinned dependency versions. These are the only files we currently support for Python with SSC.
Copy file name to clipboardexpand all lines: docs/kb/semgrep-supply-chain/ssc-python-lockfiles.md
+10-15
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
description: Generate various Python lock files to run Semgrep Supply Chain scans successfully.
2
+
description: Generate Python lockfiles to run Semgrep Supply Chain scans successfully.
3
3
tags:
4
4
- Semgrep Supply Chain
5
5
- Python
@@ -10,18 +10,15 @@ tags:
10
10
- Poetry.lock
11
11
---
12
12
13
-
# Generating Python manifest files for Semgrep Supply Chain scans
13
+
# Generating Python lockfiles for Semgrep Supply Chain scans
14
14
15
-
To correctly scan all dependencies in a project, Semgrep Supply Chain requires a Python manifest file. This article describes methods to generate the following Python manifest files or lockfiles:
15
+
To correctly scan all dependencies in a project, Semgrep Supply Chain requires a Python lockfile: a file with specific versions of all dependencies. This article describes methods to generate the following supported Python lockfiles:
16
16
17
-
*`requirements.txt`, including those in a requirements folder, such as `**/requirements/*.txt`
18
-
*`requirements.pip`
19
-
*`requirement.txt`, including those in a requirement folder, such as `**/requirement/*.txt`
20
-
*`requirement.pip`
17
+
*`requirements.txt`
21
18
*`Pipfile.lock`
22
19
*`Poetry.lock`
23
20
24
-
You can use any of these files to get a successful Semgrep Supply Chain scan. Your manifest files must have one of these three names to be scanned, or you must have a `*/requirement/*` file in the project.
21
+
You can use any of these files to get a successful Semgrep Supply Chain scan. Since Semgrep 1.93.0, a `requirements.txt` file can be placed in a `**/requirements/` folder, or can have any name that matches `*requirement*.txt` or `*requirement*.pip`.
25
22
26
23
## Generating `requirements.txt`
27
24
@@ -32,7 +29,6 @@ You can use any of these files to get a successful Semgrep Supply Chain scan. Yo
32
29
*`pip-tools` must be installed on your machine. See the [pip-tools GitHub repository](https://github.com/jazzband/pip-tools) for installation instructions.
33
30
:::
34
31
35
-
36
32
To generate a `requirements.txt` file from `requirements.in`, enter the following command in the root of your project directory:
37
33
38
34
```bash
@@ -112,10 +108,8 @@ This file has all direct and transitive dependencies of the example project and
112
108
### Using `pip freeze`
113
109
114
110
:::info Prerequisites
115
-
116
111
* The `pip freeze` utility uses dependencies from packages already installed in your current environment to generate `requirements.txt`. You must be in an isolated or [virtual environment](https://docs.python.org/3/library/venv.html).
117
112
* An existing `setup.py` file.
118
-
119
113
:::
120
114
121
115
To generate `requirements.txt` through `pip freeze`, enter the following commands:
@@ -296,16 +290,17 @@ poetry lock
296
290
297
291
The generated `Poetry.lock` file contains all transitive and direct dependencies that the project uses.
298
292
299
-
## Selecting a single manifest file among many
293
+
## Selecting a single file among many
300
294
301
-
While there may already be a manifest file in the repository, such as a `Pipfile.lock`, you may want to generate a new one, for example a `requirements.txt`, to be sure it has the latest dependencies.
295
+
While there may already be a lockfile in the repository, such as a `Pipfile.lock`, you may want to generate a new one, for example a `requirements.txt`, to be sure it has the latest dependencies.
302
296
303
-
When scanning with Semgrep Supply Chain, you can use the flag `--include` to specify that only a single manifest file should be scanned. The manifest file must still have one of the supported names.
297
+
When scanning with Semgrep Supply Chain, you can use the flag `--include` to specify that only a single lockfile should be scanned. The manifest file must still have one of the supported names.
304
298
305
299
```
306
300
semgrep ci --supply-chain --include=requirements.txt
307
301
```
302
+
However, if you have multiple `requirements.txt` files that are in supported locations, you do not need to generate a new unified lockfile. Semgrep will scan files from all supported locations.
308
303
309
304
## Conclusions
310
305
311
-
There are several ways to generate manifest files or lockfiles for Python dependencies. Depending on your preferences, you can select one or another. Keep in mind that the manifest file should be generated before the Semgrep scan and within the proper environment. This ensures that you are scanning only the dependencies of your project and not all the Python dependencies of your system.
306
+
There are several ways to generate lockfiles for Python dependencies. Depending on your preferences, you can select one or another. Keep in mind that the file should be generated before the Semgrep scan and within the proper environment. This ensures that you are scanning only the dependencies of your project and not all the Python dependencies of your system.
0 commit comments