@@ -17,12 +17,30 @@ import (
17
17
18
18
"github.com/aquasecurity/trivy/pkg/iac/debug"
19
19
"github.com/aquasecurity/trivy/pkg/iac/framework"
20
+ "github.com/aquasecurity/trivy/pkg/iac/providers"
20
21
"github.com/aquasecurity/trivy/pkg/iac/rego/schemas"
21
22
"github.com/aquasecurity/trivy/pkg/iac/scan"
22
23
"github.com/aquasecurity/trivy/pkg/iac/scanners/options"
23
24
"github.com/aquasecurity/trivy/pkg/iac/types"
24
25
)
25
26
27
+ var checkTypesWithSubtype = map [types.Source ]struct {}{
28
+ types .SourceCloud : {},
29
+ types .SourceDefsec : {},
30
+ types .SourceKubernetes : {},
31
+ }
32
+
33
+ var supportedProviders = makeSupportedProviders ()
34
+
35
+ func makeSupportedProviders () map [string ]struct {} {
36
+ m := make (map [string ]struct {})
37
+ for _ , p := range providers .AllProviders () {
38
+ m [string (p )] = struct {}{}
39
+ }
40
+ m ["kind" ] = struct {}{} // kubernetes
41
+ return m
42
+ }
43
+
26
44
var _ options.ConfigurableScanner = (* Scanner )(nil )
27
45
28
46
type Scanner struct {
@@ -295,12 +313,8 @@ func (s *Scanner) ScanInput(ctx context.Context, inputs ...Input) (scan.Results,
295
313
}
296
314
297
315
func isPolicyWithSubtype (sourceType types.Source ) bool {
298
- for _ , s := range []types.Source {types .SourceCloud , types .SourceDefsec , types .SourceKubernetes } {
299
- if sourceType == s {
300
- return true
301
- }
302
- }
303
- return false
316
+ _ , exists := checkTypesWithSubtype [sourceType ]
317
+ return exists
304
318
}
305
319
306
320
func checkSubtype (ii map [string ]any , provider string , subTypes []SubType ) bool {
@@ -311,10 +325,11 @@ func checkSubtype(ii map[string]any, provider string, subTypes []SubType) bool {
311
325
for _ , st := range subTypes {
312
326
switch services := ii [provider ].(type ) {
313
327
case map [string ]any :
314
- for service := range services {
315
- if (service == st .Service ) && (st .Provider == provider ) {
316
- return true
317
- }
328
+ if st .Provider != provider {
329
+ continue
330
+ }
331
+ if _ , exists := services [st .Service ]; exists {
332
+ return true
318
333
}
319
334
case string : // k8s - logic can be improved
320
335
if strings .EqualFold (services , st .Group ) ||
@@ -331,8 +346,7 @@ func isPolicyApplicable(staticMetadata *StaticMetadata, inputs ...Input) bool {
331
346
for _ , input := range inputs {
332
347
if ii , ok := input .Contents .(map [string ]any ); ok {
333
348
for provider := range ii {
334
- // TODO(simar): Add other providers
335
- if ! strings .Contains (strings .Join ([]string {"kind" , "aws" , "azure" }, "," ), provider ) {
349
+ if _ , exists := supportedProviders [provider ]; ! exists {
336
350
continue
337
351
}
338
352
0 commit comments