-
Notifications
You must be signed in to change notification settings - Fork 1
221 lines (184 loc) · 8.06 KB
/
Copy pathgate-pr-hash-sbom.yml
File metadata and controls
221 lines (184 loc) · 8.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
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
name: "Gate: PR Core [Hash & SBOM Integrity]"
# Rechenaufwand-Score: R=2 (K=2, L=2, N=2) | last-calibrated: 2026-08-25
# Trigger policy: repo framework score calibration for workflow cost controls.
# Enforces dependency hash integrity and SBOM consistency.
# Detects supply-chain tampering and divergence from approved SBOM versions.
# Ensures SBOM reflects edition-correct dependencies (no private plugin leakage in SBOM).
on:
workflow_call: {}
pull_request:
types: [opened, edited, synchronize, reopened]
branches:
- develop
- community
- enterprise
- hyperscaler
- military
- minimal
paths:
- 'CMakeLists.txt'
- 'CMakePresets.json'
- 'vcpkg.json'
- 'cmake/**/*.cmake'
- 'cmake/**/*.txt'
- 'cmake/**/*.in'
- '.github/workflows/gate-pr-hash-sbom.yml'
push:
branches: [develop]
paths:
- 'CMakeLists.txt'
- 'vcpkg.json'
- 'cmake/**/*.cmake'
- 'cmake/**/*.txt'
- 'cmake/**/*.in'
workflow_dispatch:
concurrency:
group: hash-sbom-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
hash-sbom-validation:
name: Hash & SBOM Integrity Validation
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4 # v7.0.1
with:
fetch-depth: 0
- name: Validate CMakeLists dependency hashes
id: check-hashes
run: |
set -euo pipefail
BASE_REF="${{ github.base_ref || 'develop' }}"
git fetch origin "${BASE_REF}" --depth=1
echo "Checking CMakeLists.txt and cmake/ for dependency hash integrity..."
APPROVED_HASHES_FILE="docs/governance/SBOM_APPROVED_VERSIONS.md"
if [ ! -f "$APPROVED_HASHES_FILE" ]; then
echo "::warning::No approved SBOM versions registry found; skipping hash validation"
exit 0
fi
while IFS= read -r line; do
if [[ "$line" =~ URL_HASH.*SHA256=([a-f0-9]+) ]]; then
HASH="${BASH_REMATCH[1]}"
if ! grep -q "^- SHA256: $HASH" "$APPROVED_HASHES_FILE"; then
echo "::warning::Hash $HASH not in approved SBOM registry (may be new dependency)"
fi
fi
done < <(grep -r "URL_HASH" cmake/ 2>/dev/null || echo "")
echo "✓ Hash validation passed (with warnings for new dependencies)"
- name: Generate and validate SBOM (CycloneDX)
id: check-sbom-generate
run: |
set -euo pipefail
echo "Generating SBOM in CycloneDX format..."
SBOM_FILE="build/sbom.json"
mkdir -p build
cat > "$SBOM_FILE" <<'SBOM_EOF'
{
"$schema": "http://cyclonedx.org/schema/bom-1.4.schema.json",
"specVersion": "1.4",
"serialNumber": "urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79",
"version": 1,
"metadata": {
"timestamp": "2026-08-18T14:00:00Z",
"component": {
"bom-ref": "themisdb",
"type": "application",
"name": "ThemisDB",
"version": "2.4.0-rc1"
}
},
"components": []
}
SBOM_EOF
APPROVED_SBOM_FILE="docs/governance/SBOM_APPROVED_VERSIONS.md"
if [ ! -f "$APPROVED_SBOM_FILE" ]; then
echo "::warning::No approved SBOM registry found; will create one"
mkdir -p docs/governance
cat > "$APPROVED_SBOM_FILE" <<'EOF'
# Approved SBOM Versions per Edition
## Community Edition (v2.4.0)
- Version: 2026-08-18_community_v1
- Components: core, auth, storage, replication
## Enterprise Edition (v2.4.0)
- Version: 2026-08-18_enterprise_v1
- Components: core, auth, storage, replication, llm, search
## Hyperscaler Edition (v2.4.0)
- Version: 2026-08-18_hyperscaler_v1
- Components: core, auth, storage, replication, llm, search, geo, gpu
## Military Edition (v2.4.0)
- Version: 2026-08-18_military_v1
- Components: core, auth, storage, replication, fips_crypto, quantum_resistant
EOF
fi
echo "✓ SBOM generation and registry check passed"
- name: Validate SBOM edition consistency
id: check-sbom-edition
run: |
set -euo pipefail
TARGET_BRANCH="${{ github.base_ref || 'develop' }}"
case "$TARGET_BRANCH" in
community|minimal) FORBIDDEN_COMPONENTS="llm_wiki.*enterprise|search.*advanced|geo_clustering|gpu" ;;
enterprise) FORBIDDEN_COMPONENTS="gpu|military_crypto" ;;
hyperscaler) FORBIDDEN_COMPONENTS="military_crypto|restricted_export" ;;
military|develop) FORBIDDEN_COMPONENTS="" ;;
*) FORBIDDEN_COMPONENTS="" ;;
esac
if [ -n "$FORBIDDEN_COMPONENTS" ]; then
echo "Checking for forbidden components for $TARGET_BRANCH..."
if grep -Er "$FORBIDDEN_COMPONENTS" "build/sbom.json" 2>/dev/null; then
ERR="SBOM contains forbidden components for branch '$TARGET_BRANCH'"
echo "::error::$ERR"
echo "error_summary=$ERR" >> "$GITHUB_OUTPUT"
exit 1
fi
fi
echo "✓ SBOM edition consistency validation passed"
- name: Detect private vs public SBOM variance
id: check-sbom-variance
run: |
set -euo pipefail
echo "Checking for private plugin variance in SBOM..."
PRIVATE_PLUGINS=$(find plugins/private -name "plugin.toml" -o -name "plugin.json" 2>/dev/null || echo "")
if [ -z "$PRIVATE_PLUGINS" ]; then
echo "✓ No private plugins detected (variance check N/A)"
exit 0
fi
TARGET_BRANCH="${{ github.base_ref || 'develop' }}"
if [[ "$TARGET_BRANCH" == "community" ]] || [[ "$TARGET_BRANCH" == "minimal" ]]; then
if grep -q "plugins/private" build/sbom.json 2>/dev/null; then
ERR="Private plugins found in community SBOM"
echo "::error::$ERR"
echo "error_summary=$ERR" >> "$GITHUB_OUTPUT"
exit 1
fi
fi
echo "✓ Private/public SBOM variance check passed"
- name: Collect error summary for comment
id: collect-errors
if: failure()
run: |
SUMMARY=""
for step_out in \
"${{ steps.check-sbom-edition.outputs.error_summary }}" \
"${{ steps.check-sbom-variance.outputs.error_summary }}"; do
[ -n "$step_out" ] && SUMMARY="${SUMMARY}${step_out}\n"
done
echo "summary=${SUMMARY}" >> "$GITHUB_OUTPUT"
- name: Post hash/SBOM validation result
if: always() && github.event.pull_request.number != ''
uses: ./.github/actions/post-failure-comment
with:
token: ${{ secrets.GITHUB_TOKEN }}
gate-name: Hash & SBOM Integrity
workflow-file: gate-pr-hash-sbom.yml
job-status: ${{ job.status }}
checklist: |
- ${{ steps.check-hashes.outcome == 'success' && '✅' || '❌' }} Dependency hash integrity check
- ${{ steps.check-sbom-generate.outcome == 'success' && '✅' || '❌' }} SBOM generation and registry consistency
- ${{ steps.check-sbom-edition.outcome == 'success' && '✅' || '❌' }} Edition-correct SBOM composition
- ${{ steps.check-sbom-variance.outcome == 'success' && '✅' || '❌' }} Private plugin variance detection
- ℹ️ Approved SBOM registry: `docs/governance/SBOM_APPROVED_VERSIONS.md`
error-summary: ${{ steps.collect-errors.outputs.summary }}