bridgecrewio / checkov

Prevent cloud misconfigurations and find vulnerabilities during build-time in infrastructure as code, container images and open source packages with Checkov by Bridgecrew.
https://www.checkov.io/
Apache License 2.0
6.85k stars 1.1k forks source link

How to exclude a particular resource from checkov custom policy #6582

Open ashfaqsharif opened 1 month ago

ashfaqsharif commented 1 month ago

Hi,

Currently, I am working on ensuring tagging compliance for all resources in AWS. My objective is to have the "owner" and "cost-centre" tags applied with compliant values to every resource created. Here is the custom policy that I have developed.

`metadata: name: "Check that all resources are tagged with mandatory tag keys" id: "CUSTOM_CFN_1" category: "TAGGING" definition: and:

The policy effectively scans all resources within the CloudFormation template. However, since the template was created using CDK, it contains a resource AWS::CDK::Metadata that does not support tagging. What steps should I take to exclude AWS::CDK::Metadata from the policy mentioned above? Attached is my template.json for reference.

`Resources: MyBucket1553EBB46: Type: AWS::S3::Bucket Properties: Tags:

`

ashfaqsharif commented 1 month ago

I updated the checkov custom policy to handle "Type" and it still failing check on AWS::CDK::Metadata. Here is my updated policy:

`metadata: name: "Check that all resources are tagged with mandatory tag keys" id: "CUSTOM_CFN_1" category: "TAGGING" definition: and:

And Here is the error in the scan:

`Check: CUSTOM_CFN_1: "Check that all resources are tagged with mandatory tag keys" FAILED for resource: AWS::CDK::Metadata.CDKMetadata File: /template.json:46-52

    46 |   CDKMetadata:
    47 |     Type: AWS::CDK::Metadata
    48 |     Properties:
    49 |       Analytics: v2:deflate64:H4sIAAAAAAAA/yXNMQ7CMAyF4bOwJwZCF1Z6g9IdFSdIbsBGdQJDlLvT0Ol9+pfn4Nid4bCbvmrRR/ukO5RrmjCaNd2KnqBcMsaQTP/gTdUoK5RR3oSt/lFr4xBU8oKhuRf2lEi4GhYfYNb9xzno1rdZieySOdErwLDtD4xdT0GKAAAA
    50 |     Metadata:
    51 |       aws:cdk:path: MyStack/CDKMetadata/Default
    52 |     Condition: CDKMetadataAvailable

`