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

fix(misconf): skip Rego errors with a nil location #6638

Merged
merged 1 commit into from
May 6, 2024

Conversation

nikpivkin
Copy link
Contributor

Description

We have to skip errors without locations.

#6502 (comment)

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@nikpivkin nikpivkin marked this pull request as ready for review May 6, 2024 14:22
@nikpivkin nikpivkin requested a review from simar7 as a code owner May 6, 2024 14:22
@simar7 simar7 added this pull request to the merge queue May 6, 2024
Merged via the queue into aquasecurity:main with commit a2c522d May 6, 2024
12 checks passed
@chen-keinan
Copy link
Contributor

chen-keinan commented May 8, 2024

@nikpivkin @simar7 it still panic at L187 : return !lo.Contains(excludedFiles, e.Location.File)

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x1032e5134]

goroutine 932 [running]:
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
	/Users/chen.keinan/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:111 +0x1a4
panic({0x10522fbe0?, 0x107a92230?})
	/opt/homebrew/Cellar/go/1.22.2/libexec/src/runtime/panic.go:770 +0x124
github.com/aquasecurity/trivy/pkg/iac/rego.(*Scanner).fallbackChecks.func1(0x1400213bb38?, 0x1032e4f70?)
	/Users/chen.keinan/go/pkg/mod/github.com/aquasecurity/[email protected]/pkg/iac/rego/load.go:187 +0x24
github.com/samber/lo.Filter[...]({0x14002708380, 0xb, 0x3d}, 0x1400213bc08?)
	/Users/chen.keinan/go/pkg/mod/github.com/samber/[email protected]/slice.go:15 +0x8c
github.com/aquasecurity/trivy/pkg/iac/rego.(*Scanner).fallbackChecks(0x14002e26360, 0x140019ec160)
	/Users/chen.keinan/go/pkg/mod/github.com/aquasecurity/[email protected]/pkg/iac/rego/load.go:186 +0xd4
github.com/aquasecurity/trivy/pkg/iac/rego.(*Scanner).compilePolicies(0x14002e26360, {0x10588a040, 0x1400498a720}, {0x140018a2b20, 0x1, 0x1})
	/Users/chen.keinan/go/pkg/mod/github.com/aquasecurity/[email protected]/pkg/iac/rego/load.go:245 +0x120
github.com/aquasecurity/trivy/pkg/iac/rego.(*Scanner).compilePolicies(0x14002e26360, {0x10588a040, 0x1400498a720}, {0x140018a2b20, 0x1, 0x1})
	/Users/chen.keinan/go/pkg/mod/github.com/aquasecurity/[email protected]/pkg/iac/rego/load.go:249 +0x158
github.com/aquasecurity/trivy/pkg/iac/rego.(*Scanner).LoadPolicies(0x14002e26360, 0x0, 0x0, {0x10588a040?, 0x1400498a720?}, {0x140018a2b20, 0x1, 0x1}, {0x0, 0x0, ...})
	/Users/chen.keinan/go/pkg/mod/github.com/aquasecurity/[email protected]/pkg/iac/rego/load.go:144 +0x7f8
github.com/aquasecurity/trivy/pkg/iac/scanners/kubernetes.(*Scanner).initRegoScanner(0x14000363980, {0x10588a040, 0x1400498a720})

@nikpivkin
Copy link
Contributor Author

@chen-keinan Do you have an example of a policy that is causing this problem that I could add a test?

@nikpivkin nikpivkin deleted the rego-errs branch May 8, 2024 06:55
@chen-keinan
Copy link
Contributor

chen-keinan commented May 8, 2024

@chen-keinan Do you have an example of a policy that is causing this problem that I could add a test?

sure , here are the policies used in the tests:
https://github.com/aquasecurity/trivy-operator/tree/main/tests/envtest/testdata/content/policies/kubernetes/policies
note: it worked with trivy v0.50.4 after upgrading to trivy v0.51.1 it started to fail

@chen-keinan
Copy link
Contributor

@nikpivkin I have adde and example of policies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants