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

test: replace Go checks with Rego #7867

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

nikpivkin
Copy link
Contributor

@nikpivkin nikpivkin commented Nov 4, 2024

Description

Part of #7718

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 changed the title refactor(test): replace Go checks with Rego test: replace Go checks with Rego Nov 5, 2024
Comment on lines -257 to -282
name: "IgnoreForImpliedIAMResource",
inputOptions: `
terraform {
required_version = "~> 1.1.6"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.48"
}
}
}

# Retrieve an IAM group defined outside of this Terraform config.

# tfsec:ignore:aws-iam-enforce-mfa
data "aws_iam_group" "externally_defined_group" {
group_name = "group-name" # tfsec:ignore:aws-iam-enforce-mfa
}

# Create an IAM policy and attach it to the group.

# tfsec:ignore:aws-iam-enforce-mfa
resource "aws_iam_policy" "test_policy" {
name = "test-policy" # tfsec:ignore:aws-iam-enforce-mfa
policy = data.aws_iam_policy_document.test_policy.json # tfsec:ignore:aws-iam-enforce-mfa
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The AVD-AWS-0123 (aws-iam-enforce-mfa) check will never be triggered for this input even without ignore rules.

Copy link
Member

Choose a reason for hiding this comment

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

Why is that? If so is the case, was the assertion incorrect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aws-iam-enforce-mfa checks that the condition key is aws:MultiFactorAuthPresent. but the test data does not contain this. I also ran trivy on the test case, but it didn't produce any results:

trivy conf main.tf
2024-11-11T15:36:25+06:00       INFO    [misconfig] Misconfiguration scanning is enabled
2024-11-11T15:36:26+06:00       INFO    [terraform scanner] Scanning root module        file_path="."
2024-11-11T15:36:26+06:00       INFO    Detected config files   num=1

Comment on lines -579 to -581
name: "TrivyIgnoreForImpliedIAMResource",
inputOptions: `
terraform {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

@nikpivkin nikpivkin marked this pull request as ready for review November 6, 2024 08:57
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.

2 participants