mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-03 08:17:52 +00:00
feat(sys-ctl-hlth-runtime): suppress vulnerability findings per image tag
A suppression entry under <service>.security.suppressions now names either one CVE (id) or one image tag (image_tag), each with until. An image_tag entry accepts every finding of the service's image while the owner runs that tag; each owner of a shared digest is judged by its own tag (Config.Image at runtime, the pinned version in the mirror scan), so a container on any other tag stays unsuppressed. Host suppressions are the id entries of the engine services; an image_tag entry there covers the engine's own image. The cve lint requires image_tag to equal the service's version, and the Docker image updater drops a service's image_tag entries with their markers when it moves the service to another version, so a tag suppression never outlives its tag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c9c7acbb61
commit
65863a2b20
14 files changed
+713
-57
No files matched your search
@@ -5,9 +5,11 @@ import tempfile
|
||||
from pathlib import Path
|
||||
from unittest import TestCase, main
|
||||
|
||||
from utils.cache.yaml import load_yaml_str
|
||||
from utils.security.suppressions import (
|
||||
Suppression,
|
||||
SuppressionError,
|
||||
drop_image_tag_entries,
|
||||
parse_entries,
|
||||
role_suppressions,
|
||||
service_suppressions,
|
||||
@@ -19,7 +21,42 @@ class TestParseEntries(TestCase):
|
||||
parsed = parse_entries(
|
||||
[{"id": "CVE-2026-1234", "until": dt.date(2026, 12, 31)}], "r:s"
|
||||
)
|
||||
self.assertEqual(parsed, [Suppression("CVE-2026-1234", dt.date(2026, 12, 31))])
|
||||
self.assertEqual(
|
||||
parsed, [Suppression("CVE-2026-1234", None, dt.date(2026, 12, 31))]
|
||||
)
|
||||
|
||||
def test_an_image_tag_entry_is_kept(self):
|
||||
parsed = parse_entries([{"image_tag": "2.18.5", "until": "2026-12-31"}], "r:s")
|
||||
self.assertEqual(parsed, [Suppression(None, "2.18.5", dt.date(2026, 12, 31))])
|
||||
|
||||
def test_an_entry_with_id_and_image_tag_is_rejected(self):
|
||||
with self.assertRaisesRegex(
|
||||
SuppressionError, "exactly one of id and image_tag"
|
||||
):
|
||||
parse_entries(
|
||||
[
|
||||
{
|
||||
"id": "CVE-2026-1234",
|
||||
"image_tag": "2.18.5",
|
||||
"until": "2026-12-31",
|
||||
}
|
||||
],
|
||||
"r:s",
|
||||
)
|
||||
|
||||
def test_an_entry_without_id_or_image_tag_is_rejected(self):
|
||||
with self.assertRaisesRegex(
|
||||
SuppressionError, "exactly one of id and image_tag"
|
||||
):
|
||||
parse_entries([{"until": "2026-12-31"}], "r:s")
|
||||
|
||||
def test_an_unquoted_numeric_image_tag_is_rejected(self):
|
||||
with self.assertRaisesRegex(SuppressionError, "non-empty quoted string"):
|
||||
parse_entries([{"image_tag": 1.1, "until": "2026-12-31"}], "r:s")
|
||||
|
||||
def test_an_empty_image_tag_is_rejected(self):
|
||||
with self.assertRaisesRegex(SuppressionError, "non-empty quoted string"):
|
||||
parse_entries([{"image_tag": "", "until": "2026-12-31"}], "r:s")
|
||||
|
||||
def test_a_quoted_until_is_parsed(self):
|
||||
parsed = parse_entries([{"id": "CVE-2026-1234", "until": "2026-12-31"}], "r:s")
|
||||
@@ -56,6 +93,92 @@ class TestParseEntries(TestCase):
|
||||
parse_entries({"id": "CVE-2026-1234"}, "r:s")
|
||||
|
||||
|
||||
MIXED = """\
|
||||
app:
|
||||
image: app
|
||||
version: "1.2"
|
||||
security:
|
||||
suppressions:
|
||||
# nocheck: cve the module is not built into the image
|
||||
- id: CVE-2026-1234
|
||||
until: 2026-12-31
|
||||
|
||||
# nocheck: cve upstream ships no rebuild yet
|
||||
- until: 2026-12-31
|
||||
image_tag: "1.2"
|
||||
mem_limit: 1g
|
||||
db:
|
||||
image: postgres
|
||||
version: "17"
|
||||
security:
|
||||
suppressions:
|
||||
# nocheck: cve upstream ships no rebuild yet
|
||||
- image_tag: "17"
|
||||
until: 2026-12-31
|
||||
"""
|
||||
|
||||
|
||||
def _drop(text, service):
|
||||
return "".join(drop_image_tag_entries(text.splitlines(keepends=True), service))
|
||||
|
||||
|
||||
class TestDropImageTagEntries(TestCase):
|
||||
def test_only_the_tag_entry_and_its_marker_leave(self):
|
||||
self.assertEqual(
|
||||
_drop(MIXED, "app"),
|
||||
MIXED.replace(
|
||||
"\n # nocheck: cve upstream ships no rebuild yet\n"
|
||||
" - until: 2026-12-31\n"
|
||||
' image_tag: "1.2"\n',
|
||||
"\n",
|
||||
),
|
||||
)
|
||||
|
||||
def test_an_emptied_list_takes_suppressions_and_security_along(self):
|
||||
self.assertEqual(
|
||||
_drop(MIXED, "db"),
|
||||
MIXED.replace(
|
||||
' version: "17"\n'
|
||||
" security:\n"
|
||||
" suppressions:\n"
|
||||
" # nocheck: cve upstream ships no rebuild yet\n"
|
||||
' - image_tag: "17"\n'
|
||||
" until: 2026-12-31\n",
|
||||
' version: "17"\n',
|
||||
),
|
||||
)
|
||||
|
||||
def test_the_result_still_parses(self):
|
||||
for service in ("app", "db"):
|
||||
with self.subTest(service=service):
|
||||
parsed = load_yaml_str(_drop(MIXED, service))
|
||||
self.assertEqual(
|
||||
[
|
||||
entry.image_tag
|
||||
for entries in service_suppressions(parsed, "r").values()
|
||||
for entry in entries
|
||||
],
|
||||
[None, "17"] if service == "app" else [None, "1.2"],
|
||||
)
|
||||
|
||||
def test_a_sequence_at_the_key_indent_is_handled(self):
|
||||
text = (
|
||||
"app:\n"
|
||||
" security:\n"
|
||||
" suppressions:\n"
|
||||
" # nocheck: cve upstream ships no rebuild yet\n"
|
||||
' - image_tag: "1"\n'
|
||||
" until: 2026-12-31\n"
|
||||
" mem_limit: 1g\n"
|
||||
)
|
||||
self.assertEqual(_drop(text, "app"), "app:\n mem_limit: 1g\n")
|
||||
|
||||
def test_a_service_without_tag_entries_is_unchanged(self):
|
||||
text = "app:\n image: app\n"
|
||||
self.assertEqual(_drop(text, "app"), text)
|
||||
self.assertEqual(_drop(text, "other"), text)
|
||||
|
||||
|
||||
class TestServiceSuppressions(TestCase):
|
||||
def test_services_without_security_are_left_out(self):
|
||||
services = {
|
||||
|
||||
@@ -77,6 +77,43 @@ nginx:
|
||||
self.assertIn("version: alpine", updated)
|
||||
self.assertNotIn('version: "4.5" # Keep comment', updated)
|
||||
|
||||
def test_a_bump_drops_the_image_tag_suppression_of_the_old_tag(self) -> None:
|
||||
original = """penpot:
|
||||
image: penpotapp/exporter
|
||||
version: "2.18.5"
|
||||
security:
|
||||
suppressions:
|
||||
# nocheck: cve upstream ships no rebuild yet
|
||||
- image_tag: "2.18.5"
|
||||
until: 2026-12-31
|
||||
# nocheck: shared
|
||||
nginx:
|
||||
image: nginx
|
||||
version: "1.29"
|
||||
security:
|
||||
suppressions:
|
||||
# nocheck: cve upstream ships no rebuild yet
|
||||
- image_tag: "1.29"
|
||||
until: 2026-12-31
|
||||
"""
|
||||
expected = original.replace(
|
||||
""" version: "2.18.5"
|
||||
security:
|
||||
suppressions:
|
||||
# nocheck: cve upstream ships no rebuild yet
|
||||
- image_tag: "2.18.5"
|
||||
until: 2026-12-31
|
||||
""",
|
||||
' version: "2.18.6"\n',
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
config_path = Path(tmpdir) / "main.yml"
|
||||
config_path.write_text(original, encoding="utf-8")
|
||||
|
||||
update_config_versions(config_path, {"penpot": "2.18.6"})
|
||||
|
||||
self.assertEqual(read_text(str(config_path)), expected)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user