Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit aa7a4b4

Browse files
add extra sections to checkov guide
1 parent b03b939 commit aa7a4b4

File tree

1 file changed

+56
-13
lines changed

1 file changed

+56
-13
lines changed

docs/guides/terraform/checkov.mdx

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,32 @@ description: Use checkov for static analysis of a Nitric project deployed with T
33
tags:
44
- Terraform
55
- Testing
6-
published_at: 2025-01-16
6+
published_at: 2025-04-11
77
---
88

99
# Static analysis of Terraform with Checkov
1010

1111
This guide will walk you through generating a report with [Checkov](https://www.checkov.io/) from a Nitric project.
1212

13-
## How Checkov works
13+
## What is Checkov?
1414

15-
[Checkov](https://www.checkov.io/) is a static code analysis tool for scanning infrastructure as code (IaC) files for misconfigurations that may lead to security or compliance problems.
15+
[Checkov](https://www.checkov.io/) is a static code analysis tool for scanning infrastructure as code (IaC) files for misconfigurations. Checkov provides several key benefits for your projects:
1616

17-
This guide assumes that you have already [installed Checkov](https://www.checkov.io/1.Welcome/Quick%20Start.html#install-checkov-from-pypi) by following their installation guide.
17+
- **Security Scanning**: Automatically detects misconfigurations and security vulnerabilities in your infrastructure code before deployment
18+
- **Compliance**: Helps ensure your infrastructure meets compliance requirements for standards like CIS, HIPAA, and PCI DSS
19+
- **Best Practices**: Enforces infrastructure best practices and coding standards
20+
- **Early Detection**: Catches potential issues during development rather than after deployment
21+
- **Custom Rules**: Allows you to create custom rules specific to your organization's requirements
22+
23+
## Prerequisites
24+
25+
Before you begin, ensure you have:
26+
27+
- [AWS CLI](https://aws.amazon.com/cli/) installed and configured
28+
- [Terraform CLI](https://www.terraform.io/downloads.html) installed
29+
- [Node.js](https://nodejs.org/) and npm installed
30+
- [Nitric CLI](https://docs.nitric.io/cli/installation) installed
31+
- [Checkov](https://www.checkov.io/2.Basics/Installing%20Checkov.html) installed
1832

1933
## What we'll be doing
2034

@@ -62,20 +76,13 @@ provider: nitric/[email protected]
6276
region: us-east-2
6377
```
6478
65-
The Nitric Terraform providers are currently in preview, to enable them you'll need to enable beta-providers in your Nitric project. You can do this by adding the following to your project's nitric.yaml file:
66-
67-
```yaml title:nitric.yaml
68-
preview:
69-
- beta-providers
70-
```
71-
7279
Once you've created your stack file, you can generate the Terraform code by running the following command:
7380
7481
```bash
7582
nitric up
7683
```
7784

78-
This will generate Terraform code which can deploy your application. The output will be in a folder named cdktf.out by default.
85+
This will generate Terraform code which can deploy your application. The output will be in a folder named `cdktf.out` by default.
7986

8087
## Run checkov
8188

@@ -91,10 +98,46 @@ terraform show -json tfplan.binary | jq > tfplan.json
9198
checkov -f tfplan.json
9299
```
93100

101+
This should produce the `checkov` scan results in the terminal, which should look something like this:
102+
103+
```bash
104+
terraform_plan scan results:
105+
106+
Passed checks: 22, Failed checks: 9, Skipped checks: 0
107+
108+
Check: CKV_AWS_41: "Ensure no hard coded AWS access key and secret key exists in provider"
109+
PASSED for resource: aws.default
110+
File: /tfplan.json:0-1
111+
Guide: https://docs.prismacloud.io/en/enterprise-edition/policy-reference/aws-policies/secrets-policies/bc-aws-secrets-5
112+
Check: CKV_AWS_364: "Ensure that AWS Lambda function permissions delegated to AWS services are limited by SourceArn or SourceAccount"
113+
PASSED for resource: module.api_main.aws_lambda_permission.apigw_lambda["checkov_services-api"]
114+
File: /tfplan.json:0-0
115+
Guide: https://docs.prismacloud.io/en/enterprise-edition/policy-reference/aws-policies/aws-iam-policies/bc-aws-364
116+
Check: CKV_AWS_301: "Ensure that AWS Lambda function is not publicly accessible"
117+
PASSED for resource: module.api_main.aws_lambda_permission.apigw_lambda["checkov_services-api"]
118+
File: /tfplan.json:0-0
119+
Guide: https://docs.prismacloud.io/en/enterprise-edition/policy-reference/aws-policies/aws-general-policies/bc-aws-301
120+
Check: CKV_AWS_136: "Ensure that ECR repositories are encrypted using KMS"
121+
FAILED for resource: module.service_checkov_services-api.aws_ecr_repository.repo
122+
File: /tfplan.json:0-0
123+
Guide: https://docs.prismacloud.io/en/enterprise-edition/policy-reference/aws-policies/aws-general-policies/ensure-that-ecr-repositories-are-encrypted
124+
```
125+
94126
## Analysing the results
95127

96128
Checkov comes with some great default checks, however, they do need to be aligned with the requirements of your application.
97129

98-
For example the Checkov policy ‘CKV_AWS_136‘ checks specifically for SSE-KMS using a customer-managed KMS key (or at least AWS-managed KMS key). This finding might not always be relevant because, by default, Amazon ECR encrypts container images at rest using Amazon S3 server-side encryption (SSE-S3). That means your images are always encrypted, even if you don’t explicitly configure a KMS key.
130+
For example the Checkov policy `CKV_AWS_136` checks specifically for SSE-KMS using a customer-managed KMS key (or at least AWS-managed KMS key). This finding might not always be relevant because, by default, Amazon ECR encrypts container images at rest using Amazon S3 server-side encryption (SSE-S3). That means your images are always encrypted, even if you don't explicitly configure a KMS key.
131+
132+
A way to handle these false positives is to use [suppress/skip comments](https://www.checkov.io/2.Basics/Suppressing%20and%20Skipping%20Policies.html) in the Terraform code.
133+
134+
```terraform
135+
# checkov:skip=CKV_AWS_136
136+
resource "aws_ecr_repository" "repo" {
137+
name = "my-ecr-repo"
138+
}
139+
```
140+
141+
You could also use custom policies to handle these false positives or create custom rules to better match your infrastructure requirements.
99142

100143
If you have any concerns, please don't hesitate to [reach out](https://nitric.io/chat).

0 commit comments

Comments
 (0)