-
Notifications
You must be signed in to change notification settings - Fork 26
171 lines (144 loc) · 5.18 KB
/
iac_scan.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Copyright 2023 Amazon.com, Inc. or its affiliates.
# SPDX-License-Identifier: Apache-2.0
# Licensed under the Apache License, Version 2.0 https://aws.amazon.com/apache-2-0/
name: Infra-as-Code Code Scanning
on: [push, pull_request]
permissions:
contents: read
jobs:
################
# Trivy Checks #
################
trivy:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
runs-on: ubuntu-latest
env:
TRIVY_REPORT_FILE: trivy_report.sarif
steps:
- name: Checkout the branch
uses: actions/checkout@v3
- name: Run trivy in fs mode and generate report
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
ignore-unfixed: true
trivy-config: ".github/conf/trivy.yaml"
trivyignores: ".github/conf/.trivyignore"
# severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
# output: ${{ env.TRIVY_REPORT_FILE }} # This flag doesnt seem to be working.
env:
TRIVY_OUTPUT: ${{ env.TRIVY_REPORT_FILE }}
# As per the following issue/solution: https://github.com/aquasecurity/trivy/issues/5003
- name: Fix trivy SARIF report for URI scheme
run: |-
sed -i 's#git::https:/##g' ${{ env.TRIVY_REPORT_FILE }}
- name: Upload trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: success() || failure()
with:
sarif_file: "${{ env.TRIVY_REPORT_FILE }}"
- name: Save report results as an artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.TRIVY_REPORT_FILE }}
path: ${{ env.TRIVY_REPORT_FILE }}
##################
# Checkov Checks #
##################
checkov:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
runs-on: ubuntu-latest
env:
CHECKOV_REPORT_FILE: checkov_report.sarif
steps:
- name: Checkout the branch
uses: actions/checkout@v3
- name: Run checkov and generate report
uses: bridgecrewio/checkov-action@v12
with:
config_file: ".github/conf/checkov.yaml"
output_format: cli,sarif
output_file_path: console,${{ env.CHECKOV_REPORT_FILE }}
- name: Upload checkov scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: success() || failure()
with:
sarif_file: "${{ env.CHECKOV_REPORT_FILE }}"
- name: Save report results as an artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.CHECKOV_REPORT_FILE }}
path: ${{ env.CHECKOV_REPORT_FILE }}
#################
# TFLint Checks #
#################
tflint:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
runs-on: ubuntu-latest
env:
TFLINT_REPORT_FILE: tflint_report.sarif
steps:
- name: Checkout the branch
uses: actions/checkout@v3
- name: Setup tflint
uses: terraform-linters/setup-tflint@v3
with:
tflint_wrapper: true
- name: Install tflint plugins
run: |-
tflint --init -c .github/conf/tflint.hcl
- name: Run tflint
id: tflint_run
run: |-
tflint --recursive --format sarif -c $(pwd)/.github/conf/tflint.hcl
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Generate report
run: |-
echo '${{ steps.tflint_run.outputs.stdout }}' > "${{ env.TFLINT_REPORT_FILE }}"
- name: Upload tflint scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: success() || failure()
with:
sarif_file: "${{ env.TFLINT_REPORT_FILE }}"
- name: Save report results as an artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.TFLINT_REPORT_FILE }}
path: ${{ env.TFLINT_REPORT_FILE }}
#############
# TF Checks #
#############
tfchecks:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
runs-on: ubuntu-latest
steps:
- name: Checkout the branch
uses: actions/checkout@v3
- name: Check Terraform fmt for grid
uses: dflook/terraform-fmt-check@v1
with:
path: deployment/grid/terraform
- name: Validate Terraform code for grid
uses: dflook/terraform-validate@v1
if: success() || failure()
with:
path: deployment/grid/terraform
- name: Check Terraform fmt for image_repository
uses: dflook/terraform-fmt-check@v1
if: success() || failure()
with:
path: deployment/image_repository/terraform
- name: Validate Terraform code for image_repository
uses: dflook/terraform-validate@v1
if: success() || failure()
with:
path: deployment/image_repository/terraform