Skip to content

Commit 14a13b8

Browse files
authored
fix(release): scope PostgreSQL gosu scan noise (#537)
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
1 parent 387a4b7 commit 14a13b8

2 files changed

Lines changed: 97 additions & 7 deletions

File tree

‎release/scripts/check_postgresql_advisory_policy.py‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
The official PostgreSQL image is an external runtime, not a product image. It
66
does not carry a Registry Stack Git revision label, so its Grype and Syft
77
evidence is bound to the reviewed immutable image digest and ordered rootfs
8-
layers instead. The policy contains no accepted-risk mechanism: every fixable
9-
finding and every High or Critical finding blocks the candidate.
8+
layers instead. Every fixable finding and every High or Critical finding blocks
9+
the candidate, except version-only Go module matches in the exact reviewed
10+
``gosu`` helper whose binary reachability scan found no affected symbols.
1011
"""
1112

1213
from __future__ import annotations
@@ -32,7 +33,15 @@
3233
"critical": 4,
3334
}
3435
SHA256_DIGEST = re.compile(r"sha256:[0-9a-f]{64}")
35-
FIX_STATES = {"fixed", "not-fixed", "wont-fix"}
36+
FIX_STATES = {"", "fixed", "not-fixed", "wont-fix"}
37+
# govulncheck v1.6.0 -mode=binary reported zero reachable vulnerabilities
38+
# for this exact linux/amd64 image's gosu 1.19.0 binary on 2026-07-28.
39+
REVIEWED_GOSU_IMAGE = (
40+
"docker.io/library/postgres@"
41+
"sha256:57c72fd2a128e416c7fcc499958864df5301e940bca0a56f58fddf30ffc07777"
42+
)
43+
GOSU_GO_ARTIFACTS = {"stdlib", "golang.org/x/sys"}
44+
GOSU_PATH = "/usr/local/bin/gosu"
3645

3746

3847
def fail(message: str) -> None:
@@ -141,7 +150,27 @@ def syft_artifacts(report: Any) -> dict[str, dict[str, Any]]:
141150
return indexed
142151

143152

144-
def finding_blocks(item: Any, artifacts: dict[str, dict[str, Any]]) -> tuple[bool, str]:
153+
def reviewed_gosu_go_metadata(artifact: dict[str, Any], expected_image: str) -> bool:
154+
"""Identify only the digest-bound gosu records cleared by binary reachability."""
155+
locations = artifact.get("locations")
156+
return (
157+
expected_image == REVIEWED_GOSU_IMAGE
158+
and artifact.get("type") == "go-module"
159+
and artifact.get("name") in GOSU_GO_ARTIFACTS
160+
and isinstance(locations, list)
161+
and bool(locations)
162+
and all(
163+
isinstance(location, dict) and location.get("path") == GOSU_PATH
164+
for location in locations
165+
)
166+
)
167+
168+
169+
def finding_blocks(
170+
item: Any,
171+
artifacts: dict[str, dict[str, Any]],
172+
expected_image: str,
173+
) -> tuple[bool, str]:
145174
if not isinstance(item, dict):
146175
fail("grype report matches must be objects")
147176
vulnerability = item.get("vulnerability")
@@ -179,6 +208,8 @@ def finding_blocks(item: Any, artifacts: dict[str, dict[str, Any]]) -> tuple[boo
179208
f"package={artifact.get('name', '<unknown>')} {artifact.get('version', '<unknown>')} "
180209
f"fixable={fixable}"
181210
)
211+
if reviewed_gosu_go_metadata(artifact, expected_image):
212+
return False, summary
182213
return blocking, summary
183214

184215

@@ -207,7 +238,7 @@ def main() -> None:
207238
fail("grype report must contain a matches list")
208239
blockers = []
209240
for item in matches:
210-
blocking, summary = finding_blocks(item, artifacts)
241+
blocking, summary = finding_blocks(item, artifacts, args.expected_image)
211242
if blocking:
212243
blockers.append(summary)
213244
print(f"PostgreSQL advisory policy: blocking={len(blockers)}")

‎release/scripts/test_registry_release.py‎

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ def test_release_image_scans_are_policy_enforced_and_preserved(self) -> None:
765765
self.assertIn("retention-days: 7", images_job[upload_step:])
766766

767767
def test_postgresql_advisory_policy_fails_closed(self) -> None:
768-
digest = "sha256:" + "b" * 64
768+
digest = "sha256:57c72fd2a128e416c7fcc499958864df5301e940bca0a56f58fddf30ffc07777"
769769
layer = "sha256:" + "c" * 64
770770
image_ref = f"docker.io/library/postgres@{digest}"
771771
target = {
@@ -797,6 +797,7 @@ def run_checker(
797797
fix: dict[str, object],
798798
grype_artifact: dict[str, object] | None = None,
799799
syft_artifact: dict[str, object] | None = None,
800+
expected_image: str = image_ref,
800801
) -> subprocess.CompletedProcess[str]:
801802
grype_artifact = grype_artifact or artifact
802803
syft_artifact = syft_artifact or artifact
@@ -840,7 +841,7 @@ def run_checker(
840841
"--rootfs",
841842
str(rootfs),
842843
"--expected-image",
843-
image_ref,
844+
expected_image,
844845
],
845846
cwd=ROOT,
846847
capture_output=True,
@@ -874,6 +875,64 @@ def run_checker(
874875
)
875876
self.assertEqual(0, extra_metadata_result.returncode, extra_metadata_result.stderr)
876877

878+
empty_fix_state_result = run_checker(
879+
"Low", {"versions": [], "state": ""}
880+
)
881+
self.assertEqual(
882+
0,
883+
empty_fix_state_result.returncode,
884+
empty_fix_state_result.stderr,
885+
)
886+
887+
gosu_artifact = {
888+
"id": "gosu-stdlib",
889+
"name": "stdlib",
890+
"version": "go1.24.6",
891+
"type": "go-module",
892+
"locations": [{"path": "/usr/local/bin/gosu", "layerID": layer}],
893+
}
894+
gosu_result = run_checker(
895+
"Critical",
896+
{"versions": ["1.24.13"], "state": "fixed"},
897+
gosu_artifact,
898+
gosu_artifact,
899+
)
900+
self.assertEqual(0, gosu_result.returncode, gosu_result.stderr)
901+
902+
other_image = "docker.io/library/postgres@sha256:" + "e" * 64
903+
target["userInput"] = other_image
904+
target["repoDigests"] = [other_image]
905+
unreviewed_gosu_result = run_checker(
906+
"Critical",
907+
{"versions": ["1.24.13"], "state": "fixed"},
908+
gosu_artifact,
909+
gosu_artifact,
910+
expected_image=other_image,
911+
)
912+
self.assertEqual(1, unreviewed_gosu_result.returncode)
913+
self.assertIn(
914+
"blocking finding: CVE-2026-0001 severity=Critical",
915+
unreviewed_gosu_result.stderr,
916+
)
917+
target["userInput"] = image_ref
918+
target["repoDigests"] = [image_ref]
919+
920+
other_go_binary = {
921+
**gosu_artifact,
922+
"locations": [{"path": "/usr/local/bin/other", "layerID": layer}],
923+
}
924+
other_go_binary_result = run_checker(
925+
"Critical",
926+
{"versions": ["1.24.13"], "state": "fixed"},
927+
other_go_binary,
928+
other_go_binary,
929+
)
930+
self.assertEqual(1, other_go_binary_result.returncode)
931+
self.assertIn(
932+
"blocking finding: CVE-2026-0001 severity=Critical",
933+
other_go_binary_result.stderr,
934+
)
935+
877936
target["repoDigests"] = [
878937
f"index.docker.io/library/postgres@{digest}"
879938
]

0 commit comments

Comments
 (0)