This repository was archived by the owner on Aug 26, 2026. It is now read-only.
forked from rancher/etcd
-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (123 loc) · 5.06 KB
/
Copy pathcodeql-verification.yml
File metadata and controls
135 lines (123 loc) · 5.06 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
name: CodeQL verification
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
concurrency:
group: etcd-compat-codeql-${{ github.ref }}
cancel-in-progress: false
jobs:
analyze:
runs-on: ubuntu-24.04
timeout-minutes: 120
steps:
- name: Check out candidate
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Verify candidate shape
shell: bash
run: |
set -euo pipefail
test -z "$(git status --porcelain)"
git merge-base --is-ancestor fd17c9101d94703f6f4c3d8d6cfb72b62b894cd7 HEAD
- name: Install checksum-pinned Go toolchain
shell: bash
run: |
set -euo pipefail
archive="$RUNNER_TEMP/go1.27.0.linux-amd64.tar.gz"
curl --fail --silent --show-error --location \
--output "$archive" \
'https://go.dev/dl/go1.27.0.linux-amd64.tar.gz'
printf '%s %s\n' \
'675c26c449cbb18fc24b74650de1eabbae6e16f64326fd85a283fb3b58280685' \
"$archive" | sha256sum --check
tar -C "$RUNNER_TEMP" -xzf "$archive"
"$RUNNER_TEMP/go/bin/go" version
printf '%s\n' "$RUNNER_TEMP/go/bin" >> "$GITHUB_PATH"
printf 'GOROOT=%s\n' "$RUNNER_TEMP/go" >> "$GITHUB_ENV"
- name: Initialize CodeQL
uses: github/codeql-action/init@db488ddef3bf6cb639b32c2e9a7c0a7ea8271d28 # v4.37.8
with:
languages: go
build-mode: manual
config: |
queries:
- uses: security-extended
threat-models: local
- name: Build source
shell: bash
run: |
set -euo pipefail
export GO111MODULE=off
export GOPATH="$GITHUB_WORKSPACE/gopath"
mkdir -p "$GOPATH/src/github.com/coreos"
ln -s "$GITHUB_WORKSPACE" "$GOPATH/src/github.com/coreos/etcd"
cd "$GOPATH/src/github.com/coreos/etcd"
CGO_ENABLED=0 go build -trimpath -o "$RUNNER_TEMP/etcd" github.com/coreos/etcd
CGO_ENABLED=0 go build -trimpath -o "$RUNNER_TEMP/etcdctl" github.com/coreos/etcd/etcdctl
CGO_ENABLED=0 go build -trimpath -o "$RUNNER_TEMP/etcdwrapper" github.com/coreos/etcd/package/etcdwrapper
- name: Analyze without publishing temporary alerts
uses: github/codeql-action/analyze@db488ddef3bf6cb639b32c2e9a7c0a7ea8271d28 # v4.37.8
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 = []
unresolved = []
total = 0
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 extension in run.get('tool', {}).get('extensions', []):
rules.update({rule.get('id'): rule for rule in extension.get('rules', [])})
for result in run.get('results', []):
total += 1
rule_id = result.get('ruleId')
rule = rules.get(rule_id)
if rule is None:
unresolved.append((rule_id, 'missing rule metadata'))
continue
try:
score = float(rule.get('properties', {}).get('security-severity', '0'))
except (TypeError, ValueError):
unresolved.append((rule_id, 'invalid security severity'))
continue
if score >= 7.0:
location = result.get('locations', [{}])[0].get('physicalLocation', {})
blocked.append((rule_id, score, location.get('artifactLocation', {}).get('uri', 'unknown'), location.get('region', {}).get('startLine', 0)))
print(f'codeql_total={total}')
print(f'codeql_critical_high={len(blocked)}')
print(f'codeql_unresolved_rule_metadata={len(unresolved)}')
for finding in blocked:
print(f'{finding[0]}\t{finding[1]}\t{finding[2]}:{finding[3]}')
for finding in unresolved:
print(f'{finding[0]}\t{finding[1]}')
if blocked or unresolved:
raise SystemExit(1)
PY
- name: Upload verification evidence
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: etcd-compat-codeql-${{ github.sha }}
path: codeql-results/
if-no-files-found: error
retention-days: 7
compression-level: 9