forked from aquasecurity/trivy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(misconf): Add terraformplan support (aquasecurity#4342)
* feat(misconf): Add terraformplan support Fixes: aquasecurity#4341 Signed-off-by: Simar <simar@linux.com> * update defsec * fix lint Signed-off-by: Simar <simar@linux.com> * remove debug prints Signed-off-by: Simar <simar@linux.com> * update tests Signed-off-by: Simar <simar@linux.com> --------- Signed-off-by: Simar <simar@linux.com>
- Loading branch information
1 parent
90581f1
commit e253b4f
Showing
10 changed files
with
176 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package terraformplan | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"k8s.io/utils/strings/slices" | ||
|
||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer" | ||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/config" | ||
"github.com/aquasecurity/trivy/pkg/misconf" | ||
) | ||
|
||
const ( | ||
analyzerType = analyzer.TypeTerraformPlan | ||
version = 1 | ||
) | ||
|
||
var requiredExts = []string{ | ||
".tfplan.json", | ||
".tf.json", | ||
} | ||
|
||
func init() { | ||
analyzer.RegisterPostAnalyzer(analyzerType, newTerraformPlanConfigAnalyzer) | ||
} | ||
|
||
// terraformPlanConfigAnalyzer is an analyzer for detecting misconfigurations in Terraform files. | ||
// It embeds config.Analyzer so it can implement analyzer.PostAnalyzer. | ||
type terraformPlanConfigAnalyzer struct { | ||
*config.Analyzer | ||
} | ||
|
||
func newTerraformPlanConfigAnalyzer(opts analyzer.AnalyzerOptions) (analyzer.PostAnalyzer, error) { | ||
a, err := config.NewAnalyzer(analyzerType, version, misconf.NewTerraformPlanScanner, opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &terraformPlanConfigAnalyzer{Analyzer: a}, nil | ||
} | ||
|
||
// Required overrides config.Analyzer.Required() and checks if the given file is a Terraform file. | ||
func (*terraformPlanConfigAnalyzer) Required(filePath string, _ os.FileInfo) bool { | ||
return slices.Contains(requiredExts, filepath.Ext(filePath)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.