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(selectors): Evaluate policy when no selectors are present #1213

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/rego/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func isPolicyWithSubtype(sourceType types.Source) bool {
}

func checkSubtype(ii map[string]interface{}, provider string, subTypes []SubType) bool {
if len(subTypes) == 0 { // policy always applies if no subtypes
if len(subTypes) == 0 {
return true
}

Expand Down Expand Up @@ -318,6 +318,10 @@ func isPolicyApplicable(staticMetadata *StaticMetadata, inputs ...Input) bool {
continue
}

if len(staticMetadata.InputOptions.Selectors) == 0 { // policy always applies if no selectors
return true
}

// check metadata for subtype
for _, s := range staticMetadata.InputOptions.Selectors {
if checkSubtype(ii, provider, s.Subtypes) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/scanners/cloud/aws/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ deny[res] {
expectedResults: struct {
totalResults int
summaries []string
}{totalResults: 0},
}{totalResults: 2, summaries: []string{"RDS Publicly Accessible", "CloudTrail Bucket Delete Policy"}},
},
{
name: "selector is empty",
Expand Down Expand Up @@ -146,7 +146,7 @@ deny[res] {
expectedResults: struct {
totalResults int
summaries []string
}{totalResults: 0},
}{totalResults: 2, summaries: []string{"RDS Publicly Accessible", "CloudTrail Bucket Delete Policy"}},
},
{
name: "selector without subtype",
Expand Down