Skip to content

Commit 0aabf29

Browse files
committed
fix: Ajout des permissions nécessaires au workflow Trivy
Corrections apportées au workflow de scan de vulnérabilités : - Ajout des permissions au niveau du workflow (security-events: write) - Ajout des permissions au niveau du job trivy-scan - Ajout de continue-on-error pour l'upload SARIF (évite l'échec du workflow) - Amélioration de la robustesse du job de résumé - Meilleure gestion des cas où les artifacts ne sont pas disponibles Ces changements permettent au workflow de fonctionner correctement même si l'upload SARIF échoue (par exemple si GitHub Advanced Security n'est pas activé). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0c05e57 commit 0aabf29

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

.github/workflows/trivy-scan.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ on:
1818
# Permet de lancer manuellement le scan
1919
workflow_dispatch:
2020

21+
permissions:
22+
contents: read
23+
security-events: write
24+
actions: read
25+
2126
jobs:
2227
trivy-scan:
2328
name: Scan Docker Images
2429
runs-on: ubuntu-latest
30+
permissions:
31+
contents: read
32+
security-events: write
2533

2634
strategy:
2735
matrix:
@@ -49,6 +57,7 @@ jobs:
4957
- name: Upload Trivy results to GitHub Security tab
5058
uses: github/codeql-action/upload-sarif@v3
5159
if: always()
60+
continue-on-error: true
5261
with:
5362
sarif_file: 'trivy-results-${{ matrix.image.name }}.sarif'
5463
category: trivy-${{ matrix.image.name }}
@@ -90,10 +99,13 @@ jobs:
9099
runs-on: ubuntu-latest
91100
needs: trivy-scan
92101
if: always()
102+
permissions:
103+
contents: read
93104

94105
steps:
95106
- name: Download all artifacts
96107
uses: actions/download-artifact@v4
108+
continue-on-error: true
97109

98110
- name: Generate summary
99111
run: |
@@ -102,15 +114,18 @@ jobs:
102114
echo "Scan completed at: $(date -u)" >> $GITHUB_STEP_SUMMARY
103115
echo "" >> $GITHUB_STEP_SUMMARY
104116
105-
for report in trivy-report-*/trivy-report-*.txt; do
106-
if [ -f "$report" ]; then
107-
image_name=$(basename "$report" .txt | sed 's/trivy-report-//')
108-
echo "## 📦 Image: $image_name" >> $GITHUB_STEP_SUMMARY
109-
echo '```' >> $GITHUB_STEP_SUMMARY
110-
head -50 "$report" >> $GITHUB_STEP_SUMMARY
111-
echo '```' >> $GITHUB_STEP_SUMMARY
112-
echo "" >> $GITHUB_STEP_SUMMARY
113-
fi
114-
done
115-
116-
echo "✅ Full reports available in artifacts" >> $GITHUB_STEP_SUMMARY
117+
if ls trivy-report-*/trivy-report-*.txt 1> /dev/null 2>&1; then
118+
for report in trivy-report-*/trivy-report-*.txt; do
119+
if [ -f "$report" ]; then
120+
image_name=$(basename "$report" .txt | sed 's/trivy-report-//')
121+
echo "## 📦 Image: $image_name" >> $GITHUB_STEP_SUMMARY
122+
echo '```' >> $GITHUB_STEP_SUMMARY
123+
head -50 "$report" >> $GITHUB_STEP_SUMMARY
124+
echo '```' >> $GITHUB_STEP_SUMMARY
125+
echo "" >> $GITHUB_STEP_SUMMARY
126+
fi
127+
done
128+
echo "✅ Full reports available in artifacts" >> $GITHUB_STEP_SUMMARY
129+
else
130+
echo "⚠️ No report files found. Check the scan job logs for details." >> $GITHUB_STEP_SUMMARY
131+
fi

0 commit comments

Comments
 (0)