Skip to content

Commit

Permalink
Merge duplicate package entries for deb-installed Python packages for…
Browse files Browse the repository at this point in the history
… Debian (#23325)

#22219

Note caveats in added tests; we may need to add more matching logic here
based on the Debian Bookworm repro I did.

# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
  • Loading branch information
iansltx authored Oct 29, 2024
1 parent 4b14f73 commit 12b2914
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/22219-python-package-demian
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Addressed Debian python package false positive vulnerabilities by removing duplicate entries for Debian python packages installed by dpkg and renaming remaining pip installed packages to match OVAL definitions.
8 changes: 4 additions & 4 deletions server/service/osquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -1249,21 +1249,21 @@ func preProcessSoftwareResults(
preProcessSoftwareExtraResults(fullQueryName, host.ID, results, statuses, messages, query, logger)
}

// Filter out python packages that are also deb packages on ubuntu
// Filter out python packages that are also deb packages on ubuntu/debian
pythonPackageFilter(host.Platform, results, statuses)
}

// pythonPackageFilter filters out duplicate python_packages that are installed under deb_packages on Ubuntu.
// pythonPackageFilter filters out duplicate python_packages that are installed under deb_packages on Ubuntu and Debian.
// python_packages not matching a Debian package names are updated to "python3-packagename" to match OVAL definitions.
func pythonPackageFilter(platform string, results *fleet.OsqueryDistributedQueryResults, statuses *map[string]fleet.OsqueryStatus) {
const pythonPrefix = "python3-"
const pythonSource = "python_packages"
const debSource = "deb_packages"
const linuxSoftware = hostDetailQueryPrefix + "software_linux"

// Return early if platform is not Ubuntu
// Return early if platform is not Ubuntu or Debian
// We may need to add more platforms in the future
if platform != "ubuntu" {
if platform != "ubuntu" && platform != "debian" {
return
}

Expand Down
53 changes: 52 additions & 1 deletion server/service/osquery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3964,7 +3964,58 @@ func TestPreProcessSoftwareResults(t *testing.T) {
},
},
{
name: "non-ubuntu installed python packages are NOT filtered out",
name: "debian dpkg installed python packages are filtered out",
host: &fleet.Host{ID: 1, Platform: "debian"},
statusesIn: map[string]fleet.OsqueryStatus{
hostDetailQueryPrefix + "software_linux": fleet.StatusOK,
},
resultsIn: fleet.OsqueryDistributedQueryResults{
hostDetailQueryPrefix + "software_linux": []map[string]string{
{
"name": "python3-twisted",
"version": "22.4.0-4",
"source": "deb_packages",
},
{
"name": "Twisted", // duplicate of python3-twisted
"version": "22.4.0-4",
"source": "python_packages",
},
// known issue below: names don't match so we don't deduplicate
{
"name": "python3-attr", // osquery source column is python-attrs
"version": "22.2.0-1",
"source": "deb_packages",
},
{
"name": "Attrs",
"version": "22.2.0",
"source": "python_packages",
},
},
},
resultsOut: fleet.OsqueryDistributedQueryResults{
hostDetailQueryPrefix + "software_linux": []map[string]string{
{
"name": "python3-twisted",
"version": "22.4.0-4",
"source": "deb_packages",
},
{
"name": "python3-attr",
"version": "22.2.0-1",
"source": "deb_packages",
},
{
"name": "python3-attrs",
"version": "22.2.0",
"source": "python_packages",
},
},
},
},
{
name: "non-ubuntu/debian installed python packages are NOT filtered out",
host: &fleet.Host{ID: 1, Platform: "rhel"},
statusesIn: map[string]fleet.OsqueryStatus{
hostDetailQueryPrefix + "software_linux": fleet.StatusOK,
Expand Down

0 comments on commit 12b2914

Please sign in to comment.