Supply Chain

Assess AWS CloudFormation Template Security with cnspec

Scan AWS CloudFormation templates for security misconfigurations using cnspec.

Use cnspec to scan AWS CloudFormation templates for security misconfigurations and policy violations before deploying them. cnspec parses both YAML and JSON CloudFormation templates and exposes resources, parameters, outputs, and other template sections as queryable MQL resources.

Scan a CloudFormation template

Scan a single template file:

cnspec scan cloudformation template.yaml

cnspec automatically detects whether the template is YAML or JSON.

Scan options

OptionDescription
--discoverEnable discovery of nested assets (all, auto)
--asset-nameOverride the asset name
--annotationAdd an annotation to the asset (key=value)
--incognitoRun in incognito mode (do not report results to Mondoo Platform)
-o, --outputSet the output format (compact, full, json, junit, summary, yaml)
-f, --policy-bundlePath to a policy file (local path, s3:// URI, or http(s):// URL)
--policySpecify policies to execute (requires --policy-bundle)
--risk-thresholdExit with status 1 if any risk meets or exceeds this value (0-100)
-j, --jsonReturn the results as JSON

Example checks

Run cnspec shell cloudformation template.yaml to open the interactive shell. From there you can make checks like the examples below.

List all resources in a template

cloudformation.template.resources { name type }

Ensure EC2 instances don't use a hardcoded AMI

cloudformation.template.resources.where(type == "AWS::EC2::Instance").all(
  properties["ImageId"] != /^ami-/
)

Check that no security groups allow unrestricted SSH

cloudformation.template.resources.where(type == "AWS::EC2::SecurityGroup") {
  name
  properties["SecurityGroupIngress"]
}

List all template outputs

cloudformation.template.outputs { name properties }

Inspect template parameters

cloudformation.template.parameters

Learn more

On this page