Repository navigation
313 lines (271 loc) · 10.7 KB
/
Copy pathcodeql.yml
File metadata and controls
313 lines (271 loc) · 10.7 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
name: "CodeQL Security Analysis"
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
release:
types: [published]
schedule:
- cron: "0 3 * * 0" # Weekly on Sunday at 3 AM UTC
jobs:
analyze:
name: "CodeQL Analysis (Linux x64 Clang Release)"
runs-on: ubuntu-22.04
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ["cpp"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install system dependencies
timeout-minutes: 15
run: |
set -e # Exit on any error
# Update package list first
sudo apt update
# Install basic dependencies first
sudo apt install -y cmake python3-pip git wget curl
# Install Clang 18 with timeout and retry logic
echo "Installing Clang 18 for CodeQL analysis..."
for i in {1..3}; do
if timeout 10m bash -c "
wget -q https://apt.llvm.org/llvm.sh &&
chmod +x llvm.sh &&
sudo ./llvm.sh 18
"; then
echo "LLVM installation successful on attempt $i"
break
else
echo "LLVM installation attempt $i failed, retrying..."
rm -f llvm.sh
if [ $i -eq 3 ]; then
echo "All LLVM installation attempts failed"
exit 1
fi
sleep 30
fi
done
# Install additional tools
sudo apt install -y clang-format-18 || {
echo "clang-format-18 not available, trying alternatives..."
sudo apt install -y clang-format || echo "clang-format installation failed"
}
# Set up symlinks
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++
if command -v clang-format-18 >/dev/null 2>&1; then
sudo ln -sf /usr/bin/clang-format-18 /usr/bin/clang-format
fi
# Verify installation
clang --version
clang++ --version
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Conan
run: |
pip3 install --user conan
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup Conan profile
run: |
conan profile detect --force
# Update to use the correct Clang version and C++23
CLANG_VERSION=$(clang-18 --version 2>/dev/null | head -n1 | grep -o '[0-9]\+' | head -n1 || clang --version | head -n1 | grep -o '[0-9]\+' | head -n1)
echo "Detected Clang version: $CLANG_VERSION"
sed -i 's/compiler=gcc/compiler=clang/' ~/.conan2/profiles/default
if [ -n "$CLANG_VERSION" ]; then
sed -i "s/compiler.version=.*/compiler.version=$CLANG_VERSION/" ~/.conan2/profiles/default
else
echo "Warning: Could not detect Clang version, using Conan default"
fi
sed -i 's/compiler.libcxx=libstdc++11/compiler.libcxx=libstdc++11/' ~/.conan2/profiles/default
sed -i 's/compiler.cppstd=gnu17/compiler.cppstd=23/' ~/.conan2/profiles/default
sed -i 's/compiler.cppstd=17/compiler.cppstd=23/' ~/.conan2/profiles/default
echo "=== Final Conan Profile ==="
conan profile show --profile:host=default
- name: Cache Conan packages
uses: actions/cache@v4
with:
path: ~/.conan2
key: conan-codeql-clang-release-${{ hashFiles('conanfile.py') }}
restore-keys: |
conan-codeql-clang-release-
conan-linux-clang-
- name: Install dependencies
run: |
export CC=clang
export CXX=clang++
conan install . -s os=Linux -s build_type=Release --output-folder=build --build=missing -o with_gperftools=True
# Initialize CodeQL tools for scanning
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# Use standard security query suites for comprehensive coverage
queries: security-extended,security-and-quality
# Simple path configuration inline to avoid config file issues
config: |
paths-ignore:
- "build/"
- "conan-cache/"
- ".conan2/"
- "**/*.cmake"
- "**/CMakeFiles/"
# Configure and build the project with Clang Release build for CodeQL analysis
- name: Configure CMake (Release build with Clang)
run: |
export CC=clang
export CXX=clang++
cmake --preset conan-release \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++
- name: Build for CodeQL (Release)
run: |
cmake --build --preset conan-release --parallel
# Perform CodeQL Analysis
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
upload: true
# Upload CodeQL database as artifact (optional, for debugging)
- name: Upload CodeQL Database as Artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: codeql-database-cpp
path: ${{ runner.temp }}/codeql_databases
retention-days: 7
compression-level: 6
# Run additional security checks on the Release build
- name: Run Security Tests
run: |
cd build/build
# Run tests to ensure the release build is secure and functional
./utf_strings-tests
# Run benchmarks to ensure performance hasn't regressed
./utf_strings-bench --benchmark_min_time=0.1s --benchmark_format=json --benchmark_out=security_analysis_benchmarks.json
- name: Upload security analysis artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: codeql-security-analysis-results
path: |
build/build/security_analysis_benchmarks.json
# Enhanced security analysis for releases
release-security-analysis:
name: "Enhanced Security Analysis for Release"
runs-on: ubuntu-22.04
if: github.event_name == 'release'
needs: [analyze]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install additional security tools
run: |
sudo apt update
sudo apt install -y clang-tools cppcheck valgrind
- name: Install system dependencies
timeout-minutes: 15
run: |
set -e # Exit on any error
# Install basic dependencies first
sudo apt install -y cmake python3-pip git wget curl
# Install Clang 18 with timeout and retry logic
echo "Installing Clang 18 for enhanced security analysis..."
for i in {1..3}; do
if timeout 10m bash -c "
wget -q https://apt.llvm.org/llvm.sh &&
chmod +x llvm.sh &&
sudo ./llvm.sh 18
"; then
echo "LLVM installation successful on attempt $i"
break
else
echo "LLVM installation attempt $i failed, retrying..."
rm -f llvm.sh
if [ $i -eq 3 ]; then
echo "All LLVM installation attempts failed"
exit 1
fi
sleep 30
fi
done
# Install additional tools
sudo apt install -y clang-format-18 || {
echo "clang-format-18 not available, trying alternatives..."
sudo apt install -y clang-format || echo "clang-format installation failed"
}
# Set up symlinks
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++
# Verify installation
clang --version
clang++ --version
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Conan
run: |
pip3 install --user conan
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup Conan profile
run: |
conan profile detect --force
# Update to use the correct Clang version and C++23
CLANG_VERSION=$(clang-18 --version 2>/dev/null | head -n1 | grep -o '[0-9]\+' | head -n1 || clang --version | head -n1 | grep -o '[0-9]\+' | head -n1)
echo "Detected Clang version: $CLANG_VERSION"
sed -i 's/compiler=gcc/compiler=clang/' ~/.conan2/profiles/default
if [ -n "$CLANG_VERSION" ]; then
sed -i "s/compiler.version=.*/compiler.version=$CLANG_VERSION/" ~/.conan2/profiles/default
else
echo "Warning: Could not detect Clang version, using Conan default"
fi
sed -i 's/compiler.libcxx=libstdc++11/compiler.libcxx=libstdc++11/' ~/.conan2/profiles/default
sed -i 's/compiler.cppstd=gnu17/compiler.cppstd=23/' ~/.conan2/profiles/default
sed -i 's/compiler.cppstd=17/compiler.cppstd=23/' ~/.conan2/profiles/default
echo "=== Final Conan Profile ==="
conan profile show --profile:host=default
- name: Install dependencies
run: |
export CC=clang
export CXX=clang++
conan install . -s os=Linux -s build_type=Release --output-folder=build --build=missing -o with_gperftools=True
- name: Configure and Build with Security Hardening
run: |
export CC=clang
export CXX=clang++
cmake --preset conan-release
cmake --build --preset conan-release --parallel
- name: Run Static Analysis (clang-tidy)
run: |
clang-tidy-18 --version
find src include -name "*.cpp" -o -name "*.hpp" | xargs clang-tidy-18 -p build/build --
- name: Run Static Analysis (cppcheck)
run: |
cppcheck --enable=all --std=c++23 --inline-suppr --error-exitcode=1 \
--suppress=missingIncludeSystem --suppress=unmatchedSuppression \
src/ include/ tests/ benchmarks/
- name: Run Memory Analysis (Valgrind)
run: |
cd build/build
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all \
--track-origins=yes --error-exitcode=1 ./utf_strings-tests
- name: Upload enhanced security results
uses: actions/upload-artifact@v4
if: always()
with:
name: enhanced-security-analysis-results
path: |
clang-tidy-results.txt
cppcheck-results.txt
valgrind-results.txt