AWS CloudFormation cfn-guard is now GA - an intro with policy-as-code

Hi All,

Cloudformation is way to define your infrastructure as code (IaC) and last month AWS released cfn-guard which is a command line tool to check your cloudformation templates against certain rules.

It’s a pretty cool little utility, you can generate rules from previous templates and there are examples to get you started.

I walk through one of my previous CDK projects (AppSync WAF) and generate rules based on the template generated from the synth. I then update the rules and the project to modify the firewall rules and the type of authentication used with AppSync. This tests cfn-guard by checking template against my policy and find that the firewall and appsync are not compliant.

Some other stand outs:

  • Compatible with CI/CD
  • Error 0, 2 codes with overrides
  • Firewall like syntax

I’ve written an article here if you want to check out the full write up:

https://www.talkncloud.com/cloudformation-cfn-guard-policy-as-code/

You can access my repo here for this project here:

https://github.com/talkncloud/aws/tree/main/appsync-waf-guard

You can access cloudformation guard on github here:

https://github.com/aws-cloudformation/cloudformation-guard

Keen to hear what others think of this and if you’ve already started using cfn-guard.

Cheers,

Mick.


Related discussions:

Been using it in beta for CICD IaC pipeline for customer in govcloud for a couple months. Really useful needs a little ironing out but extremely powerful.

Well done guys!

Awesome, but why is this written in Rust when every other AWS CLI tool is Python?

Thought it was a strange choice as well, I suspect it’s for efficiency?

great post. thanks for the deep dive

Strange - how efficient does it need to be? It’s not a web server processing millions of requests per second. At best it’ll have to do a few hundred policy evaluations in an environment (like CI/CD) where the difference between 10 and 100ms is unnoticeable. Not directing this at you, by the way, just thinking out loud.