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

feat(terraform): Terraform Plan snapshot scanning support #6176

Merged
merged 16 commits into from
Mar 4, 2024

Conversation

nikpivkin
Copy link
Contributor

@nikpivkin nikpivkin commented Feb 21, 2024

Description

Added a new Terraform Plan file scanner

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@nikpivkin nikpivkin marked this pull request as ready for review February 26, 2024 07:34
Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

Left some comments.

FYI: i didn't check iac directory

docs/docs/coverage/iac/terraform.md Outdated Show resolved Hide resolved
docs/tutorials/misconfiguration/terraform.md Outdated Show resolved Hide resolved
docs/tutorials/misconfiguration/terraform.md Outdated Show resolved Hide resolved
magefiles/terraformplan.go Outdated Show resolved Hide resolved
magefiles/magefile.go Show resolved Hide resolved
integration/aws_cloud_test.go Show resolved Hide resolved
magefiles/terraformplan.go Outdated Show resolved Hide resolved
magefiles/terraformplan.go Show resolved Hide resolved
expectedFiles []string
}{
{
name: "just resource",
Copy link
Member

Choose a reason for hiding this comment

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

how about reusing dir and name vars to reduce test code, since they are called the same anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@simar7 simar7 self-requested a review February 29, 2024 03:14
Copy link
Member

@simar7 simar7 left a comment

Choose a reason for hiding this comment

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

Just a couple of small fixes but lgtm otherwise!

},
{
dir: "with-remote-module",
expectedDir: path.Join("terraform-aws-modules", "s3-bucket", "aws", "main.tf"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking the path of a remote module is not reliable, as the result may depend on the order in which the tests are executed. If the module is not in the cache, the path is a reference to the git, otherwise the path to the module is in the cache.

Copy link
Member

Choose a reason for hiding this comment

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

I wasn't able to make this test fail, is it flaky? Is there any way to test without the effects of the cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. clear the cache rm -rf $TMPDIR/.aqua.
  2. comment out the first two test cases so that the test with the remote module is the first.
  3. run test:
Error:      Not equal: 
            expected: "terraform-aws-modules/s3-bucket/aws/main.tf"
            actual  : "git::https:/github.com/terraform-aws-modules/terraform-aws-s3-bucket?ref=3a1c80b29fdf8fc682d2749456ec36ecbaf4ce14/main.tf"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since only the remote module is used in this test case, we only need to verify that the check detected misconfig. I'll update the test

Copy link
Contributor Author

@nikpivkin nikpivkin Mar 4, 2024

Choose a reason for hiding this comment

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

I created an issue in defsec asking to add the ability to skip cache to avoid fluky tests, but the issues are now closed. Can we move this issue to Trivy?

Copy link
Member

Choose a reason for hiding this comment

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

I created an issue in defsec asking to add the ability to skip cache to avoid fluky tests, but the issues are now closed. Can we move this issue to Trivy?

Yes please, if it's a small change you can just make a PR without the need to track with an issue.

@simar7 simar7 added this pull request to the merge queue Mar 4, 2024
Merged via the queue into aquasecurity:main with commit 9361cdb Mar 4, 2024
17 checks passed
@nikpivkin nikpivkin deleted the tf-plan-snapshot branch March 6, 2024 08:32
thall added a commit to einride/sage that referenced this pull request Apr 9, 2024
Trivy has added support for scanning terraform plan snapshots and
thus so updated the config names.

See (PR)[aquasecurity/trivy#6176)
thall added a commit to einride/sage that referenced this pull request Apr 9, 2024
Trivy has added support for scanning terraform plan snapshots and
thus so updated the config names.

See [PR](aquasecurity/trivy#6176)
thall added a commit to einride/sage that referenced this pull request Apr 9, 2024
Trivy has added support for scanning terraform plan snapshots and
thus so updated the config names.

See [PR](aquasecurity/trivy#6176)
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.

feat(misconf): Improve support for scanning Terraform plan JSON input
3 participants