forked from rancher/kubernetes-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (86 loc) · 3.33 KB
/
Copy pathcodeql-verification.yml
File metadata and controls
96 lines (86 loc) · 3.33 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
name: CodeQL verification
on:
push:
branches:
- 'verification/kubernetes-authentication-bridge-*'
workflow_dispatch:
permissions:
contents: read
security-events: write
jobs:
analyze:
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
- name: Check out candidate
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803
with:
fetch-depth: 0
persist-credentials: false
- name: Install verified Go toolchain
shell: bash
env:
GO_VERSION: 1.26.5
GO_LINUX_AMD64_SHA256: 5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053
run: |
set -euo pipefail
archive="go${GO_VERSION}.linux-amd64.tar.gz"
curl --proto '=https' --tlsv1.2 --fail --silent --show-error --location \
--output "/tmp/${archive}" "https://go.dev/dl/${archive}"
printf '%s %s\n' "$GO_LINUX_AMD64_SHA256" "/tmp/${archive}" | sha256sum -c -
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "/tmp/${archive}"
printf '/usr/local/go/bin\n' >> "$GITHUB_PATH"
- name: Initialize CodeQL
uses: github/codeql-action/init@24c7eb380a2dc368f2d129e4c65e51d172983a1e
with:
languages: go
queries: security-extended
build-mode: autobuild
- name: Autobuild the same package graph as default setup
uses: github/codeql-action/autobuild@24c7eb380a2dc368f2d129e4c65e51d172983a1e
- name: Analyze without publishing temporary alerts
uses: github/codeql-action/analyze@24c7eb380a2dc368f2d129e4c65e51d172983a1e
with:
category: '/language:go'
upload: never
output: codeql-results
- name: Reject Critical and High findings
shell: bash
run: |
set -euo pipefail
python3 - <<'PY'
import glob
import json
blocked = []
for path in glob.glob('codeql-results/**/*.sarif', recursive=True):
with open(path, encoding='utf-8') as stream:
sarif = json.load(stream)
for run in sarif.get('runs', []):
rules = {
rule.get('id'): rule
for rule in run.get('tool', {}).get('driver', {}).get('rules', [])
}
for result in run.get('results', []):
rule = rules.get(result.get('ruleId'), {})
severity = str(rule.get('properties', {}).get('security-severity', '0'))
try:
score = float(severity)
except ValueError:
score = 0.0
if score >= 7.0:
blocked.append((result.get('ruleId'), score))
print('codeql_critical_high=' + str(len(blocked)))
if blocked:
for rule_id, score in blocked:
print(f'{rule_id}\t{score}')
raise SystemExit(1)
PY
- name: Upload verification evidence
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: kubernetes-authentication-bridge-codeql-${{ github.sha }}
path: codeql-results/
if-no-files-found: warn
retention-days: 7