Skip to content

Commit 6207169

Browse files
authored
Introduce scalibr inventory extractor for dpkg/rpm/cos os/filesystem extractors (linux) (#834)
* bump go 1.23.0 -> 1.24.0 (scalibr prerequisite) * go get github.com/google/osv-scalibr * rm `google.golang.org/grpc/stats/opentelemetry v0.0.0-20240907200651-3ffb98b2c93a // indirect`, go mod tidy * Introduce scalibr extracted packages mappers for os/dpkg, os/rpm, os/cos * Introduce metadata[inventory-extractor] == "scalibr" setting for early scalibr runs * Implement scalibr inventory extractor (zypper excluded from scan for now) * Fix go 1.24-related go vet `ospatch/system_windows.go:52:21: non-constant format string in call` failure * Address config-related review issues * Fail fast on scalibr config issues * Add scalibr integration test (dpkg) * Extend cos mapper test * Add fallback zypperPatches extractor to scalibr provider * Disable zypper in scalibr integration test
1 parent 386b335 commit 6207169

File tree

12 files changed

+709
-26
lines changed

12 files changed

+709
-26
lines changed

agentconfig/agentconfig.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ type config struct {
131131
taskNotificationEnabled bool
132132
guestPoliciesEnabled bool
133133
osInventoryEnabled bool
134+
scalibrLinuxEnabled bool
134135
guestAttributesEnabled bool
135136
traceGetInventory bool
136137
}
@@ -221,6 +222,7 @@ type attributesJSON struct {
221222
DisabledFeatures string `json:"osconfig-disabled-features"`
222223
EnableGuestAttributes string `json:"enable-guest-attributes"`
223224
TraceGetInventory string `json:"trace-get-inventory"`
225+
ScalibrLinuxEnabled string `json:"enable-scalibr-linux"`
224226
}
225227

226228
func createConfigFromMetadata(md metadataJSON) *config {
@@ -351,12 +353,24 @@ func createConfigFromMetadata(md metadataJSON) *config {
351353
c.debugEnabled = true
352354
}
353355

356+
setScalibrEnablement(md, c)
354357
setSVCEndpoint(md, c)
355358
setTraceGetInventory(md, c)
356359

357360
return c
358361
}
359362

363+
func setScalibrEnablement(md metadataJSON, c *config) {
364+
projectSetting := md.Project.Attributes.ScalibrLinuxEnabled
365+
instanceSetting := md.Instance.Attributes.ScalibrLinuxEnabled
366+
if projectSetting != "" {
367+
c.scalibrLinuxEnabled = parseBool(projectSetting)
368+
}
369+
if instanceSetting != "" {
370+
c.scalibrLinuxEnabled = parseBool(instanceSetting)
371+
}
372+
}
373+
360374
func setSVCEndpoint(md metadataJSON, c *config) {
361375
switch {
362376
case *endpoint != prodEndpoint:
@@ -549,6 +563,11 @@ func DisableLocalLogging() bool {
549563
return *disableLocalLogging
550564
}
551565

566+
// ScalibrLinuxEnabled answers whether scalibr or legacy inventory extractors should be used.
567+
func ScalibrLinuxEnabled() bool {
568+
return getAgentConfig().scalibrLinuxEnabled
569+
}
570+
552571
// SvcEndpoint is the OS Config service endpoint.
553572
func SvcEndpoint() string {
554573
return getAgentConfig().svcEndpoint

go.mod

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/GoogleCloudPlatform/osconfig
22

3-
go 1.23.0
3+
go 1.24.0
44

55
toolchain go1.24.2
66

@@ -14,6 +14,7 @@ require (
1414
github.com/go-ole/go-ole v1.3.0
1515
github.com/golang/mock v1.6.0
1616
github.com/google/go-cmp v0.7.0
17+
github.com/google/osv-scalibr v0.2.0
1718
github.com/kr/pretty v0.3.1
1819
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
1920
github.com/ulikunitz/xz v0.5.12
@@ -23,8 +24,8 @@ require (
2324
google.golang.org/api v0.214.0
2425
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697
2526
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576
26-
google.golang.org/grpc v1.68.0
27-
google.golang.org/protobuf v1.36.3
27+
google.golang.org/grpc v1.70.0
28+
google.golang.org/protobuf v1.36.5
2829
)
2930

3031
require (
@@ -36,30 +37,98 @@ require (
3637
cloud.google.com/go/logging v1.13.0 // indirect
3738
cloud.google.com/go/longrunning v0.6.3 // indirect
3839
cloud.google.com/go/monitoring v1.21.2 // indirect
40+
deps.dev/api/v3 v3.0.0-20250307021655-d811e36f9cad // indirect
41+
deps.dev/util/maven v0.0.0-20250307021655-d811e36f9cad // indirect
42+
deps.dev/util/pypi v0.0.0-20250307021655-d811e36f9cad // indirect
43+
deps.dev/util/resolve v0.0.0-20250310223405-f4cf91c9e684 // indirect
44+
deps.dev/util/semver v0.0.0-20250307021655-d811e36f9cad // indirect
45+
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
46+
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect
47+
github.com/BurntSushi/toml v1.3.2 // indirect
48+
github.com/CycloneDX/cyclonedx-go v0.9.0 // indirect
3949
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0 // indirect
4050
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.49.0 // indirect
4151
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0 // indirect
52+
github.com/Microsoft/go-winio v0.6.2 // indirect
53+
github.com/Microsoft/hcsshim v0.11.7 // indirect
54+
github.com/anchore/go-struct-converter v0.0.0-20230627203149-c72ef8859ca9 // indirect
4255
github.com/cespare/xxhash/v2 v2.3.0 // indirect
4356
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
57+
github.com/containerd/cgroups v1.1.0 // indirect
58+
github.com/containerd/containerd v1.7.27 // indirect
59+
github.com/containerd/containerd/api v1.8.0 // indirect
60+
github.com/containerd/continuity v0.4.4 // indirect
61+
github.com/containerd/errdefs v0.3.0 // indirect
62+
github.com/containerd/fifo v1.1.0 // indirect
63+
github.com/containerd/log v0.1.0 // indirect
64+
github.com/containerd/platforms v0.2.1 // indirect
65+
github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect
66+
github.com/containerd/ttrpc v1.2.7 // indirect
67+
github.com/containerd/typeurl/v2 v2.1.1 // indirect
68+
github.com/davecgh/go-spew v1.1.1 // indirect
69+
github.com/deitch/magic v0.0.0-20240306090643-c67ab88f10cb // indirect
70+
github.com/distribution/reference v0.6.0 // indirect
71+
github.com/docker/cli v25.0.3+incompatible // indirect
72+
github.com/docker/distribution v2.8.3+incompatible // indirect
73+
github.com/docker/docker v25.0.6+incompatible // indirect
74+
github.com/docker/docker-credential-helpers v0.8.1 // indirect
75+
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
76+
github.com/edsrzf/mmap-go v1.1.0 // indirect
4477
github.com/envoyproxy/go-control-plane/envoy v1.32.3 // indirect
4578
github.com/envoyproxy/go-control-plane/ratelimit v0.1.0 // indirect
4679
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
80+
github.com/erikvarga/go-rpmdb v0.0.0-20240208180226-b97e041ef9af // indirect
4781
github.com/felixge/httpsnoop v1.0.4 // indirect
82+
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
83+
github.com/go-git/go-billy/v5 v5.6.2 // indirect
84+
github.com/go-git/go-git/v5 v5.14.0 // indirect
4885
github.com/go-logr/logr v1.4.2 // indirect
4986
github.com/go-logr/stdr v1.2.2 // indirect
87+
github.com/gobwas/glob v0.2.3 // indirect
88+
github.com/gogo/protobuf v1.3.2 // indirect
5089
github.com/golang/glog v1.2.4 // indirect
90+
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
5191
github.com/golang/protobuf v1.5.4 // indirect
92+
github.com/google/go-containerregistry v0.19.1 // indirect
5293
github.com/google/s2a-go v0.1.8 // indirect
5394
github.com/google/uuid v1.6.0 // indirect
5495
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
5596
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
97+
github.com/groob/plist v0.1.1 // indirect
98+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
5699
github.com/julienschmidt/httprouter v1.3.0 // indirect
100+
github.com/klauspost/compress v1.17.7 // indirect
57101
github.com/kr/text v0.2.0 // indirect
102+
github.com/mattn/go-sqlite3 v1.14.28 // indirect
103+
github.com/mitchellh/go-homedir v1.1.0 // indirect
104+
github.com/moby/locker v1.0.1 // indirect
105+
github.com/moby/sys/mountinfo v0.6.2 // indirect
106+
github.com/moby/sys/sequential v0.5.0 // indirect
107+
github.com/moby/sys/signal v0.7.0 // indirect
108+
github.com/moby/sys/user v0.3.0 // indirect
109+
github.com/moby/sys/userns v0.1.0 // indirect
110+
github.com/opencontainers/go-digest v1.0.0 // indirect
111+
github.com/opencontainers/image-spec v1.1.0 // indirect
112+
github.com/opencontainers/runtime-spec v1.1.0 // indirect
113+
github.com/opencontainers/selinux v1.11.0 // indirect
114+
github.com/package-url/packageurl-go v0.1.2 // indirect
58115
github.com/pkg/errors v0.9.1 // indirect
59116
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
60-
github.com/rogpeppe/go-internal v1.13.1 // indirect
117+
github.com/rogpeppe/go-internal v1.14.1 // indirect
118+
github.com/rust-secure-code/go-rustaudit v0.0.0-20250226111315-e20ec32e963c // indirect
119+
github.com/saferwall/pe v1.5.6 // indirect
120+
github.com/secDre4mer/pkcs7 v0.0.0-20240322103146-665324a4461d // indirect
61121
github.com/sirupsen/logrus v1.9.3 // indirect
122+
github.com/spdx/gordf v0.0.0-20221230105357-b735bd5aac89 // indirect
123+
github.com/spdx/tools-golang v0.5.3 // indirect
124+
github.com/tidwall/gjson v1.18.0 // indirect
125+
github.com/tidwall/jsonc v0.3.2 // indirect
126+
github.com/tidwall/match v1.1.1 // indirect
127+
github.com/tidwall/pretty v1.2.0 // indirect
128+
github.com/vbatts/tar-split v0.11.5 // indirect
62129
go.chromium.org/luci v0.0.0-20201204084249-3e81ee3e83fe // indirect
130+
go.etcd.io/bbolt v1.3.10 // indirect
131+
go.opencensus.io v0.24.0 // indirect
63132
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
64133
go.opentelemetry.io/contrib/detectors/gcp v1.32.0 // indirect
65134
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0 // indirect
@@ -69,10 +138,18 @@ require (
69138
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
70139
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect
71140
go.opentelemetry.io/otel/trace v1.35.0 // indirect
141+
go.uber.org/multierr v1.11.0 // indirect
142+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
143+
golang.org/x/mod v0.21.0 // indirect
72144
golang.org/x/net v0.40.0 // indirect
73145
golang.org/x/sync v0.14.0 // indirect
74146
golang.org/x/text v0.25.0 // indirect
75147
golang.org/x/time v0.9.0 // indirect
76-
google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect
77-
google.golang.org/grpc/stats/opentelemetry v0.0.0-20240907200651-3ffb98b2c93a // indirect
148+
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
149+
google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a // indirect
150+
gopkg.in/ini.v1 v1.67.0 // indirect
151+
gopkg.in/warnings.v0 v0.1.2 // indirect
152+
gopkg.in/yaml.v3 v3.0.1 // indirect
153+
sigs.k8s.io/yaml v1.4.0 // indirect
154+
www.velocidex.com/golang/regparser v0.0.0-20240404115756-2169ac0e3c09 // indirect
78155
)

0 commit comments

Comments
 (0)