Skip to content

Commit f04c50b

Browse files
committed
feat: improved the Trivy vulnerability scanning by pre-pulling the target image and running the scan in a Docker container for better stability
1 parent aacf7ed commit f04c50b

1 file changed

Lines changed: 40 additions & 18 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Login to Docker Hub
2020
uses: docker/login-action@v3
2121
with:
22-
username: ${{ secrets.DOCKERHUB_USERNAME }}
22+
username: 'vxcontrol'
2323
password: ${{ secrets.DOCKERHUB_TOKEN }}
2424

2525
- name: Extract metadata
@@ -116,23 +116,37 @@ jobs:
116116
runs-on: self-hosted
117117

118118
steps:
119-
- name: Run Trivy vulnerability scanner
120-
uses: aquasecurity/trivy-action@master
121-
with:
122-
image-ref: 'vxcontrol/kali-linux:latest'
123-
format: 'sarif'
124-
output: 'trivy-results.sarif'
125-
# Optimize scanning for large images
126-
scanners: 'vuln'
127-
timeout: '60m'
128-
# Skip problematic files
129-
skip-files: '**/*.dll,**/*.exe,**/libstdc++-6.dll'
130-
# Additional optimizations
131-
severity: 'CRITICAL,HIGH'
132-
skip-dirs: '/usr/lib/gcc,/usr/share/doc'
133-
env:
134-
# Stability improvements via environment variables
135-
TRIVY_PARALLEL: '4'
119+
- name: Pull target image locally to avoid streaming issues
120+
run: |
121+
echo "Pre-pulling target image for stable scanning..."
122+
docker pull vxcontrol/kali-linux:latest
123+
echo "✅ Target image available locally"
124+
125+
- name: Run Trivy vulnerability scanner via Docker (stable approach)
126+
run: |
127+
echo "Running Trivy scan using Docker with docker.sock access..."
128+
129+
# Simplified approach without host cache mapping (ephemeral scan)
130+
docker run --rm \
131+
-v /var/run/docker.sock:/var/run/docker.sock \
132+
-v "$(pwd):$(pwd)" \
133+
-w "$(pwd)" \
134+
--memory=4g \
135+
--memory-swap=8g \
136+
-e TRIVY_PARALLEL=4 \
137+
aquasec/trivy:0.63.0 \
138+
image \
139+
--format sarif \
140+
--output trivy-results.sarif \
141+
--scanners vuln \
142+
--timeout 60m \
143+
--severity CRITICAL,HIGH \
144+
--skip-files '**/*.dll,**/*.exe,**/libstdc++-6.dll' \
145+
--skip-dirs '/usr/lib/gcc,/usr/share/doc' \
146+
--quiet \
147+
vxcontrol/kali-linux:latest
148+
149+
echo "✅ Trivy scan completed"
136150
continue-on-error: true
137151

138152
- name: Verify SARIF file exists
@@ -186,3 +200,11 @@ jobs:
186200
echo "- 🔍 **Check logs** above for timeout or scanning errors" >> $GITHUB_STEP_SUMMARY
187201
echo "- 💡 **Tip:** Large images may require scanning optimization" >> $GITHUB_STEP_SUMMARY
188202
fi
203+
204+
- name: Cleanup local resources
205+
if: always()
206+
run: |
207+
echo "Cleaning up local resources..."
208+
docker rmi vxcontrol/kali-linux:latest 2>/dev/null || echo "Target image not found"
209+
docker rmi aquasec/trivy:0.63.0 2>/dev/null || echo "Trivy image not found"
210+
echo "✅ Cleanup completed"

0 commit comments

Comments
 (0)