-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix(terraform_plan): Add provisioners to TF Plan parser #5622
Conversation
checkov/terraform/plan_parser.py
Outdated
provisioners = conf.get(TF_PLAN_RESOURCE_PROVISIONERS) if conf else None | ||
if provisioners: | ||
resource_conf[TF_PLAN_RESOURCE_PROVISIONERS] = provisioners |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem with this approach is, that the provisioners
in HCL looks different than in the plan file. So, a custom policy would need to cover both cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gruebel good callout. I've updated it to match as best I could, but note that Terraform transforms the command and removes some of it, so it won't match completely. Now this policy:
metadata:
name: "Test"
id: "CKV2_CUSTOM_1"
guidelines: "Policy description"
category: "GENERAL_SECURITY"
scope:
provider: "aws"
definition:
cond_type: attribute
resource_types:
- aws_instance
attribute: "provisioner/local-exec"
operator: not_exists
Works for both TF and Plan files using all methods documented here: https://developer.hashicorp.com/terraform/language/resources/provisioners/syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍻
@tsmithv11 , do you think there is bug here with item['expressions']['command'] since type is not checked and remote and file provisioners (or future provisioners) does not have the key "command" in the Terraform plan file. We are seeing this error with checkov (where checkov just exits silently and indicates nothing scanned. Traceback (most recent call last): def _get_provisioner(input_data: List[Any]) -> List[Any]: |
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Description
Add provisioners to TF Plan parser to support local-exec policies
Checklist: