|
| 1 | +# Vulnerability Report |
| 2 | + |
| 3 | +Pulp Python provides vulnerability scanning capabilities to help you identify known security |
| 4 | +vulnerabilities in your Python packages. This feature integrates with the [Open Source Vulnerabilities (OSV)](https://osv.dev/) |
| 5 | +database to scan Pulp `RepositoryVersions` for vulnerable packages. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +Before generating the vulnerability report, ensure that: |
| 10 | + |
| 11 | +1. You have a Python repository with [synced or uploaded content](site:pulp_python/docs/user/guides/sync/) |
| 12 | +2. Pulp has connectivity to the [OSV API](https://api.osv.dev/v1/query) |
| 13 | + |
| 14 | +## Generating a vulnerability report |
| 15 | + |
| 16 | +To scan a `RepositoryVersion` for vulnerabilities, you need to make a POST request to the `/scan` |
| 17 | +endpoint of it: |
| 18 | + |
| 19 | +```bash |
| 20 | +REPO_VERSION_HREF=$(pulp python repository show --name my-repo | jq -r '.latest_version_href') |
| 21 | +curl -XPOST -u <user>:<password> ${BASE_ADDR}${REPO_VERSION_HREF}scan/ |
| 22 | +``` |
| 23 | + |
| 24 | +## Understanding Scan Results |
| 25 | + |
| 26 | +After a scan completes, vulnerability information is available in two places: |
| 27 | + |
| 28 | +### 1. Repository Version Level |
| 29 | + |
| 30 | +The `RepositoryVersion` includes a `vuln_report` field that references a vulnerability report |
| 31 | +containing all vulnerabilities found in that version: |
| 32 | + |
| 33 | +```bash |
| 34 | +pulp python repository version show --repository my-repo |
| 35 | +``` |
| 36 | + |
| 37 | +The response includes: |
| 38 | + |
| 39 | +```json |
| 40 | +{ |
| 41 | + "pulp_href": "/pulp/api/v3/repositories/python/python/.../versions/1/", |
| 42 | + "number": 1, |
| 43 | + ... |
| 44 | + "vuln_report": "/pulp/api/v3/vuln-reports/..." |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +### 2. Content Level |
| 49 | + |
| 50 | +Individual Python package content units also include vulnerability report references: |
| 51 | + |
| 52 | +```bash |
| 53 | +pulp python content list |
| 54 | +``` |
| 55 | + |
| 56 | +Each package in the response includes: |
| 57 | + |
| 58 | +```json |
| 59 | +{ |
| 60 | + "pulp_href": "/pulp/api/v3/content/python/packages/.../", |
| 61 | + "name": "Django", |
| 62 | + ... |
| 63 | + "vuln_report": "/pulp/api/v3/vuln-reports/...", |
| 64 | + ... |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +### Viewing Vulnerability Details |
| 69 | + |
| 70 | +To view the actual vulnerability data, retrieve the vulnerability report: |
| 71 | + |
| 72 | +```bash |
| 73 | +# Get vulnerability report details |
| 74 | +pulp show --href ${VULN_REPORT_HREF} |
| 75 | +``` |
| 76 | + |
| 77 | +The report contains detailed information about each vulnerability, including: |
| 78 | + |
| 79 | +- **CVE identifiers**: Common Vulnerabilities and Exposures identifiers |
| 80 | +- **Affected versions**: Which package versions are vulnerable |
| 81 | +- **Fixed versions**: Which versions contain fixes |
| 82 | +- **References**: Links to advisories and patches |
| 83 | +- **Repository and Content**: Pulp `RepositoryVersion` and `Content` impacted |
| 84 | + |
| 85 | +## Example Workflow |
| 86 | + |
| 87 | +Here's a complete example of scanning a repository for vulnerabilities: |
| 88 | + |
| 89 | +```bash |
| 90 | +# 1. Create a repository |
| 91 | +pulp python repository create --name security-scan-repo |
| 92 | + |
| 93 | +# 2. Create a remote pointing to PyPI |
| 94 | +pulp python remote create \ |
| 95 | + --name pypi-remote \ |
| 96 | + --url https://pypi.org/ \ |
| 97 | + --includes '["django==5.2.1"]' |
| 98 | + |
| 99 | +# 3. Sync the repository |
| 100 | +pulp python repository sync \ |
| 101 | + --name security-scan-repo \ |
| 102 | + --remote pypi-remote |
| 103 | + |
| 104 | +# 4. Get the latest version href |
| 105 | +REPO=$(pulp python repository show --name security-scan-repo) |
| 106 | +VERSION_HREF=$(echo $REPO | jq -r '.latest_version_href') |
| 107 | + |
| 108 | +# 5. Scan for vulnerabilities |
| 109 | +curl -XPOST -u <user>:<password> ${BASE_ADDR}${VERSION_HREF}scan/ |
| 110 | + |
| 111 | +# 6. View the vulnerability report |
| 112 | +VULN_REPORT=$(pulp python repository version show --repository security-scan-repo | jq -r '.vuln_report') |
| 113 | +pulp show --href $VULN_REPORT |
| 114 | +``` |
0 commit comments