Skip to content

Commit

Permalink
✨ support querypack execution
Browse files Browse the repository at this point in the history
Requires: mondoohq/cnquery#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 <[email protected]>
  • Loading branch information
arlimus committed Nov 9, 2023
1 parent bb87d0e commit 5dd86bc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/cnspec/cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions policy/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ 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...)
res.FrameworkMaps = append(res.FrameworkMaps, a.FrameworkMaps...)

// 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...)
Expand All @@ -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()

Check failure on line 187 in policy/bundle.go

View workflow job for this annotation

GitHub Actions / golangci-lint

pack.DeprecatedV9_ensureUIDs undefined (type *explorer.QueryPack has no field or method DeprecatedV9_ensureUIDs)) (typecheck)

Check failure on line 187 in policy/bundle.go

View workflow job for this annotation

GitHub Actions / go-test

pack.DeprecatedV9_ensureUIDs undefined (type *explorer.QueryPack has no field or method DeprecatedV9_ensureUIDs)

Check failure on line 187 in policy/bundle.go

View workflow job for this annotation

GitHub Actions / go-test

pack.DeprecatedV9_ensureUIDs undefined (type *explorer.QueryPack has no field or method DeprecatedV9_ensureUIDs)
// ^^

policy := Policy{
Mrn: pack.Mrn,
Uid: pack.Uid,
Expand Down

0 comments on commit 5dd86bc

Please sign in to comment.