Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds support to scan sub folders for terraform iac provider #640

Merged
merged 6 commits into from
May 8, 2021

Conversation

patilpankaj212
Copy link
Contributor

@patilpankaj212 patilpankaj212 commented Apr 5, 2021

  1. adds support for sub folder scanning for terraform iac provider.
  2. the default behaviour for terraform iac provider is changed, to disable recursive sub folder scan use --non-recursive flag
  3. a new attribute plan_root is added in the resource config and violations summary output

@codecov
Copy link

codecov bot commented Apr 5, 2021

Codecov Report

Merging #640 (1d83969) into master (4590a3a) will increase coverage by 0.78%.
The diff coverage is 80.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #640      +/-   ##
==========================================
+ Coverage   73.00%   73.78%   +0.78%     
==========================================
  Files         110      110              
  Lines        3178     3285     +107     
==========================================
+ Hits         2320     2424     +104     
- Misses        674      677       +3     
  Partials      184      184              
Impacted Files Coverage Δ
pkg/iac-providers/helm/v3/load-dir.go 82.89% <ø> (ø)
pkg/iac-providers/kubernetes/v1/load-dir.go 67.74% <ø> (ø)
pkg/iac-providers/kustomize/v3/load-dir.go 71.69% <ø> (ø)
pkg/iac-providers/tfplan/v1/load-dir.go 100.00% <ø> (ø)
pkg/results/types.go 100.00% <ø> (ø)
pkg/termcolor/colorpatterns.go 33.33% <ø> (ø)
pkg/policy/opa/engine.go 65.43% <27.77%> (-0.13%) ⬇️
pkg/http-server/file-scan.go 81.00% <50.00%> (ø)
pkg/k8s/admission-webhook/validating-webhook.go 62.00% <50.00%> (ø)
pkg/writer/human_readable.go 82.75% <57.14%> (-4.04%) ⬇️
... and 12 more

@patilpankaj212 patilpankaj212 linked an issue Apr 7, 2021 that may be closed by this pull request
@patilpankaj212 patilpankaj212 force-pushed the tf-recursive-poc branch 5 times, most recently from 5568a30 to e860bcf Compare April 15, 2021 09:30
@patilpankaj212 patilpankaj212 force-pushed the tf-recursive-poc branch 6 times, most recently from 70eb5a5 to 0fd882f Compare May 1, 2021 12:59
pkg/cli/scan.go Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented May 7, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

No Coverage information No Coverage information
7.3% 7.3% Duplication

@@ -92,6 +92,9 @@ type ScanOptions struct {

// showPassedRules indicates whether to display passed rules or not
showPassedRules bool

// nonRecursive enables recursive scan for the terraform iac provider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update the comment to mention non-recursive scan

}

// NewTerraformDirectoryLoader creates a new terraformDirectoryLoader
func NewTerraformDirectoryLoader(rootDirectory string, nonRecursive bool) TerraformDirectoryLoader {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!

// iac providers that support sub folder scanning
// this needs be updated when other iac providers implement
// sub folder scanning
iacWithSubFolderScan := []string{"all", "k8s", "helm"}
if nonRecursive && iacType == "terraform" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, there is no other option but to implement an IaC specific check

return false
}

iacWithSubFolderScan := []string{"all", "k8s", "helm", "terraform"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this PR, but we should have this information at the time of IaC registration and create a list of iac types which implement recursive scanning in the init() of package iac-providers. And we can fetch it from there, hence eliminating the need to hard code these values here.

@kanchwala-yusuf kanchwala-yusuf merged commit dee8090 into tenable:master May 8, 2021
@patilpankaj212 patilpankaj212 deleted the tf-recursive-poc branch May 5, 2022 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: scan sub-folders too
2 participants