Skip to content

Conversation

@DmitriyLewen
Copy link
Contributor

Description

This PR fixes an issue where OS package PURLs (Package URLs) were not being updated when the --distro flag is used to override the detected OS. Previously, when Trivy detected one OS version but the user specified a different one via
the distro flag, the package PURLs would still contain the originally detected OS information, creating inconsistency between the overridden OS and the package metadata.

Examples:

  1. Override OS
    before:
    ➜  trivy -q image almalinux:9.5 -f json --distro alma/9.6 | jq '{OS: .Metadata.OS, pkg: .Results[].Packages[0].Identifier.PURL}' 
    {
      "OS": {
        "Family": "alma",
        "Name": "9.6"
      },
      "pkg": "pkg:rpm/alma/[email protected]?arch=x86_64&distro=alma-9.5"
    }
    after:
    ➜  ./trivy -q image almalinux:9.5 -f json --distro alma/9.6 | jq '{OS: .Metadata.OS, pkg: .Results[].Packages[0].Identifier.PURL}'
    {
      "OS": {
        "Family": "alma",
        "Name": "9.6"
      },
      "pkg": "pkg:rpm/alma/[email protected]?arch=x86_64&distro=alma-9.6"
    }
  2. Override empty OS
    before:
    ➜  trivy -q image slos-test:latest -f json --distro alma/9.6 | jq '{OS: .Metadata.OS, pkg: .Results[0].Packages[0].Identifier.PURL}' 
    {
      "OS": {
        "Family": "alma",
        "Name": "9.6"
      },
      "pkg": null
    }
    after:
    ➜  ./trivy -q image slos-test:latest -f json --distro alma/9.6 | jq '{OS: .Metadata.OS, pkg: .Results[0].Packages[0].Identifier.PURL}'
    {
      "OS": {
        "Family": "alma",
        "Name": "9.6"
      },
      "pkg": "pkg:rpm/alma/[email protected]?arch=x86_64&distro=alma-9.6"
    }
    

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen changed the title fix: overwrite PURLs after overwrite OS fix: overwrite OS packages PURLs after overwrite OS Nov 13, 2025
@DmitriyLewen DmitriyLewen self-assigned this Nov 13, 2025
@DmitriyLewen DmitriyLewen added the autoready Automatically mark PR as ready for review when all checks pass label Nov 13, 2025
@github-actions github-actions bot marked this pull request as ready for review November 13, 2025 08:57
@github-actions github-actions bot requested a review from knqyf263 as a code owner November 13, 2025 08:57
@github-actions github-actions bot removed the autoready Automatically mark PR as ready for review when all checks pass label Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Trivy should overwrite the namespace and distro qualifier for PURLs when the --distro flag is used.

1 participant