From 5dd86bcc045c8f2d61956a260d2b11432969b9b1 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Thu, 9 Nov 2023 08:47:02 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20support=20querypack=20execution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Requires: https://github.com/mondoohq/cnquery/pull/2545 + updated `go.mod`. ```bash cnspec scan -f ../cnquery/examples/os.mql.yaml ``` ... now works as advertised: ```bash Data queries: services.where.list: [ 0: service name="sshd" running=false enabled=false type="systemd" 1: service name="sshdgenkeys" running=false enabled=false type="systemd" ] packages.where.list: [ 0: package name="lib32-libssh2" version="1.11.0-1" 1: package name="libssh" version="0.10.5-1" 2: package name="libssh2" version="1.11.0-1" 3: package name="openssh" version="9.5p1-1" 4: package name="sshfs" version="3.7.3-1" ] ... ``` Signed-off-by: Dominik Richter --- apps/cnspec/cmd/scan.go | 2 ++ policy/bundle.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/apps/cnspec/cmd/scan.go b/apps/cnspec/cmd/scan.go index 677807eb..c8a26458 100644 --- a/apps/cnspec/cmd/scan.go +++ b/apps/cnspec/cmd/scan.go @@ -324,6 +324,8 @@ func (c *scanConfig) loadPolicies() error { return err } + bundle.ConvertQuerypacks() + _, err = bundle.CompileExt(context.Background(), policy.BundleCompileConf{ Schema: c.runtime.Schema(), // We don't care about failing queries for local runs. We may only diff --git a/policy/bundle.go b/policy/bundle.go index 684a8163..ca49637b 100644 --- a/policy/bundle.go +++ b/policy/bundle.go @@ -148,6 +148,7 @@ func aggregateBundles(a *Bundle, b *Bundle) *Bundle { // merge in a res.Policies = append(res.Policies, a.Policies...) + res.Packs = append(res.Packs, a.Packs...) res.Props = append(res.Props, a.Props...) res.Queries = append(res.Queries, a.Queries...) res.Frameworks = append(res.Frameworks, a.Frameworks...) @@ -155,6 +156,7 @@ func aggregateBundles(a *Bundle, b *Bundle) *Bundle { // merge in b res.Policies = append(res.Policies, b.Policies...) + res.Packs = append(res.Packs, b.Packs...) res.Props = append(res.Props, b.Props...) res.Queries = append(res.Queries, b.Queries...) res.Frameworks = append(res.Frameworks, b.Frameworks...) @@ -181,6 +183,10 @@ func (p *Bundle) ConvertQuerypacks() { for i := range p.Packs { pack := p.Packs[i] + // Remove this once we reach v10 vv + pack.DeprecatedV9_ensureUIDs() + // ^^ + policy := Policy{ Mrn: pack.Mrn, Uid: pack.Uid,