File tree Expand file tree Collapse file tree 1 file changed +41
-2
lines changed
Expand file tree Collapse file tree 1 file changed +41
-2
lines changed Original file line number Diff line number Diff line change 9393 - name : Run unit tests
9494 run : make test
9595
96- - name : Run cfn-guard
97- run : make cfn-guard
96+ - name : Install AWS SAM CLI
97+ if : steps.check_cfn_templates.outputs.exists == 'true'
98+ run : |
99+ pip install aws-sam-cli
100+
101+ - name : Run cfn-guard script
102+ if : steps.check_cfn_templates.outputs.exists == 'true'
103+ run : |
104+ #!/usr/bin/env bash
105+ set -eou pipefail
106+
107+ rm -rf /tmp/ruleset
108+ rm -rf cfn_guard_output
109+
110+ wget -O /tmp/ruleset.zip https://github.com/aws-cloudformation/aws-guard-rules-registry/releases/download/1.0.2/ruleset-build-v1.0.2.zip >/dev/null 2>&1
111+ unzip /tmp/ruleset.zip -d /tmp/ruleset/ >/dev/null 2>&1
112+
113+ curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/aws-cloudformation/cloudformation-guard/main/install-guard.sh | sh >/dev/null 2>&1
114+
115+ mkdir -p cfn_guard_output
116+
117+ declare -a rulesets=("ncsc" "ncsc-cafv3" "wa-Reliability-Pillar" "wa-Security-Pillar")
118+ for ruleset in "${rulesets[@]}"
119+ do
120+ while IFS= read -r -d '' file
121+ do
122+ echo "checking SAM template $file with ruleset $ruleset"
123+ mkdir -p "$(dirname cfn_guard_output/"$file")"
124+
125+ # Transform the SAM template to CloudFormation and then run through cfn-guard
126+ SAM_OUTPUT=$(sam validate -t "$file" --region eu-west-2 --debug 2>&1 | \
127+ grep -Pazo '(?s)AWSTemplateFormatVersion.*\n\/' | tr -d '\0')
128+ echo "${SAM_OUTPUT::-1}" | ~/.guard/bin/cfn-guard validate \
129+ --rules "/tmp/ruleset/output/$ruleset.guard" \
130+ --show-summary fail \
131+ > "cfn_guard_output/${file}_${ruleset}.txt"
132+
133+ done < <(find ./SAMtemplates -name '*.y*ml' -print0)
134+ done
135+
136+ rm -rf /tmp/ruleset
98137
99138 - name : Show cfn-guard output
100139 if : failure()
You can’t perform that action at this time.
0 commit comments