Skip to content

Commit 555d93c

Browse files
pedro-psbmdellweg
authored andcommitted
Add vulnerability report support for pulp_rpm
This adds the vulnerability report capability provided by pulpcore and the rpm-specific vulnerability report configurations required by on the rpm repository for the scan to work. Closes #1427
1 parent 212d6d2 commit 555d93c

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

CHANGES/1427.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added support for RPM vulnerability reports.
2+
This includes the `scan` subcommand for repository versions and the `--osv-config` option for repositories.

pulp-glue/src/pulp_glue/rpm/context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ class PulpRpmRepositoryVersionContext(PulpRepositoryVersionContext):
371371
HREF = "rpm_rpm_repository_version_href"
372372
ID_PREFIX = "repositories_rpm_rpm_versions"
373373
NEEDS_PLUGINS = [PluginRequirement("rpm", specifier=">=3.9.0")]
374+
CAPABILITIES = {"scan": [PluginRequirement("rpm", specifier=">=3.38.0")]}
374375

375376

376377
class PulpRpmRepositoryContext(PulpRepositoryContext):
@@ -387,6 +388,7 @@ class PulpRpmRepositoryContext(PulpRepositoryContext):
387388
"roles": [PluginRequirement("rpm", specifier=">=3.19.0")],
388389
}
389390
NEEDS_PLUGINS = [PluginRequirement("rpm", specifier=">=3.9.0")]
391+
NULLABLES = PulpRepositoryContext.NULLABLES | {"osv_config"}
390392

391393
def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> EntityDefinition:
392394
body = super().preprocess_entity(body, partial=partial)

src/pulpcore/cli/rpm/repository.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ def repository() -> None:
204204
),
205205
callback=load_json_callback,
206206
),
207+
pulp_option(
208+
"--osv-config",
209+
"osv_config",
210+
needs_plugins=[PluginRequirement("rpm", specifier=">=3.38.0")],
211+
help=_(
212+
"A JSON list of ecosystem configs for vulnerability scanning via osv.dev "
213+
"(or @file containing a JSON list). "
214+
"Each entry must have 'name' and 'releases' keys. Pass '' to clear."
215+
),
216+
callback=load_json_callback,
217+
),
207218
]
208219
create_options = update_options + [click.option("--name", required=True)]
209220

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
# shellcheck source=tests/scripts/config.source
5+
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source
6+
7+
pulp debug has-plugin --name "core" --specifier ">=3.85.3" || exit 0
8+
pulp debug has-plugin --name "rpm" --specifier ">=3.38.0" || exit 0
9+
10+
KERNEL_URL="https://vault.centos.org/7.0.1406/os/x86_64/Packages/kernel-3.10.0-123.el7.x86_64.rpm"
11+
OSV_CONFIG_A='[{"name": "AlmaLinux", "releases": ["9"]}]'
12+
OSV_CONFIG_B='[{"name": "Red Hat", "releases": ["cpe:/o:redhat:enterprise_linux:7::workstation"]}]'
13+
REPOSITORY=rpm_vulnerability_repo
14+
REPOSITORY_NO_CONFIG=rpm_vulnerability_repo_no_config
15+
16+
cleanup () {
17+
pulp rpm repository destroy --name ${REPOSITORY} || true
18+
pulp rpm repository destroy --name ${REPOSITORY_NO_CONFIG} || true
19+
}
20+
trap cleanup EXIT
21+
22+
23+
get_osv_config(){
24+
pulp rpm repository show --name "${1}" | jq '.osv_config'
25+
}
26+
27+
# osv_config can be created
28+
expect_succ pulp rpm repository create --name ${REPOSITORY} --osv-config "${OSV_CONFIG_A}"
29+
test "$(get_osv_config $REPOSITORY)" != "null"
30+
31+
# osv_config can be cleared
32+
expect_succ pulp rpm repository update --name ${REPOSITORY} --osv-config ""
33+
test "$(get_osv_config $REPOSITORY)" = "null"
34+
35+
# osv_config can be modified
36+
expect_succ pulp rpm repository update --name ${REPOSITORY} --osv-config "${OSV_CONFIG_B}"
37+
test "$(get_osv_config $REPOSITORY)" != "null"
38+
39+
# vulnerability generates a report
40+
pulp rpm content -t package create --file-url "${KERNEL_URL}" --repository ${REPOSITORY}
41+
expect_succ pulp rpm repository version scan --repository ${REPOSITORY}
42+
VULN_REPORT="$(pulp rpm repository version show --repository ${REPOSITORY} | jq -r '.vuln_report')"
43+
VULN_COUNT="$(pulp show --href "$VULN_REPORT" | jq '.results[0].vulns | length')"
44+
test "$VULN_COUNT" -gt 50 # kernels has lots of vuln reports
45+
46+
# absence of osv_config fails
47+
pulp rpm repository create --name ${REPOSITORY_NO_CONFIG}
48+
expect_fail pulp rpm repository version scan --repository ${REPOSITORY_NO_CONFIG}

0 commit comments

Comments
 (0)