Skip to content

Commit

Permalink
fix(misconf): Parse JSON k8s manifests properly (#6490)
Browse files Browse the repository at this point in the history
  • Loading branch information
simar7 committed Apr 19, 2024
1 parent 13e72ec commit 9b7d713
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 168 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -138,6 +138,7 @@ require (
github.com/zclconf/go-cty-yaml v1.0.3
golang.org/x/crypto v0.19.0
helm.sh/helm/v3 v3.14.2
sigs.k8s.io/yaml v1.4.0
)

require (
Expand Down Expand Up @@ -433,5 +434,4 @@ require (
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
7 changes: 6 additions & 1 deletion pkg/iac/scanners/kubernetes/parser/parser.go
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"gopkg.in/yaml.v3"
kyaml "sigs.k8s.io/yaml"

"github.com/aquasecurity/trivy/pkg/iac/debug"
"github.com/aquasecurity/trivy/pkg/iac/detection"
Expand Down Expand Up @@ -113,7 +114,11 @@ func (p *Parser) Parse(r io.Reader, path string) ([]interface{}, error) {
if err := json.Unmarshal(contents, &target); err != nil {
return nil, err
}
return []interface{}{target}, nil

contents, err = kyaml.JSONToYAML(contents) // convert into yaml to reuse file parsing logic
if err != nil {
return nil, err
}
}

var results []interface{}
Expand Down

0 comments on commit 9b7d713

Please sign in to comment.