Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions scanpipe/pipes/purldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,19 @@ def get_unique_unresolved_purls(project):
def populate_purldb_with_discovered_packages(project, logger=logger.info):
"""Add DiscoveredPackage to PurlDB."""
discoveredpackages = project.discoveredpackages.all()
packages = [{"purl": pkg.purl} for pkg in discoveredpackages]
packages_to_populate = []
for pkg in discoveredpackages:
package = {"purl": pkg.purl}
if pkg.source_packages:
package["source_purl"] = pkg.source_packages
packages_to_populate.append(package)

logger(f"Populating PurlDB with {len(packages):,d} PURLs from DiscoveredPackage")
logger(
f"Populating PurlDB with {len(packages_to_populate):,d}"
f" PURLs from DiscoveredPackage"
)
feed_purldb(
packages=packages,
packages=packages_to_populate,
chunk_size=100,
logger=logger,
)
Expand Down
21 changes: 21 additions & 0 deletions scanpipe/pipes/rootfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import fnmatch
import logging
import os
from collections import Counter

from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q
Expand Down Expand Up @@ -263,10 +264,30 @@ def scan_rootfs_for_system_packages(project, rootfs):
logger.info(f"rootfs location: {rootfs.location}")

installed_packages = rootfs.get_installed_packages(package_getter)

created_system_packages = []
seen_namespaces = []
for index, (purl, package) in enumerate(installed_packages):
logger.info(f"Creating package #{index}: {purl}")
created_system_packages.append(package)
seen_namespaces.append(package.namespace)
_create_system_package(project, purl, package)

namespace_counts = Counter(seen_namespaces)
# we overwite namespace only when there are multiple
# namespaces in the packages
if not len(namespace_counts.keys()) > 1:
return

most_seen_namespace = max(namespace_counts)
# if the distro_id is different from the namespace
# most seen in packages, we update all the package
# namespaces to the distro_id
if most_seen_namespace != distro_id:
for package in created_system_packages:
if package.namespace != distro_id:
package.update(namespace=distro_id)


def get_resource_with_md5(project, status):
"""
Expand Down
Binary file modified scanpipe/tests/data/basic-rootfs.tar.gz
Binary file not shown.
32 changes: 17 additions & 15 deletions scanpipe/tests/data/basic-rootfs_root_filesystems.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,26 @@
"distro": {
"os": "linux",
"architecture": null,
"name": "Debian GNU/Linux",
"version": "9 (stretch)",
"identifier": "debian",
"id_like": null,
"version_codename": null,
"version_id": "9",
"pretty_name": "Debian GNU/Linux 9 (stretch)",
"name": "Ubuntu",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I've updated the os-release file in the basic-rootfs test case to the ubuntu distro file, as the packages detected below seem to be ubuntu packages, and the old example seemed to be wrong. Otherwise the namespaces being overridden from this os-release file seemed to be wrong.

"version": "22.04.3 LTS (Jammy Jellyfish)",
"identifier": "ubuntu",
"id_like": "debian",
"version_codename": "jammy",
"version_id": "22.04",
"pretty_name": "Ubuntu 22.04.3 LTS",
"cpe_name": null,
"home_url": "https://www.debian.org/",
"home_url": "https://www.ubuntu.com/",
"documentation_url": null,
"support_url": "https://www.debian.org/support",
"bug_report_url": "https://bugs.debian.org/",
"privacy_policy_url": null,
"support_url": "https://help.ubuntu.com/",
"bug_report_url": "https://bugs.launchpad.net/ubuntu/",
"privacy_policy_url": "https://www.ubuntu.com/legal/terms-and-policies/privacy-policy",
"build_id": null,
"variant": null,
"variant_id": null,
"logo": null,
"extra_data": {}
"extra_data": {
"UBUNTU_CODENAME": "jammy"
}
}
}
]
Expand Down Expand Up @@ -355,9 +357,9 @@
"status": "ignored-not-interesting",
"tag": "",
"extension": "",
"md5": "8589b473401e7ebcca5d97204405c887",
"sha1": "29420ee3cb176f64209d5beddc5713133fa7c2d4",
"sha256": "aa6ccd5b1ade06c11f679cc781bdd3158f1007266ea391ed98a1bbf365641fd4",
"md5": "fd30c92c61acbdebbd205e33534ac9bc",
"sha1": "46d2cadf740c18ed8a1b30dbd7f5eeee521e1e8f",
"sha256": "4bde2c39f541afb5ac413a03c8e5f57aa99b8fab304a62386dc0b16044cc0e2d",
"sha512": "",
"programming_language": "",
"is_binary": false,
Expand Down