-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (100 loc) · 3.67 KB
/
Copy pathcontainer-scan.yml
File metadata and controls
109 lines (100 loc) · 3.67 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
name: Container Scan
# Trivy container image scanning for OS and application dependency CVEs.
# Runs on every build for audit evidence (artifact). Remediation is handled
# separately by the container-remediation.yml scheduled workflow.
on:
workflow_call:
inputs:
image-ref:
description: Container image to scan (e.g. 613957054632.dkr.ecr.us-east-1.amazonaws.com/kernel/api:sha-abc1234)
type: string
required: true
severity:
description: Comma-separated severities to flag (CRITICAL,HIGH,MEDIUM,LOW)
type: string
required: false
default: 'CRITICAL,HIGH'
exit-code:
description: Exit code when vulnerabilities are found (1 to fail the build, 0 to observe only)
type: string
required: false
default: '0'
ignore-unfixed:
description: Skip CVEs with no available patch
type: boolean
required: false
default: true
aws-region:
description: AWS region for ECR login
type: string
required: false
default: 'us-east-1'
ecr-role-to-assume:
description: IAM role ARN to assume for ECR pull access
type: string
required: false
default: ''
jobs:
scan:
runs-on: ubuntu-24.04
permissions:
contents: read
id-token: write
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
if: inputs.ecr-role-to-assume != ''
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ inputs.ecr-role-to-assume }}
aws-region: ${{ inputs.aws-region }}
- name: Log in to ECR
if: inputs.ecr-role-to-assume != ''
uses: aws-actions/amazon-ecr-login@v2
- name: Scan container image (table)
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ inputs.image-ref }}
severity: ${{ inputs.severity }}
exit-code: '0'
ignore-unfixed: ${{ inputs.ignore-unfixed }}
format: 'table'
- name: Scan container image (json)
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ inputs.image-ref }}
severity: ${{ inputs.severity }}
exit-code: ${{ inputs.exit-code }}
ignore-unfixed: ${{ inputs.ignore-unfixed }}
format: 'json'
output: 'trivy-results.json'
- name: Write scan summary
if: always()
shell: bash
run: |
if [ ! -f trivy-results.json ]; then
echo "No scan results produced." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
CRITICAL=$(jq '[.Results[]?.Vulnerabilities[]? | select(.Severity == "CRITICAL")] | length' trivy-results.json)
HIGH=$(jq '[.Results[]?.Vulnerabilities[]? | select(.Severity == "HIGH")] | length' trivy-results.json)
MEDIUM=$(jq '[.Results[]?.Vulnerabilities[]? | select(.Severity == "MEDIUM")] | length' trivy-results.json)
LOW=$(jq '[.Results[]?.Vulnerabilities[]? | select(.Severity == "LOW")] | length' trivy-results.json)
{
echo "### Container Scan Results"
echo "**Image:** \`${{ inputs.image-ref }}\`"
echo ""
echo "| Severity | Count |"
echo "|----------|-------|"
echo "| Critical | $CRITICAL |"
echo "| High | $HIGH |"
echo "| Medium | $MEDIUM |"
echo "| Low | $LOW |"
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload scan artifact
uses: actions/upload-artifact@v4
with:
name: container-scan-report
path: trivy-results.json
if: always()