ci(lint): keep the job token away from renovate.json and pin image lines in place

The renovate-config job clones in its own step and validates in a second
step, so the job token is not in the environment that reads the pull
request's renovate.json.

check_bot_pr_diff.py now refuses a moved image line in every workflow
whose pins a bot may move, lint.yml included, not only in image.yml and
renovate.yml. Tests cover a moved lint.yml line, an added second
Renovate line and a changed indentation.

Refs: #188
Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-12-06 17:25:56 +00:00
1 parent 076546f91b
commit 9fb3cbd4fd
3 files changed
+34 -14

No files matched your search

+9 -4
View File
@@ -157,8 +157,8 @@ jobs:
container: container:
image: renovate/renovate:44.161.0-full@sha256:ddbf02e44b542343c9df696b88fd953f04cc3ee5f771221805ff8efb26595416 image: renovate/renovate:44.161.0-full@sha256:ddbf02e44b542343c9df696b88fd953f04cc3ee5f771221805ff8efb26595416
steps: steps:
# The image runs as a non-root user, so the clone goes to a directory it owns. # The image runs as a non-root user, so the clone goes to the runner's temp directory.
- name: Validate renovate.json - name: Checkout the commit under test
env: env:
GIT_CONFIG_COUNT: "1" GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: http.extraheader GIT_CONFIG_KEY_0: http.extraheader
@@ -167,10 +167,15 @@ jobs:
REF: ${{ github.ref }} REF: ${{ github.ref }}
REPO_URL: ${{ github.server_url }}/${{ github.repository }} REPO_URL: ${{ github.server_url }}/${{ github.repository }}
run: | run: |
src="$(mktemp -d)" src="${RUNNER_TEMP:-/tmp}/renovate-config"
git clone "$REPO_URL" "$src" git clone "$REPO_URL" "$src"
cd "$src" cd "$src"
git checkout "$SHA" || { git fetch origin "$REF" && git checkout "$SHA"; } git checkout "$SHA" || { git fetch origin "$REF" && git checkout "$SHA"; }
echo "Checked out $(git rev-parse HEAD)" echo "Checked out $(git rev-parse HEAD)"
# --no-global: renovate.json is a repository config, not the bot's global one.
# A step of its own, so the job token is not in the environment that reads renovate.json.
# --no-global: renovate.json is a repository config, not the bot's global one.
- name: Validate renovate.json
run: |
cd "${RUNNER_TEMP:-/tmp}/renovate-config"
renovate-config-validator --strict --no-global renovate.json renovate-config-validator --strict --no-global renovate.json
+5 -5
View File
@@ -25,8 +25,8 @@ When <head-ref> starts with `renovate/`, the diff of <base-ref>...HEAD may only
`job_image: ubuntu:...@sha256:...` lines (the name stays); CI assigns the image versions `job_image: ubuntu:...@sha256:...` lines (the name stays); CI assigns the image versions
and a human sets the matrix `base:`, so neither is the bot's to change; and a human sets the matrix `base:`, so neither is the bot's to change;
* .gitea/workflows/{lint,build,molecule,gitea-release-key}.yml: the version and digest of a * .gitea/workflows/{lint,build,molecule,gitea-release-key}.yml: the version and digest of a
`git.rkdr.net/mortis/<name>:<version>@sha256:<digest>` pin (the name stays), including `git.rkdr.net/mortis/<name>:<version>@sha256:<digest>` pin, in place (the name stays),
the MOLECULE_IMAGE value; including the MOLECULE_IMAGE value;
* .gitea/workflows/renovate.yml, and lint.yml's copy of it: the version and digest of the * .gitea/workflows/renovate.yml, and lint.yml's copy of it: the version and digest of the
`image: renovate/renovate:<version>-full@sha256:<digest>` line, in place; the name and the `image: renovate/renovate:<version>-full@sha256:<digest>` line, in place; the name and the
`-full` flavour stay (the job's report check needs the python3 that only -full ships). `-full` flavour stay (the job's report check needs the python3 that only -full ships).
@@ -295,8 +295,8 @@ def parse_patch(text):
def moved_problem(removed, added): def moved_problem(removed, added):
"""A reason when a changed line changes position, else None; both lists are (line number, line). """A reason when a changed line changes position, else None; both lists are (line number, line).
A `job_image:` pin moved to another matrix entry, or the Renovate image line moved out of its A `job_image:` pin moved to another matrix entry, or a workflow's image line moved to another
`container:`, would change which job runs on it.""" job, would change which job runs on it."""
if [n for n, unused in removed] != [n for n, unused in added]: if [n for n, unused in removed] != [n for n, unused in added]:
return "moves or deletes a line (the changed lines must stay where they are)" return "moves or deletes a line (the changed lines must stay where they are)"
return None return None
@@ -347,7 +347,7 @@ def check(entries, patch_of, show=None):
[line for unused, line in removed], [line for unused, line in removed],
[line for unused, line in added], [line for unused, line in added],
) )
if not reason and path in (civ.MATRIX_FILE, RENOVATE_WORKFLOW): if not reason and (path == civ.MATRIX_FILE or path in WORKFLOW_PINS):
reason = moved_problem(removed, added) reason = moved_problem(removed, added)
if reason: if reason:
problems.append(f"{path}: {reason}") problems.append(f"{path}: {reason}")
+20 -5
View File
@@ -367,6 +367,7 @@ class RuleTest(unittest.TestCase):
RENOVATE_NEW.replace(f"@{D2}", ""), RENOVATE_NEW.replace(f"@{D2}", ""),
RENOVATE_NEW.replace("44.170.2", "latest"), RENOVATE_NEW.replace("44.170.2", "latest"),
RENOVATE_NEW + " # evil", RENOVATE_NEW + " # evil",
RENOVATE_NEW.replace(" image:", " image:"),
): ):
self.assertIsNotNone(self.problem(path, RENOVATE_OLD, new), (path, new)) self.assertIsNotNone(self.problem(path, RENOVATE_OLD, new), (path, new))
@@ -627,16 +628,30 @@ class RepoTest(unittest.TestCase):
self.assertEqual(code, 0, err) self.assertEqual(code, 0, err)
self.assertIn("2 file(s)", out) self.assertIn("2 file(s)", out)
def test_a_moved_renovate_image_line_is_refused(self): def test_an_added_renovate_image_line_is_refused(self):
path = ".gitea/workflows/renovate.yml" for path in (".gitea/workflows/renovate.yml", ".gitea/workflows/lint.yml"):
self.assertIsNotNone(cbd.file_problem(path, [], [RENOVATE_NEW]), path)
self.assertIsNotNone(
cbd.file_problem(path, [RENOVATE_OLD], [RENOVATE_NEW, RENOVATE_NEW]),
path,
)
def assert_moved_line_refused(self, path, anchor):
self.edit(path, f"{RENOVATE_OLD}\n", "") self.edit(path, f"{RENOVATE_OLD}\n", "")
self.edit( self.edit(path, anchor, f"{anchor}{RENOVATE_NEW}\n")
path, " run: renovate\n", f" run: renovate\n{RENOVATE_NEW}\n"
)
self.commit("bot") self.commit("bot")
code, _unused, err = self.gate() code, _unused, err = self.gate()
self.assertEqual(code, 1, err) self.assertEqual(code, 1, err)
self.assertIn(path, err) self.assertIn(path, err)
self.assertIn("moves or deletes a line", err)
def test_a_moved_renovate_image_line_is_refused(self):
self.assert_moved_line_refused(
".gitea/workflows/renovate.yml", " run: renovate\n"
)
def test_a_moved_image_line_in_lint_yml_is_refused(self):
self.assert_moved_line_refused(".gitea/workflows/lint.yml", "run: echo a\n")
def bump_apm_cli(self): def bump_apm_cli(self):
"""The change Renovate makes for apm-cli 0.39.4, as uv 0.13.1 writes it.""" """The change Renovate makes for apm-cli 0.39.4, as uv 0.13.1 writes it."""