Skip to content

fix(os): keep the fullest OS version when merging analyzer results - #11039

Open
DmitriyLewen wants to merge 2 commits into
aquasecurity:mainfrom
DmitriyLewen:fix/os-merge-full-version
Open

fix(os): keep the fullest OS version when merging analyzer results#11039
DmitriyLewen wants to merge 2 commits into
aquasecurity:mainfrom
DmitriyLewen:fix/os-merge-full-version

Conversation

@DmitriyLewen

Copy link
Copy Markdown
Contributor

Description

/etc/os-release and the distro-specific release file can describe the same OS with different granularity.
On CentOS 7 the former reports VERSION_ID=7, while /etc/centos-release reports 7.9.2009.
Both files are analyzed concurrently, and OS.Merge filled Name only while it was still empty, so the reported version depended on which analyzer merged first.

In practice the winner is decided by the order of the entries in the layer tar, which normally puts /etc/centos-release first.
That order is not part of the contract though.
Rebuilding the same layer with /etc/os-release moved ahead of /etc/centos-release — with the contents of every file unchanged — flips the reported version to 7 in 100% of runs.

Changes

OS.Merge now keeps the more specific version when both sources describe the same family: a new name replaces the current one when the current one is a dotted prefix of it.
CentOS is the only distribution affected in practice — Rocky, Alma, Oracle, RHEL and Fedora put the full x.y version into VERSION_ID, so their sources already agree.

Example

Before / after, same image with /etc/os-release placed first in the layer tar:

Before:

"OS": { "Family": "centos", "Name": "7" }

After:

"OS": { "Family": "centos", "Name": "7.6.1810" }

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 self-assigned this Aug 4, 2026
@DmitriyLewen DmitriyLewen added kind/bug Categorizes issue or PR as related to a bug. autoready Automatically mark PR as ready for review when all checks pass labels Aug 4, 2026
@github-actions
github-actions Bot marked this pull request as ready for review August 4, 2026 13:00
@github-actions github-actions Bot removed the autoready Automatically mark PR as ready for review when all checks pass label Aug 4, 2026
@github-actions
github-actions Bot requested a review from knqyf263 as a code owner August 4, 2026 13:00
if o.Name == "" {
// One of the sources may report a shortened version, e.g. 7 and 7.9.2009 for CentOS.
// We always take the fullest version.
if o.Name == "" || (o.Family == newOS.Family && strings.HasPrefix(newOS.Name, o.Name+".")) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we bump the relevant analyzer version so that old cached OS results are not reused?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants