Skip to content

Commit

Permalink
fix(selectors): Evaluate policy when no selectors are present
Browse files Browse the repository at this point in the history
Signed-off-by: Simar <[email protected]>
  • Loading branch information
simar7 committed Feb 28, 2023
1 parent 2d6fe11 commit 0f198cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pkg/rego/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ 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
return true
}

for _, st := range subTypes {
switch services := ii[provider].(type) {
case map[string]interface{}: // cloud
Expand Down Expand Up @@ -318,6 +314,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 0f198cc

Please sign in to comment.