Skip to content

Commit c50e3d8

Browse files
committed
vuln scan on amd64
1 parent 61dac1c commit c50e3d8

File tree

1 file changed

+56
-11
lines changed

1 file changed

+56
-11
lines changed

.github/workflows/build.yml

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,66 @@ jobs:
9393
name: oci-image-tar
9494
path: /tmp/oci-image.tar
9595

96-
# Convert OCI Directory to Docker-compatible tars for amd64 and arm64
97-
- name: Convert OCI to Docker tarballs (amd64 + arm64)
96+
# Convert OCI Directory to Docker-compatible tar for amd64
97+
- name: Convert OCI to Docker tarball
9898
run: |
9999
set -euo pipefail
100-
for arch in amd64 arm64; do
101-
echo "Converting $arch image..."
102-
103-
if ! skopeo copy \
104-
--override-arch=$arch --override-os=linux \
105-
oci-archive:/tmp/oci-image.tar \
106-
docker-archive:/tmp/converted-$arch.tar; then
107-
echo "skopeo copy failed for $arch"
100+
echo "Converting amd64 image..."
101+
102+
if ! skopeo copy \
103+
--override-arch=amd64 --override-os=linux \
104+
oci-archive:/tmp/oci-image.tar \
105+
docker-archive:/tmp/converted-amd64.tar; then
106+
echo "skopeo copy failed for amd64"
107+
exit 1
108+
fi
109+
110+
- name: Trivy scan for vulnerabilities (AMD64)
111+
id: trivy_amd64
112+
uses: aquasecurity/trivy-action@0.33.1
113+
with:
114+
input: /tmp/converted-amd64.tar
115+
format: "json"
116+
severity: "HIGH,CRITICAL"
117+
ignore-unfixed: true
118+
cache-dir: /tmp/trivy-cache
119+
output: /tmp/trivy-report-amd64.json
120+
121+
- name: Upload Trivy scan reports
122+
uses: actions/upload-artifact@v4
123+
with:
124+
name: trivy-scan-reports
125+
path: /tmp/trivy-report-amd64.json
126+
127+
- name: Check Trivy Report for HIGH/CRITICAL vulnerabilities (amd64 only)
128+
env:
129+
GITHUB_EVENT_NAME: ${{ github.event_name }}
130+
run: |
131+
echo "Checking Trivy report for HIGH/CRITICAL vulnerabilities (amd64 only)..."
132+
133+
# Ensure report exists
134+
if [ ! -f /tmp/trivy-report-amd64.json ]; then
135+
echo "Error: /tmp/trivy-report-amd64.json not found!"
136+
exit 1
137+
fi
138+
139+
# Count vulnerabilities from amd64 report
140+
total_vulns=$(jq '[.Results[].Vulnerabilities[]? | select(.Severity=="HIGH" or .Severity=="CRITICAL")] | length' /tmp/trivy-report-amd64.json)
141+
142+
echo "Event: $GITHUB_EVENT_NAME"
143+
echo "Total HIGH/CRITICAL vulnerabilities: $total_vulns"
144+
145+
if [ "$total_vulns" -gt 0 ]; then
146+
# Fail only on push events
147+
if [ "$GITHUB_EVENT_NAME" = "push" ]; then
148+
echo "Push event detected. Failing the job to block image push."
108149
exit 1
150+
else
151+
echo "Pull request event. Vulnerabilities found, but continuing (non-blocking)."
109152
fi
110-
done
153+
else
154+
echo "No HIGH/CRITICAL vulnerabilities found. Safe to proceed."
155+
fi
111156
112157
build:
113158
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)