-
Notifications
You must be signed in to change notification settings - Fork 1
172 lines (141 loc) · 5.13 KB
/
Copy pathsecurity-scan.yml
File metadata and controls
172 lines (141 loc) · 5.13 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
name: 🔒 Security Scan
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
schedule:
- cron: "0 2 * * 1" # Weekly on Monday at 2 AM UTC
jobs:
# CodeQL Analysis
codeql:
name: 🔍 CodeQL Analysis
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ["csharp"]
steps:
- name: 📥 Checkout
uses: actions/checkout@v7
- name: 🔍 Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
queries: security-extended,security-and-quality
- name: 🔍 Autobuild
uses: github/codeql-action/autobuild@v4
- name: 🔍 Perform Analysis
uses: github/codeql-action/analyze@v4
with:
category: "/language:${{matrix.language}}"
# Snyk Security Scan
snyk:
name: 🛡️ Snyk Security
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout
uses: actions/checkout@v7
- name: 🗄️ Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"
- name: 🔧 Restore Dependencies
run: dotnet restore QRCoder.Core.sln --ignore-failed-sources
- name: 🛡️ Install Snyk CLI
run: |
curl -s https://static.snyk.io/cli/latest/snyk-linux -o snyk
chmod +x ./snyk
sudo mv ./snyk /usr/local/bin/
- name: 🛡️ Run Snyk Security Scan
run: |
snyk test --severity-threshold=high --all-projects
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
# SonarQube Analysis
sonarqube:
name: 📊 SonarQube Analysis
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
steps:
- name: 📥 Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: 📦 Setup NuGet
uses: NuGet/setup-nuget@v4
- name: 🗄️ Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"
- name: ☕ Set up JDK 17
uses: actions/setup-java@v5
with:
java-version: 17
distribution: "zulu"
- name: 🔧 Clear NuGet cache
run: dotnet nuget locals all --clear
- name: 📦 Install SonarQube Tools
run: dotnet tool install --global --ignore-failed-sources dotnet-sonarscanner
- name: 📦 Install Coverlet Tools
run: dotnet tool install --global --ignore-failed-sources coverlet.console
- name: 🔧 Fix Permission
run: chmod 777 sonar/ -R || true
- name: 🔍 Prepare analysis on SonarQube
run: |
echo "🔍 Checking SonarQube configuration..."
if [ -z "${{ secrets.SONNAR_TOKEN }}" ]; then
echo "❌ SONNAR_TOKEN is not set or empty"
echo "⚠️ Skipping SonarQube analysis"
exit 0
fi
echo "✅ SONNAR_TOKEN is configured"
dotnet sonarscanner begin \
/o:"afonsoft" \
/k:"afonsoft_metar-decoder" \
/d:sonar.host.url="https://sonarcloud.io" \
/d:sonar.login="${{ secrets.SONNAR_TOKEN }}" \
/d:sonar.scm.provider=git \
/d:sonar.coverage.exclusions="**Test*.cs"
- name: 🏗️ Build
run: dotnet build QRCoder.Core.sln --configuration release
- name: 🔍 Run Code Analysis
run: |
echo "🔍 Finalizing SonarQube analysis..."
if [ -z "${{ secrets.SONNAR_TOKEN }}" ]; then
echo "⚠️ SONNAR_TOKEN not configured, skipping analysis"
exit 0
fi
dotnet sonarscanner end /d:sonar.login="${{ secrets.SONNAR_TOKEN }}"
# Security Summary
security-summary:
name: 📋 Security Summary
runs-on: ubuntu-latest
needs: [codeql, snyk]
if: always()
steps:
- name: 📋 Generate Security Report
run: |
echo "## 🔒 Security Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Tool | Status |" >> $GITHUB_STEP_SUMMARY
echo "|------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| 🔍 CodeQL | ${{ needs.codeql.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| 🛡️ Snyk | ${{ needs.snyk.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| 📊 SonarQube | ${{ contains(needs.*.result, 'skipped') && 'skipped' || 'N/A' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.codeql.result }}" == "failure" || "${{ needs.snyk.result }}" == "failure" ]]; then
echo "❌ **Security issues detected! Please review the scan results.**" >> $GITHUB_STEP_SUMMARY
else
echo "✅ **All security scans passed successfully!**" >> $GITHUB_STEP_SUMMARY
fi
- name: 🚨 Security Alert
if: needs.codeql.result == 'failure' || needs.snyk.result == 'failure'
run: |
echo "🚨 SECURITY ISSUES DETECTED!"
echo "Please review the security scan results immediately."