-
Notifications
You must be signed in to change notification settings - Fork 4
369 lines (355 loc) · 12.8 KB
/
scan.yml
File metadata and controls
369 lines (355 loc) · 12.8 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
---
name: Security scan
# Periodically scan production images for security vulnerabilities
on:
schedule:
# Once a day at midnight
- cron: '0 0 * * *'
# Once an hour
# - cron: '0 * * * *'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# Name of image
IMAGE_NAME: foo-app
# Name of org in GHCR Docker repository (must be lowercase)
IMAGE_OWNER: ${{ github.repository_owner }}
# IMAGE_OWNER: foo
# ECR Docker repo org name (may be blank, otherwise must have trailing slash)
ECR_IMAGE_OWNER: cogini/
# Tag for release images
# IMAGE_TAG: ${{ (github.ref == 'refs/heads/main' && 'staging') || (github.ref == 'refs/heads/qa' && 'qa') }}
IMAGE_TAG: latest
IMAGE_VER: ${{ github.sha }}
# Registry for test images
REGISTRY: ghcr.io/
# Registry for public images, default is docker.io
PUBLIC_REGISTRY: ''
# Give GitHub Actions access to AWS
AWS_ENABLED: 1
# AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
# AWS_ROLE_TO_ASSUME: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/cogini-foo-dev-app-github-action
# AWS_REGION: us-east-1
# S3_BUCKET_ASSETS: cogini-foo-app-dev-app-assets
# CLOUDFRONT_CDN_DISTRIBUTION_ID: XXXX
# S3_BUCKET_CI: cogini-prod-foo-ci
# Health check port for app
APP_PORT: 4000
# Datadog
# DD_API_KEY: ${{ secrets.ACTIONS_DD_API_KEY }}
# DD_ENV: ci
# DD_TAGS: "environment:ci"
# MIX_ENV: foo
ELIXIR_MODULE: PhoenixContainerExample
ECS_CLUSTER: foo
ECS_SERVICE: foo-app
ECS_CONTAINER: foo-app
ECS_CPU: 256
ECS_RAM: 2048
CODEDEPLOY_APPLICATION: foo-app
CODEDEPLOY_DEPLOYMENT_GROUP: foo-app-ecs
# CODEDEPLOY_BUCKET: foo-prod-bounce-public-deploy
TASKDEF: ecs/task-definition.json
ECS_SERVICE_WORKER: foo-worker
ECS_CONTAINER_WORKER: foo-worker
ECS_CPU_WORKER: 256
ECS_RAM_WORKER: 2048
TASKDEF_WORKER: ecs/task-definition.worker.json
APPSPEC: ecs/appspec.yml
# AWS SSM Parameter Store name prefix
# AWS_PS_PREFIX: cogini/foo/dev
# APPSIGNAL_APP_NAME: bounce
# Name of environment for resources created by Terraform
# TERRAFORM_ENV: dev
# TASK_ROLE_ARN: "arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/foo-app"
# EXECUTION_ROLE_ARN: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/foo-ecs-task-execution-role
# GitHub Advanced Security, free for open source, otherwise a paid feature
# https://docs.github.com/en/get-started/learning-about-github/about-github-advanced-security
# https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning
# https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github
GITHUB_ADVANCED_SECURITY: 0
DEPLOY_DOCKER_HUB: 0
# Docker
DOCKER_BUILDKIT: '1'
COMPOSE_DOCKER_CLI_BUILD: '1'
COMPOSE_FILE: docker-compose.gha.yml
DOCKER_FILE: deploy/debian.Dockerfile
jobs:
setup-matrix:
name: Set up build matrix
runs-on: ubuntu-latest
outputs:
# Elixir/Erlang/OS combinations for tests
# Generally this will match prod
test-matrix: ${{ steps.common-matrix.outputs.result }}
# Combinations for prod images
# Used for the final deploy image as well as external tests
prod-matrix: ${{ steps.prod-matrix.outputs.result }}
# Combinations to deploy to prod (or staging)
# Generally this will only be a single variant
deploy-matrix: ${{ steps.deploy-matrix.outputs.result }}
# Combinations used to build assets
# Generally this will only be a single variant
assets-matrix: ${{ steps.assets-matrix.outputs.result }}
steps:
- uses: actions/github-script@v7
id: common-matrix
# Specify versions of Erlang, Elixir, and base OS
# in a combination supported by https://hub.docker.com/r/hexpm/elixir/tags
# {
# os: "alma",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "10",
# prod_os_ver: "10"
# },
# {
# os: "alpine",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "3.21.3",
# prod_os_ver: "3.21.3"
# },
# {
# os: "distroless",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "bookworm-20250630-slim",
# prod_os_ver: "bookworm-slim"
# },
# {
# os: "rocky",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "9",
# prod_os_ver: "9"
# },
# {
# os: "ubuntu",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "jammy-20250619",
# prod_os_ver: "jammy"
# },
# {
# os: "chiseled",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "jammy-20250619",
# prod_os_ver: "jammy"
# },
# {
# os: "ubuntu",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "noble-20250619",
# prod_os_ver: "noble"
# },
with:
script: |
return {
include: [
{
os: "centos7",
elixir: "1.18.4",
otp: "28.0.1",
build_os_ver: "7",
prod_os_ver: "7"
},
{
os: "debian",
elixir: "1.18.4",
otp: "28.0.1",
build_os_ver: "bookworm-20250630-slim",
prod_os_ver: "bookworm-slim"
},
]
}
# druzan/setup-matrix is slow, taking about 15 seconds to initialize
# - name: Define matrix for test containers
# id: test-matrix
# uses: druzsan/setup-matrix@v2
# with:
# matrix: |
# include:
# - elixir: 1.16.3
# otp: 26.2.5
# build_os_ver: bullseye-20240513
# prod_os_ver: bullseye-slim
# os: debian
# {
# os: "alma",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "10",
# prod_os_ver: "10"
# },
# {
# os: "alpine",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "3.21.3",
# prod_os_ver: "3.21.3"
# },
# {
# os: "rocky",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "9",
# prod_os_ver: "9"
# },
# {
# os: "ubuntu",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "jammy-20250619",
# prod_os_ver: "jammy"
# },
# {
# os: "chiseled",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "jammy-20250619",
# prod_os_ver: "jammy"
# },
# {
# os: "ubuntu",
# elixir: "1.18.4",
# otp: "28.0.1",
# build_os_ver: "noble-20250619",
# prod_os_ver: "noble"
# },
- uses: actions/github-script@v7
id: prod-matrix
with:
script: |
return {
include: [
{
os: "debian",
elixir: "1.18.4",
otp: "28.0.1",
build_os_ver: "bookworm-20250630-slim",
prod_os_ver: "bookworm-slim"
},
]
}
- uses: actions/github-script@v7
id: deploy-matrix
with:
script: |
return {
include: [
{
os: "debian",
elixir: "1.18.4",
otp: "28.0.1",
build_os_ver: "bookworm-20250630-slim",
prod_os_ver: "bookworm-slim",
},
]
}
- uses: actions/github-script@v7
id: assets-matrix
# Specify versions of Erlang, Elixir, and base OS
# in a combination supported by https://hub.docker.com/r/hexpm/elixir/tags
with:
script: |
return {
include: [
{
os: "debian",
elixir: "1.18.4",
otp: "28.0.1",
build_os_ver: "bookworm-20250630-slim",
prod_os_ver: "bookworm-slim",
},
]
}
scan:
name: Security scan prod image
needs: [setup-matrix]
permissions:
id-token: write
contents: read
packages: read
checks: write
pull-requests: write
issues: read
# Upload SARIF report files
security-events: write
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup-matrix.outputs.prod-matrix) }}
env:
DOCKER_FILE: deploy/${{ matrix.os }}.Dockerfile
VAR: ${{ matrix.elixir }}-erlang-${{ matrix.otp }}-${{ matrix.os }}-${{ matrix.build_os_ver }}
steps:
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull image
run: docker pull "ghcr.io/${IMAGE_OWNER}/${IMAGE_NAME}:${VAR}${IMAGE_VER}"
- name: Scan image with Trivy
uses: aquasecurity/trivy-action@0.28.0
# https://github.com/aquasecurity/trivy-action
# https://github.com/marketplace/actions/aqua-security-trivy#inputs
with:
image-ref: ghcr.io/${{env.IMAGE_OWNER}}/${{env.IMAGE_NAME}}:${{ env.VAR }}${{ env.IMAGE_VER }}
# exit-code: '1' # fail build
# ignore-unfixed: true
# vuln-type: 'os,library'
# severity: 'CRITICAL,HIGH'
# cache-dir: /var/cache
# format: 'sarif'
format: 'table'
# format: ${{ env.GITHUB_ADVANCED_SECURITY == 1 && 'sarif' || 'table' }}
output: 'trivy.sarif'
- name: Display scan results
if: ${{ always() && env.GITHUB_ADVANCED_SECURITY == 1 }}
run: cat trivy-results.sarif | jq .
- name: Upload Trivy scan results to GitHub Security tab
if: ${{ always() && env.GITHUB_ADVANCED_SECURITY == 1 }}
uses: github/codeql-action/upload-sarif@v3
# Requires GitHub Advanced Security
# https://docs.github.com/en/get-started/learning-about-github/about-github-advanced-security
# https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning
# https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github
with:
sarif_file: 'trivy-results.sarif'
category: trivy
- name: Scan image with Grype
uses: anchore/scan-action@v6
# https://github.com/marketplace/actions/anchore-container-scan
id: scan-grype
with:
image: ghcr.io/${{env.IMAGE_OWNER}}/${{env.IMAGE_NAME}}:${{ env.VAR }}${{ env.IMAGE_VER }}
# severity-cutoff: critical
fail-build: false
# output-format: 'sarif'
output-format: table
# output-format: ${{ env.GITHUB_ADVANCED_SECURITY == 1 && 'sarif' || 'table' }}
- name: Display scan results
if: ${{ always() && env.GITHUB_ADVANCED_SECURITY == 1 }}
run: cat ${{ steps.scan-grype.outputs.sarif }} | jq .
- name: Upload Grype scan results to GitHub Security tab
if: ${{ always() && env.GITHUB_ADVANCED_SECURITY == 1 }}
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.scan-grype.outputs.sarif }}
category: grype
# - name: Scan image with Snyk
# # if: github.event_name != 'pull_request'
# uses: snyk/actions/docker@master
# continue-on-error: true
# env:
# SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
# with:
# command: test
# image: ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:${{ env.VAR }}${{ env.IMAGE_VER }}
# args: --file=${{ env.DOCKER_FILE }} --project-name=api