diff --git a/scanpipe/pipes/rootfs.py b/scanpipe/pipes/rootfs.py index b587daa4c..2cddf1cc9 100644 --- a/scanpipe/pipes/rootfs.py +++ b/scanpipe/pipes/rootfs.py @@ -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 @@ -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): """ diff --git a/scanpipe/tests/data/basic-rootfs.tar.gz b/scanpipe/tests/data/basic-rootfs.tar.gz index e0b5a05fc..3bc4595ca 100644 Binary files a/scanpipe/tests/data/basic-rootfs.tar.gz and b/scanpipe/tests/data/basic-rootfs.tar.gz differ diff --git a/scanpipe/tests/data/basic-rootfs_root_filesystems.json b/scanpipe/tests/data/basic-rootfs_root_filesystems.json index ceed38586..acf75b44e 100644 --- a/scanpipe/tests/data/basic-rootfs_root_filesystems.json +++ b/scanpipe/tests/data/basic-rootfs_root_filesystems.json @@ -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", + "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" + } } } ] @@ -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,