mondoohq / cnspec

An open source, cloud-native security to protect everything from build to runtime
https://cnspec.io
Other
276 stars 16 forks source link

v9 scan with `--sudo` panics on windows #767

Open czunker opened 1 year ago

czunker commented 1 year ago

Describe the bug

C:\Users\christian>cnspec.exe scan local --sudo -f bsi-sys12-windows-server.mql.yaml
→ no Mondoo configuration file provided, using defaults
! No credentials provided. Switching to --incognito mode.
→ discover related assets for 1 asset(s)
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
go.mondoo.com/cnspec/policy/scan.(*LocalScanner).distributeJob(0xc001113f10, 0xc001113f80, {0x178f060, 0xc00132cd80}, 0xc001344000)
        /home/runner/_work/cnspec/cnspec/policy/scan/local_scanner.go:367 +0x17a6
go.mondoo.com/cnspec/policy/scan.(*LocalScanner).RunIncognito(0x178f028?, {0x178f060, 0xc00132cd80}, 0xc001113f80)
        /home/runner/_work/cnspec/cnspec/policy/scan/local_scanner.go:180 +0x7b
go.mondoo.com/cnspec/apps/cnspec/cmd.RunScan(0xc0006159a0, {0x0?, 0xc000607b00?, 0x178f028?})
        /home/runner/_work/cnspec/cnspec/apps/cnspec/cmd/scan.go:285 +0x305
go.mondoo.com/cnspec/apps/cnspec/cmd.glob..func13(0x0?, 0x178fe78?, 0x22a65a0?)
        /home/runner/_work/cnspec/cnspec/apps/cnspec/cmd/scan.go:120 +0xaf
go.mondoo.com/cnquery/cli/providers.setConnector.func2(0xc00046da00?, {0xc0004e3470?, 0x0, 0x3})
        /home/runner/go/pkg/mod/go.mondoo.com/cnquery@v0.0.0-20230927095627-c2c4003e085d/cli/providers/providers.go:446 +0x8c3
github.com/spf13/cobra.(*Command).execute(0xc0004ef200, {0xc0004e3410, 0x3, 0x3})
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:944 +0x863
github.com/spf13/cobra.(*Command).ExecuteC(0x22360a0)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
go.mondoo.com/cnspec/apps/cnspec/cmd.Execute()
        /home/runner/_work/cnspec/cnspec/apps/cnspec/cmd/root.go:109 +0x19b
main.main()
        /home/runner/_work/cnspec/cnspec/apps/cnspec/cnspec.go:9 +0xf

To Reproduce Steps to reproduce the behavior:

  1. Run scan local with --sudo on windows
  2. Note the error

Expected behavior Should work.

Desktop (please complete the following information):

Additional context w/o --sudo works.

czunker commented 1 year ago

The panic looks quite similar to this one: https://github.com/mondoohq/cnspec/issues/755

czunker commented 1 year ago

This works:

C:\Users\christian>cnquery.exe run local --sudo -c "asset"
→ no Mondoo configuration file provided, using defaults
asset: asset name="" platform="windows" version="20348"
czunker commented 1 year ago

--sudo in v8 does also not work, but fails differently:

C:\Users\christian>cnspecv8.exe scan local --sudo -f bsi-sys12-windows-server.mql.yaml
→ no Mondoo configuration file provided. using defaults
→ discover related assets for 1 asset(s)
→ resolved assets resolved-assets=0
x could not resolve asset error="could not determine a platform identifier" asset=
FTL failed to run scan error="failed to resolve multiple assets"