TL;DR
Overview
So, static code analysis for infrastructure code is hot! A few tools have appeared recently, and
Checkov looks pretty good.
I tested it locally (as a command line tool on my laptop) against
my aws-student-lab project. This terraform code just sets up a simple student lab on AWS, and I like to use it for testing new tools, since it's both simple and realistic. Checkov found no problems, and showed a nice green "PASSED":
The next step after local analysis, of course, is continuous integration, so I used Github Actions to run Checkov each time there's a commit. This involved writing a small yaml snippet.
To avoid having to do this setup on each repository, I decided to make
a new Github Action and publish it on the Github Marketplace. This way, other people can easily integrate Checkov in their CI with minimal configuration!
Deep-dive test-drive
To test out Checkov and my new Github Action, I
added the definition for an S3 bucket in my terraform code and gradually removed security features, to see if Checkov complains.
Starting with a nice secure bucket:
This bucket is pretty ok: it has encryption, versioning, logging and MFA confirmation for deletions.
As expected, Checkov checks everything and is happy, so
the build passes:
Then,
I decided to remove most of the nice features and options. Checkov breaks the build and
complains:
The output is very helpful in determining how to fix this:
- Ensure all data stored in the S3 bucket is securely encrypted at rest
- Ensure the S3 bucket has access logging enabled
- Ensure all data stored in the S3 bucket have versioning enabled
- Ensure S3 bucket has MFA delete enabled
Nice! Working backwards, someone who sees these errors can look up cloud provider (AWS in this case) and terraform documentation and enable the missing features, reaching a more secure configuration.
Overall I'm happy and will be using this on all my future cloud code.
Pull requests are welcome!