forked from hazelcast/hazelcast
-
Notifications
You must be signed in to change notification settings - Fork 0
418 lines (402 loc) · 21.8 KB
/
Copy pathsecurity-release-gate.yml
File metadata and controls
418 lines (402 loc) · 21.8 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
name: Security release gate
on:
push:
branches:
- 'verification/distributed-cache-runtime-*'
workflow_dispatch:
permissions:
contents: read
concurrency:
group: distributed-cache-security-${{ github.ref }}
cancel-in-progress: false
jobs:
test-build-scan:
runs-on: ubuntu-24.04
timeout-minutes: 150
env:
TRIVY_IMAGE: aquasec/trivy:0.73.0@sha256:7cced7cae583819fc7806d4cbc0dbbc7cad18b99f7d3e235192e6da8c091045c
steps:
- name: Check out candidate
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
fetch-depth: 0
persist-credentials: false
- name: Install verified Temurin LTS JDK
shell: bash
env:
JDK_URL: https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.4%2B7/OpenJDK25U-jdk_x64_linux_hotspot_25.0.4_7.tar.gz
JDK_SHA256: e58fcdcd637b25c03ca84cbbcefc70d11efb8f4b4cbd05decc9f661769d77f94
run: |
set -euo pipefail
archive="$RUNNER_TEMP/temurin-jdk.tar.gz"
java_home="$RUNNER_TEMP/temurin-jdk"
curl --proto '=https' --tlsv1.2 --fail --silent --show-error --location \
--output "$archive" "$JDK_URL"
printf '%s %s\n' "$JDK_SHA256" "$archive" | sha256sum -c -
mkdir -p "$java_home"
tar -xzf "$archive" -C "$java_home" --strip-components=1
printf 'JAVA_HOME=%s\n' "$java_home" >> "$GITHUB_ENV"
printf '%s/bin\n' "$java_home" >> "$GITHUB_PATH"
"$java_home/bin/java" -version
- name: Verify candidate identity and supply-chain pins
shell: bash
run: |
set -euo pipefail
test -z "$(git status --porcelain)"
test "$(git rev-list --count 60c31e3750cbad64f5720e2e02f0a9830973193c..HEAD)" -eq 1
test "$(git rev-parse 60c31e3750cbad64f5720e2e02f0a9830973193c^{commit})" = \
60c31e3750cbad64f5720e2e02f0a9830973193c
grep -Fxq 'distributionSha256Sum=55fadd669532a3205d5db95f490bf13971d8b0843526f407f29db0e61f074ab3' \
.mvn/wrapper/maven-wrapper.properties
mkdir -p evidence
git rev-parse HEAD > evidence/source-revision.txt
sha256sum .mvn/wrapper/maven-wrapper.properties > evidence/source-locks.sha256
- name: Run focused legitimate and malicious regression suite
shell: bash
run: |
set -euo pipefail
core_tests='com.hazelcast.aws.AwsMetadataApiTest,com.hazelcast.azure.TagTest,com.hazelcast.config.XmlSchemaSourceSecurityTest,com.hazelcast.console.ConsoleAppTest,com.hazelcast.core.server.HazelcastMemberStarterTest,com.hazelcast.dataconnection.impl.JdbcDataConnectionTest,com.hazelcast.dataconnection.impl.JdbcUrlPolicyTest,com.hazelcast.dataconnection.impl.hazelcastdataconnection.HazelcastDataConnectionConfigLoaderTest,com.hazelcast.dataconnection.impl.jdbcproperties.HikariTranslatorTest,com.hazelcast.flakeidgen.impl.FlakeIdGeneratorProxyTest,com.hazelcast.gcp.LabelTest,com.hazelcast.gcp.UtilsTest,com.hazelcast.internal.config.ConfigLoaderSecurityTest,com.hazelcast.internal.diagnostics.DiagnosticsLogFileTest,com.hazelcast.internal.serialization.impl.ByteArrayObjectDataIntegrationTest,com.hazelcast.internal.serialization.impl.ObjectDataInputStreamIntegrationTest,com.hazelcast.internal.serialization.impl.UnsafeObjectDataInputIntegrationTest,com.hazelcast.internal.util.ClockTest,com.hazelcast.internal.util.HashUtilTest,com.hazelcast.internal.util.SecureFileAccessTest,com.hazelcast.internal.util.collection.LongHashSetTest,com.hazelcast.internal.util.concurrent.BackoffIdleStrategyTest,com.hazelcast.internal.util.phonehome.PhoneHomeDifferentConfigTest,com.hazelcast.internal.util.phonehome.PhoneHomeIntegrationTest,com.hazelcast.internal.util.XmlUtilTest,com.hazelcast.jet.impl.submitjob.memberside.JobUploadStatusTest,com.hazelcast.jet.impl.submitjob.memberside.validator.JarOnClientValidatorTest,com.hazelcast.jet.retry.impl.IntervalFunctionTest,com.hazelcast.kubernetes.KubernetesApiOriginPolicyTest,com.hazelcast.kubernetes.KubernetesConfigTest,com.hazelcast.spi.discovery.multicast.MulticastDiscoveryStrategyTest,com.hazelcast.spi.utils.RestClientTest,com.hazelcast.spi.utils.RetryUtilsTest'
all_tests="$core_tests,com.hazelcast.jet.sql.impl.parse.QueryParserTest,com.hazelcast.buildutils.ExportPackageViewerTest,com.hazelcast.jet.cdc.OperationTest"
timeout --signal=TERM --kill-after=30s 30m ./mvnw -B \
-pl hazelcast,hazelcast-sql,hazelcast-build-utils,extensions/cdc-debezium \
-am \
-Dcheckstyle.skip=true \
-Dsurefire.failIfNoSpecifiedTests=false \
-Dtest="$all_tests" \
test
timeout --signal=TERM --kill-after=30s 10m ./mvnw -B \
-pl hazelcast -am \
-Dcheckstyle.skip=true \
-Dsurefire.failIfNoSpecifiedTests=false \
-Dtest=com.hazelcast.query.impl.TypeConverterTest \
test
timeout --signal=TERM --kill-after=30s 15m ./mvnw -B \
-pl hazelcast -am \
-Dcheckstyle.skip=true \
-Dsurefire.failIfNoSpecifiedTests=false \
-Dtest=com.hazelcast.jet.impl.deployment.ProcessorClassLoaderTest \
test
scripts/check-xml-parser-hardening
scripts/check-numeric-conversion-hardening
- name: Verify every required test suite was discovered
shell: bash
run: |
set -euo pipefail
python3 - <<'PY'
import pathlib
import xml.etree.ElementTree as ET
core = '''
com.hazelcast.aws.AwsMetadataApiTest
com.hazelcast.azure.TagTest
com.hazelcast.config.XmlSchemaSourceSecurityTest
com.hazelcast.console.ConsoleAppTest
com.hazelcast.core.server.HazelcastMemberStarterTest
com.hazelcast.dataconnection.impl.JdbcDataConnectionTest
com.hazelcast.dataconnection.impl.JdbcUrlPolicyTest
com.hazelcast.dataconnection.impl.hazelcastdataconnection.HazelcastDataConnectionConfigLoaderTest
com.hazelcast.dataconnection.impl.jdbcproperties.HikariTranslatorTest
com.hazelcast.flakeidgen.impl.FlakeIdGeneratorProxyTest
com.hazelcast.gcp.LabelTest
com.hazelcast.gcp.UtilsTest
com.hazelcast.internal.config.ConfigLoaderSecurityTest
com.hazelcast.internal.diagnostics.DiagnosticsLogFileTest
com.hazelcast.internal.serialization.impl.ByteArrayObjectDataIntegrationTest
com.hazelcast.internal.serialization.impl.ObjectDataInputStreamIntegrationTest
com.hazelcast.internal.serialization.impl.UnsafeObjectDataInputIntegrationTest
com.hazelcast.internal.util.ClockTest
com.hazelcast.internal.util.HashUtilTest
com.hazelcast.internal.util.SecureFileAccessTest
com.hazelcast.internal.util.collection.LongHashSetTest
com.hazelcast.internal.util.concurrent.BackoffIdleStrategyTest
com.hazelcast.internal.util.phonehome.PhoneHomeDifferentConfigTest
com.hazelcast.internal.util.phonehome.PhoneHomeIntegrationTest
com.hazelcast.internal.util.XmlUtilTest
com.hazelcast.jet.impl.deployment.ProcessorClassLoaderTest
com.hazelcast.jet.impl.submitjob.memberside.JobUploadStatusTest
com.hazelcast.jet.impl.submitjob.memberside.validator.JarOnClientValidatorTest
com.hazelcast.jet.retry.impl.IntervalFunctionTest
com.hazelcast.kubernetes.KubernetesApiOriginPolicyTest
com.hazelcast.kubernetes.KubernetesConfigTest
com.hazelcast.query.impl.TypeConverterTest
com.hazelcast.spi.discovery.multicast.MulticastDiscoveryStrategyTest
com.hazelcast.spi.utils.RestClientTest
com.hazelcast.spi.utils.RetryUtilsTest
'''.split()
expected = [
(pathlib.Path('hazelcast/target/surefire-reports'), name)
for name in core
]
expected.append((
pathlib.Path('hazelcast-sql/target/surefire-reports'),
'com.hazelcast.jet.sql.impl.parse.QueryParserTest',
))
expected.append((
pathlib.Path('hazelcast-build-utils/target/surefire-reports'),
'com.hazelcast.buildutils.ExportPackageViewerTest',
))
expected.append((
pathlib.Path('extensions/cdc-debezium/target/surefire-reports'),
'com.hazelcast.jet.cdc.OperationTest',
))
total = failures = errors = skipped = 0
for directory, name in expected:
report = directory / f'TEST-{name}.xml'
if not report.is_file():
raise SystemExit(f'missing_test_report={name}')
suite = ET.parse(report).getroot()
total += int(suite.attrib.get('tests', 0))
failures += int(suite.attrib.get('failures', 0))
errors += int(suite.attrib.get('errors', 0))
skipped += int(suite.attrib.get('skipped', 0))
summary = (
f'test_suites={len(expected)}\n'
f'tests={total}\nfailures={failures}\nerrors={errors}\nskipped={skipped}\n'
)
pathlib.Path('evidence/test-summary.txt').write_text(summary, encoding='utf-8')
print(summary, end='')
if total < 385 or failures or errors or skipped:
raise SystemExit(1)
PY
- name: Build reviewed runtime artifact
shell: bash
run: |
set -euo pipefail
PASTURESTACK_OUTPUT_DIR=dist scripts/pasturestack-build-runtime
test -s dist/hazelcast-5.7.2.jar
sha256sum dist/hazelcast-5.7.2.jar | tee evidence/hazelcast-5.7.2.jar.sha256
jar tf dist/hazelcast-5.7.2.jar | grep -Fxq META-INF/LICENSE
jar tf dist/hazelcast-5.7.2.jar | grep -Fxq META-INF/NOTICE
- name: Generate SBOM and scan current source and artifact
shell: bash
run: |
set -euo pipefail
# Generate the reviewed runtime SBOM from Maven's resolved dependency
# graph. A filesystem scanner can only see this project's shaded JAR
# as one file and therefore cannot reconstruct its embedded libraries.
plugin_stage="$RUNNER_TEMP/cyclonedx-maven-plugin"
plugin_repo="$HOME/.m2/repository/org/cyclonedx/cyclonedx-maven-plugin/2.9.3"
plugin_base=https://repo.maven.apache.org/maven2/org/cyclonedx/cyclonedx-maven-plugin/2.9.3
mkdir -p "$plugin_stage" "$plugin_repo"
curl --proto '=https' --tlsv1.2 --fail --silent --show-error --location \
--output "$plugin_stage/cyclonedx-maven-plugin-2.9.3.jar" \
"$plugin_base/cyclonedx-maven-plugin-2.9.3.jar"
curl --proto '=https' --tlsv1.2 --fail --silent --show-error --location \
--output "$plugin_stage/cyclonedx-maven-plugin-2.9.3.pom" \
"$plugin_base/cyclonedx-maven-plugin-2.9.3.pom"
printf '%s %s\n%s %s\n' \
c452d5eebe28bc86bef2e7c72d129f04f60877bef843eac8120f01fb655be293 \
"$plugin_stage/cyclonedx-maven-plugin-2.9.3.jar" \
7c8d3c7c1a2efd58c134f09926f3de47d3de26de36130775ab1c3bfb74b4279c \
"$plugin_stage/cyclonedx-maven-plugin-2.9.3.pom" | sha256sum -c -
install -m 0644 "$plugin_stage/cyclonedx-maven-plugin-2.9.3.jar" "$plugin_repo/"
install -m 0644 "$plugin_stage/cyclonedx-maven-plugin-2.9.3.pom" "$plugin_repo/"
# The reviewed artifact build above already compiled the reactor.
# Install only the POMs and runtime prerequisite JAR into the runner's
# ephemeral repository, without recompiling or running tests.
./mvnw -B org.apache.maven.plugins:maven-install-plugin:3.1.4:install-file \
-Dfile=pom.xml -DpomFile=pom.xml
./mvnw -B org.apache.maven.plugins:maven-install-plugin:3.1.4:install-file \
-Dfile=hazelcast-parent/pom.xml -DpomFile=hazelcast-parent/pom.xml
test -s hazelcast-tpc-engine/target/hazelcast-tpc-engine-5.7.2.jar
./mvnw -B org.apache.maven.plugins:maven-install-plugin:3.1.4:install-file \
-Dfile=hazelcast-tpc-engine/target/hazelcast-tpc-engine-5.7.2.jar \
-DpomFile=hazelcast-tpc-engine/pom.xml
timeout --signal=TERM --kill-after=30s 30m ./mvnw -B \
-f hazelcast/pom.xml \
-DskipTests \
-Dcyclonedx.skipAttach=true \
-DincludeBomSerialNumber=false \
-DincludeCompileScope=true \
-DincludeProvidedScope=false \
-DincludeRuntimeScope=true \
-DincludeSystemScope=false \
-DincludeTestScope=false \
-DoutputFormat=json \
-DoutputReactorProjects=false \
-DoutputDirectory="$PWD/evidence" \
-DoutputName=hazelcast-5.7.2.cdx \
-DschemaVersion=1.6 \
org.cyclonedx:cyclonedx-maven-plugin:2.9.3:makeBom
printf '%s %s\n%s %s\n' \
c452d5eebe28bc86bef2e7c72d129f04f60877bef843eac8120f01fb655be293 \
"$plugin_repo/cyclonedx-maven-plugin-2.9.3.jar" \
7c8d3c7c1a2efd58c134f09926f3de47d3de26de36130775ab1c3bfb74b4279c \
"$plugin_repo/cyclonedx-maven-plugin-2.9.3.pom" | sha256sum -c -
timeout --signal=TERM --kill-after=30s 10m ./mvnw -B \
-f hazelcast/pom.xml \
-Dscope=runtime \
-DoutputType=json \
-DoutputFile="$PWD/evidence/maven-runtime-dependency-tree.json" \
org.apache.maven.plugins:maven-dependency-plugin:3.10.0:tree
docker pull "$TRIVY_IMAGE"
trivy_cache="$RUNNER_TEMP/trivy-cache"
mkdir -p "$trivy_cache"
docker run --rm \
-v "$trivy_cache:/root/.cache/trivy" \
"$TRIVY_IMAGE" image --cache-dir /root/.cache/trivy --download-db-only
source_tree=$(mktemp -d)
trap 'rm -rf "$source_tree"' EXIT
git archive --format=tar HEAD | tar -xf - -C "$source_tree"
docker run --rm --network none \
-v "$source_tree:/scan:ro" \
-v "$PWD/evidence:/evidence" \
-v "$trivy_cache:/root/.cache/trivy" \
"$TRIVY_IMAGE" fs \
--cache-dir /root/.cache/trivy --skip-db-update --offline-scan \
--scanners vuln,secret --severity CRITICAL,HIGH --format json \
--output /evidence/source-security.json /scan
docker run --rm --network none \
-v "$PWD/dist:/artifact:ro" \
-v "$PWD/evidence:/evidence" \
-v "$trivy_cache:/root/.cache/trivy" \
"$TRIVY_IMAGE" fs \
--cache-dir /root/.cache/trivy --skip-db-update --offline-scan \
--scanners vuln --severity CRITICAL,HIGH --format json \
--output /evidence/hazelcast-5.7.2.trivy.json /artifact/hazelcast-5.7.2.jar
docker run --rm --network none \
-v "$PWD/evidence:/evidence" \
-v "$trivy_cache:/root/.cache/trivy" \
"$TRIVY_IMAGE" sbom \
--cache-dir /root/.cache/trivy --skip-db-update --skip-java-db-update --offline-scan \
--scanners vuln --severity CRITICAL,HIGH --format json \
--output /evidence/hazelcast-5.7.2.sbom.trivy.json \
/evidence/hazelcast-5.7.2.cdx.json
sha256sum evidence/hazelcast-5.7.2.cdx.json \
evidence/hazelcast-5.7.2.sbom.trivy.json evidence/hazelcast-5.7.2.trivy.json \
> evidence/security-evidence.sha256
- name: Enforce complete zero-Critical and zero-High evidence
shell: bash
run: |
set -euo pipefail
python3 - <<'PY'
import json
import pathlib
def load(path):
with open(path, encoding='utf-8') as stream:
return json.load(stream)
source = load('evidence/source-security.json')
artifact = load('evidence/hazelcast-5.7.2.trivy.json')
dependency_scan = load('evidence/hazelcast-5.7.2.sbom.trivy.json')
sbom = load('evidence/hazelcast-5.7.2.cdx.json')
maven_tree = load('evidence/maven-runtime-dependency-tree.json')
source_vulnerabilities = [
item
for result in source.get('Results', [])
for item in result.get('Vulnerabilities') or []
if item.get('Severity') in {'CRITICAL', 'HIGH'}
]
source_secrets = [
item
for result in source.get('Results', [])
for item in result.get('Secrets') or []
]
artifact_vulnerabilities = [
item
for result in artifact.get('Results', [])
for item in result.get('Vulnerabilities') or []
if item.get('Severity') in {'CRITICAL', 'HIGH'}
]
dependency_vulnerabilities = [
item
for result in dependency_scan.get('Results', [])
for item in result.get('Vulnerabilities') or []
if item.get('Severity') in {'CRITICAL', 'HIGH'}
]
components = sbom.get('components') or []
component_refs = [item.get('bom-ref') for item in components]
component_purls = [item.get('purl') for item in components]
dependencies = sbom.get('dependencies') or []
root_component = sbom.get('metadata', {}).get('component') or {}
root_ref = root_component.get('bom-ref')
dependency_refs = {item.get('ref') for item in dependencies}
allowed_refs = set(component_refs) | {root_ref}
dangling_dependency_refs = sorted(
child
for item in dependencies
for child in item.get('dependsOn') or []
if child not in allowed_refs
)
dependencies_exist = any(item.get('dependsOn') for item in dependencies)
maven_coordinates = set()
remaining_nodes = [maven_tree]
while remaining_nodes:
node = remaining_nodes.pop()
if node.get('scope') in {'compile', 'runtime'} and str(node.get('optional')).lower() != 'true':
maven_coordinates.add((node.get('groupId'), node.get('artifactId'), node.get('version')))
remaining_nodes.extend(node.get('children') or [])
sbom_coordinates = {
(item.get('group'), item.get('name'), item.get('version'))
for item in components
}
maven_root = (maven_tree.get('groupId'), maven_tree.get('artifactId'), maven_tree.get('version'))
sbom_root = (root_component.get('group'), root_component.get('name'), root_component.get('version'))
missing_from_sbom = sorted(maven_coordinates - sbom_coordinates)
unexpected_in_sbom = sorted(sbom_coordinates - maven_coordinates)
missing_identity = [
item for item in components
if not item.get('group') or not item.get('name') or not item.get('version') or not item.get('purl')
]
summary = (
f'source_critical_high={len(source_vulnerabilities)}\n'
f'source_secrets={len(source_secrets)}\n'
f'artifact_critical_high={len(artifact_vulnerabilities)}\n'
f'dependency_critical_high={len(dependency_vulnerabilities)}\n'
f'sbom_spec={sbom.get("specVersion", "missing")}\n'
f'sbom_components={len(components)}\n'
f'sbom_dependencies={len(dependencies)}\n'
f'maven_runtime_components={len(maven_coordinates)}\n'
f'sbom_runtime_missing={len(missing_from_sbom)}\n'
f'sbom_runtime_unexpected={len(unexpected_in_sbom)}\n'
f'sbom_dangling_dependency_refs={len(dangling_dependency_refs)}\n'
)
pathlib.Path('evidence/security-summary.txt').write_text(summary, encoding='utf-8')
print(summary, end='')
if (
source_vulnerabilities
or source_secrets
or artifact_vulnerabilities
or dependency_vulnerabilities
or sbom.get('specVersion') != '1.6'
or not components
or missing_identity
or None in component_refs
or None in component_purls
or len(component_refs) != len(set(component_refs))
or len(component_purls) != len(set(component_purls))
or maven_root != ('com.hazelcast', 'hazelcast', '5.7.2')
or sbom_root != maven_root
or root_ref not in dependency_refs
or dependency_refs != allowed_refs
or dangling_dependency_refs
or not dependencies_exist
or missing_from_sbom
or unexpected_in_sbom
):
raise SystemExit(1)
PY
# The Maven plugin validates the produced BOM against CycloneDX 1.6
# while writing it; this second independent validator prevents a
# generator regression from being accepted by its own implementation.
docker run --rm --network none \
-v "$PWD/evidence:/evidence:ro" \
cyclonedx/cyclonedx-cli:0.32.0@sha256:9a858a15e7b0843606efc0ff19d5f7575011a5428d7f3d343b4f6cf09d8f0d4e \
validate --input-file /evidence/hazelcast-5.7.2.cdx.json \
--input-format json --input-version v1_6 --fail-on-errors
- name: Upload review evidence
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: distributed-cache-security-${{ github.sha }}
path: evidence/
if-no-files-found: error
retention-days: 30
compression-level: 9
include-hidden-files: false
- name: Clean runner resources
if: always()
shell: bash
run: |
set +e
docker image rm -f "$TRIVY_IMAGE" >/dev/null 2>&1
docker builder prune --all --force >/dev/null 2>&1
rm -rf dist evidence