Skip to content

Commit

Permalink
fix(selectors): Evaluate policy when no selectors are present (#1213)
Browse files Browse the repository at this point in the history
Signed-off-by: Simar <simar@linux.com>
  • Loading branch information
simar7 authored Feb 28, 2023
1 parent 2d6fe11 commit d994770
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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

0 comments on commit d994770

Please sign in to comment.