Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⭐️ Add Purl to macOS and Windows systems #4996

Merged
merged 2 commits into from
Dec 17, 2024
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
4 changes: 2 additions & 2 deletions cli/reporter/cnquery_report.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion explorer/cnquery_explorer.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions explorer/resources/cnquery_resources_explorer.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions explorer/scan/cnquery_explorer_scan.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions llx/llx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 33 additions & 11 deletions providers-sdk/v1/plugin/plugin_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions providers-sdk/v1/upstream/health/errors.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions providers-sdk/v1/upstream/health/health.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions providers-sdk/v1/upstream/mvd/cvss/cvss.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions providers-sdk/v1/upstream/mvd/mvd.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions providers-sdk/v1/upstream/upstream.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions providers/os/resources/packages/aix_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io"
"strings"

"github.com/package-url/packageurl-go"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
cpe2 "go.mondoo.com/cnquery/v11/providers/os/resources/cpe"
"go.mondoo.com/cnquery/v11/providers/os/resources/purl"
Expand Down Expand Up @@ -43,8 +42,10 @@ func parseAixPackages(pf *inventory.Platform, r io.Reader) ([]Package, error) {
Version: record[2],
Description: strings.TrimSpace(record[6]),
Format: AixPkgFormat,
PUrl: purl.NewPackageUrl(pf, record[1], record[2], "", "", packageurl.TypeGeneric),
CPEs: cpes,
PUrl: purl.NewPackageURL(
pf, purl.TypeGeneric, record[1], record[2], purl.WithNamespace(pf.Name),
).String(),
CPEs: cpes,
})

}
Expand Down
2 changes: 1 addition & 1 deletion providers/os/resources/packages/aix_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestParseAixPackages(t *testing.T) {
Name: "X11.apps.msmit",
Version: "7.3.0.0",
Description: "AIXwindows msmit Application",
PUrl: "pkg:generic/aix/X11.apps.msmit@7.3.0.0?distro=aix-7.2",
PUrl: "pkg:generic/aix/X11.apps.msmit@7.3.0.0?arch=powerpc&distro=aix-7.2",
CPEs: []string{
"cpe:2.3:a:x11.apps.msmit:x11.apps.msmit:7.3.0.0:*:*:*:*:*:powerpc:*",
"cpe:2.3:a:x11.apps.msmit:x11.apps.msmit:7.3.0:*:*:*:*:*:powerpc:*",
Expand Down
6 changes: 4 additions & 2 deletions providers/os/resources/packages/apk_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"path/filepath"
"regexp"

"github.com/package-url/packageurl-go"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
cpe2 "go.mondoo.com/cnquery/v11/providers/os/resources/cpe"
"go.mondoo.com/cnquery/v11/providers/os/resources/purl"
Expand Down Expand Up @@ -44,7 +43,10 @@ func ParseApkDbPackages(pf *inventory.Platform, input io.Reader) []Package {
}

pkg.Format = AlpinePkgFormat
pkg.PUrl = purl.NewPackageUrl(pf, pkg.Name, pkg.Version, pkg.Arch, pkg.Epoch, packageurl.TypeApk)
pkg.PUrl = purl.NewPackageURL(pf, purl.TypeApk, pkg.Name, pkg.Version,
purl.WithArch(pkg.Arch),
purl.WithEpoch(pkg.Epoch),
).String()

cpes, _ := cpe2.NewPackage2Cpe(pkg.Vendor, pkg.Name, pkg.Version, "", pf.Arch)
pkg.CPEs = cpes
Expand Down
6 changes: 4 additions & 2 deletions providers/os/resources/packages/dpkg_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"regexp"
"strings"

"github.com/package-url/packageurl-go"
"github.com/rs/zerolog/log"
"github.com/spf13/afero"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
Expand Down Expand Up @@ -39,7 +38,10 @@ func ParseDpkgPackages(pf *inventory.Platform, input io.Reader) ([]Package, erro
add := func(pkg Package) {
// do sanitization checks to ensure we have minimal information
if pkg.Name != "" && pkg.Version != "" {
pkg.PUrl = purl.NewPackageUrl(pf, pkg.Name, pkg.Version, pkg.Arch, pkg.Epoch, packageurl.TypeDebian)
pkg.PUrl = purl.NewPackageURL(pf, purl.TypeDebian, pkg.Name, pkg.Version,
purl.WithArch(pkg.Arch),
purl.WithEpoch(pkg.Epoch),
).String()
cpes, _ := cpe.NewPackage2Cpe(pkg.Name, pkg.Name, pkg.Version, pkg.Epoch, pkg.Arch)
cpesWithoutArch, _ := cpe.NewPackage2Cpe(pkg.Name, pkg.Name, pkg.Version, pkg.Epoch, "")
cpes = append(cpes, cpesWithoutArch...)
Expand Down
12 changes: 9 additions & 3 deletions providers/os/resources/packages/macos_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"strings"

"github.com/cockroachdb/errors"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v11/providers/os/connection/shared"
"go.mondoo.com/cnquery/v11/providers/os/resources/purl"
plist "howett.net/plist"
)

Expand All @@ -18,7 +20,7 @@ const (
)

// parse macos system version property list
func ParseMacOSPackages(input io.Reader) ([]Package, error) {
func ParseMacOSPackages(platform *inventory.Platform, input io.Reader) ([]Package, error) {
var r io.ReadSeeker
r, ok := input.(io.ReadSeeker)

Expand Down Expand Up @@ -58,6 +60,9 @@ func ParseMacOSPackages(input io.Reader) ([]Package, error) {
pkgs[i].Version = entry.Version
pkgs[i].Format = MacosPkgFormat
pkgs[i].FilesAvailable = PkgFilesIncluded
pkgs[i].PUrl = purl.NewPackageURL(
platform, purl.TypeMacos, entry.Name, entry.Version,
).String()
if entry.Path != "" {
pkgs[i].Files = []FileRecord{
{
Expand All @@ -72,7 +77,8 @@ func ParseMacOSPackages(input io.Reader) ([]Package, error) {

// MacOS
type MacOSPkgManager struct {
conn shared.Connection
conn shared.Connection
platform *inventory.Platform
}

func (mpm *MacOSPkgManager) Name() string {
Expand All @@ -89,7 +95,7 @@ func (mpm *MacOSPkgManager) List() ([]Package, error) {
return nil, fmt.Errorf("could not read package list")
}

return ParseMacOSPackages(cmd.Stdout)
return ParseMacOSPackages(mpm.platform, cmd.Stdout)
}

func (mpm *MacOSPkgManager) Available() (map[string]PackageUpdate, error) {
Expand Down
10 changes: 9 additions & 1 deletion providers/os/resources/packages/macos_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,27 @@ func TestMacOsXPackageParser(t *testing.T) {
}
assert.Nil(t, err)

m, err := packages.ParseMacOSPackages(c.Stdout)
pf := &inventory.Platform{
Name: "macos",
Version: "15.2",
Arch: "x86_64",
Family: []string{"darwin", "bsd", "unix", "os"},
}
m, err := packages.ParseMacOSPackages(pf, c.Stdout)
assert.Nil(t, err)
assert.Equal(t, 2, len(m), "detected the right amount of packages")

assert.Equal(t, "Preview", m[0].Name, "pkg name detected")
assert.Equal(t, "10.0", m[0].Version, "pkg version detected")
assert.Equal(t, packages.MacosPkgFormat, m[0].Format, "pkg format detected")
assert.Equal(t, packages.PkgFilesIncluded, m[0].FilesAvailable)
assert.Equal(t, "pkg:macos/Preview@10.0?arch=x86_64", m[0].PUrl)
assert.Equal(t, []packages.FileRecord{{Path: "/Applications/Preview.app"}}, m[0].Files)

assert.Equal(t, "Contacts", m[1].Name, "pkg name detected")
assert.Equal(t, "11.0", m[1].Version, "pkg version detected")
assert.Equal(t, packages.MacosPkgFormat, m[1].Format, "pkg format detected")
assert.Equal(t, packages.PkgFilesIncluded, m[1].FilesAvailable)
assert.Equal(t, "pkg:macos/Contacts@11.0?arch=x86_64", m[1].PUrl)
assert.Equal(t, []packages.FileRecord{{Path: "/Applications/Contacts.app"}}, m[1].Files)
}
2 changes: 1 addition & 1 deletion providers/os/resources/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func ResolveSystemPkgManager(conn shared.Connection) (OperatingSystemPkgManager,
case asset.Platform.Name == "alpine" || asset.Platform.Name == "wolfi": // alpine & wolfi share apk
pm = &AlpinePkgManager{conn: conn, platform: asset.Platform}
case asset.Platform.Name == "macos": // mac os family
pm = &MacOSPkgManager{conn: conn}
pm = &MacOSPkgManager{conn: conn, platform: asset.Platform}
case asset.Platform.Name == "windows":
pm = &WinPkgManager{conn: conn, platform: asset.Platform}
case asset.Platform.Name == "scratch" || asset.Platform.Name == "coreos":
Expand Down
Loading
Loading