Merge pull request 'ci: lint workflows with zizmor' (#279) from ci/zizmor into main
Build / build (push) Successful in 12s
Images / image (Dockerfile, ubuntu:24.04@sha256:73b999393d07f2bf65a40373778a44dc9a6d54ad7718d29247d8ff9413c4d6a8, molecule-ubuntu2404, images/molecule-ubuntu2404, 0.1.8) (push) Successful in 9s
Lint / lint (push) Successful in 52s
Images / image (Dockerfile, ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db, molecule-ubuntu2604, images/molecule-ubuntu2604, 0.1.5) (push) Successful in 10s
Images / image (images/ci/Dockerfile, ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db, ci, , 0.2.32) (push) Successful in 4m38s

Reviewed-on: #279
Reviewed-by: Defame1297 <[email protected]>
This commit was merged in pull request #279.
This commit is contained in:
Defame1297 committed 2026-11-21 18:58:07 +00:00
commit d30e32e49f
6 files changed
+50 -46

No files matched your search

+24 -40
View File
@@ -22,12 +22,12 @@ name: Images
# same Ubuntu release as the FROM lines of the image's Dockerfile (check_image_versions.py
# pins enforces it; run 2529 broke a 24.04 build in a 26.04 job container: GLIBC_2.42
# not found).
# - Credentials: the job token is tried first (permissions: packages: write). Gitea 28
# refuses it for an organisation-owned package (HTTP 401 on a write probe, run 2237:
# the Actions user is not an org member, services/context/package.go, TODO ActionUser
# permission check). Only if a write probe is refused are the org secrets
# PACKAGE_PUSH_USER / PACKAGE_PUSH_TOKEN used. The log names the method that worked,
# never a value.
# - Credentials: the push uses the org secrets PACKAGE_PUSH_USER / PACKAGE_PUSH_TOKEN only.
# The job token cannot write an organisation-owned package on Gitea 28 (HTTP 401 on a
# write probe: the Actions user is not an org member), so the workflow asks for no
# packages permission. One write probe checks the token before anything is built and
# fails the job when it is refused. Revisit when a Gitea release lets the job token
# write organisation packages.
# - Layers: every layer stays far below Cloudflare's 100 MB request-body limit (see the
# Dockerfile). No kaniko cache: a tiny, rarely rebuilt image gains little, and cache
# layers would be pushed through the same Cloudflare-limited path.
@@ -48,7 +48,6 @@ on: # yamllint disable-line rule:truthy
permissions:
contents: read
packages: write
# One image build at a time; a later run must not cancel a push in progress.
concurrency:
@@ -88,7 +87,7 @@ jobs:
dockerfile: Dockerfile
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
- name: ci
version: 0.2.31
version: 0.2.32
subpath: ""
dockerfile: images/ci/Dockerfile
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
@@ -133,15 +132,13 @@ jobs:
# Its CA bundle (layers[1]) and executor (layers[9], both 0-based) are fetched by content digest and
# verified with sha256sum.
#
# The credential: the job token first; the org secrets only after a write probe was
# refused. Credentials reach commands only through the environment and curl's stdin
# The credential: the org push token, checked by one write probe before the build.
# Credentials reach commands only through the environment and curl's stdin
# config, never the argument list or the log. Writes /kaniko/.docker/config.json.
- name: Prepare kaniko and select the registry credential
- name: Prepare kaniko and check the registry credential
env:
KANIKO_CA_LAYER_SHA256: 5ecab5922e6a5124fab96e8cb404b8cf93e8a96716af4fbbea2a9221b1216f86
KANIKO_EXECUTOR_LAYER_SHA256: 49c71aa9e7197af5dcf12811395f182f831c7e714ba94241908c955dd1649ca7
JOB_USER: ${{ github.actor }}
JOB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PAT_USER: ${{ secrets.PACKAGE_PUSH_USER }}
PAT_TOKEN: ${{ secrets.PACKAGE_PUSH_TOKEN }}
SERVER_URL: ${{ github.server_url }}
@@ -196,33 +193,20 @@ jobs:
(umask 077; printf '{"auths":{"%s":{"auth":"%s"}}}\n' "$registry" "$auth" > /kaniko/.docker/config.json)
}
code="$(probe "$JOB_USER" "$JOB_TOKEN")"
if [ "$code" = "202" ]; then
write_config "$JOB_USER" "$JOB_TOKEN"
method="job-token"
elif [ "$code" = "401" ] || [ "$code" = "403" ]; then
echo "The Actions job token was refused for a package write (HTTP $code)."
if [ -z "$PAT_USER" ] || [ -z "$PAT_TOKEN" ]; then
echo "::error::The job token cannot push to the organisation's packages, and the org Actions" \
"secrets PACKAGE_PUSH_USER and PACKAGE_PUSH_TOKEN are not set. Create a bot user with write" \
"access to the mortis packages and a personal access token with the write:package scope," \
"and store them as those two org secrets."
exit 1
fi
code="$(probe "$PAT_USER" "$PAT_TOKEN")"
if [ "$code" != "202" ]; then
echo "::error::The PACKAGE_PUSH_USER / PACKAGE_PUSH_TOKEN credential was refused too" \
"(HTTP $code). Check the token's write:package scope and the bot user's access to the org."
exit 1
fi
write_config "$PAT_USER" "$PAT_TOKEN"
method="org-secrets (PACKAGE_PUSH_USER / PACKAGE_PUSH_TOKEN)"
else
echo "::error::Unexpected HTTP status $code from the registry write probe; not trying another credential."
if [ -z "$PAT_USER" ] || [ -z "$PAT_TOKEN" ]; then
echo "::error::The org Actions secrets PACKAGE_PUSH_USER and PACKAGE_PUSH_TOKEN are not set." \
"Create a bot user with write access to the mortis packages and a personal access token" \
"with the write:package scope, and store them as those two org secrets."
exit 1
fi
echo "$method" > /kaniko/credential-method
echo "Registry credential in use: $method"
code="$(probe "$PAT_USER" "$PAT_TOKEN")"
if [ "$code" != "202" ]; then
echo "::error::The PACKAGE_PUSH_USER / PACKAGE_PUSH_TOKEN credential was refused (HTTP $code)." \
"Check the token's write:package scope and the bot user's access to the org."
exit 1
fi
write_config "$PAT_USER" "$PAT_TOKEN"
echo "Registry credential accepted: PACKAGE_PUSH_USER / PACKAGE_PUSH_TOKEN"
# Gitea cannot make a tag immutable, so look the version tag up first: when it
# exists the build must not move it (the build step reads this marker).
@@ -307,8 +291,8 @@ jobs:
if [ -n "$SUBPATH" ]; then ctx+=(--context-sub-path "$SUBPATH"); fi
#
# When it finishes the executor has replaced the job container's filesystem with
# the built image and removed /kaniko, so nothing written there (a --digest-file,
# the credential method) can be read back. Take the digest from its
# the built image and removed /kaniko, so nothing written there (a --digest-file)
# can be read back. Take the digest from its
# "Pushed <image>@sha256:<digest>" log line into a variable of this shell, which
# needs only builtins by then.
digest=""
+12
View File
@@ -63,6 +63,18 @@ repos:
files: ^\.gitea/workflows/.*\.ya?ml$
stages: ['pre-commit']
# zizmor finds security problems in workflows (pull_request_target, ${{ }} expanded into
# run:). Its own files: pattern only matches .github/, so point it at .gitea/workflows.
# --offline: no network audits, so a run needs no token and gives the same result everywhere.
# Overriding args drops the hook's default, so --no-progress is repeated here.
- repo: https://github.com/zizmorcore/zizmor-pre-commit
rev: 06a39750ec31860bb44f2acf67182c40016cd1e7 # frozen: v1.32.0
hooks:
- id: zizmor
args: [--no-progress, --offline]
files: ^\.gitea/workflows/[^/]+\.ya?ml$
stages: ['pre-commit']
# ansible-lint and the changelog lint run from PATH (language: system): their
# versions are the pins in requirements-dev.txt, installed into a virtualenv by
# CI and locally. ansible-lint is the slowest hook, so fail_fast stops the run
+1 -2
View File
@@ -72,8 +72,7 @@ outside contributions:
- Protect `main`: pull request required, with the `Lint` and `Build` checks. Molecule has no path filter
on pull requests (the job always starts and chooses its scenarios itself), so it can be made a required
check as well; that is the operator's decision.
- The image workflow (`.gitea/workflows/image.yml`) tries the Actions job token first;
Gitea 28 refuses it for an organisation's packages, so it pushes with the organisation secrets
- The image workflow (`.gitea/workflows/image.yml`) pushes with the organisation secrets
`PACKAGE_PUSH_USER` and `PACKAGE_PUSH_TOKEN` (a bot user with write access to the
organisation's packages and a token with only the `write:package` scope). Keep
those the only credentials stored at organisation level.
+1 -1
View File
@@ -13,7 +13,7 @@ Ubuntu 26.04 with:
`requirements.yml`: `community.general` and `ansible.posix` at the exact versions CI tests against, so
`ansible-lint --offline` resolves their modules instead of mocking them.
- **Every pre-commit hook environment** of `.pre-commit-config.yaml` in `/opt/pre-commit`
(`PRE_COMMIT_HOME`): conventional-pre-commit, gitleaks, yamllint, ruff, shellcheck-py, pre-commit-hooks and actionlint. The Go
(`PRE_COMMIT_HOME`): conventional-pre-commit, gitleaks, yamllint, ruff, shellcheck-py, pre-commit-hooks, actionlint and zizmor. The Go
hooks are prebuilt; their toolchains, and the binaries of those repositories that no hook runs, are removed to
keep layers small. The local hooks (`reuse-lint`,
`antsibull-changelog-lint`, `ansible-lint`) are `language: system`: they run from `/opt/venv`, which is why
+4 -3
View File
@@ -118,7 +118,8 @@ RUN ANSIBLE_COLLECTIONS_PATH=/opt/collections \
# environments fit: with them the layer was about 103 MB compressed and the push of
# ci 0.2.16 got a 413. The hooks below run on a staged sample before and after the
# deletion: a cache that is incomplete (a missing environment would be rebuilt, which
# needs the network) or no longer works fails the image build, not the jobs.
# needs the network) or no longer works fails the image build, not the jobs. The sample
# workflow sets `permissions: {}` because zizmor flags a workflow that leaves them default.
#
# The last lines print the compressed size of each directory a later COPY turns into a
# layer, which is what the 100 MB (95 MiB) limit applies to. These gzip -6 figures run
@@ -135,9 +136,9 @@ RUN set -eu; \
printf -- 'print("ok")\n' > ok.py; \
printf -- '#!/bin/sh\necho ok\n' > ok.sh; \
printf -- '---\nself-hosted-runner:\n labels:\n - kamino-docker\n' > .gitea/actionlint.yaml; \
printf -- '---\n"on": push\njobs:\n t:\n runs-on: kamino-docker\n steps:\n - run: echo ok\n' > .gitea/workflows/t.yml; \
printf -- '---\n"on": push\npermissions: {}\njobs:\n t:\n runs-on: kamino-docker\n steps:\n - run: echo ok\n' > .gitea/workflows/t.yml; \
git add ok.yaml ok.py ok.sh .gitea/actionlint.yaml .gitea/workflows/t.yml; \
smoke() { for h in yamllint gitleaks actionlint ruff-check ruff-format shellcheck; do /opt/venv/bin/pre-commit run "$h" --all-files; done; }; \
smoke() { for h in yamllint gitleaks actionlint zizmor ruff-check ruff-format shellcheck; do /opt/venv/bin/pre-commit run "$h" --all-files; done; }; \
smoke; \
rm -rf /opt/pre-commit/repo*/golangenv-*/.go /root/.cache/go-build; \
find /opt/pre-commit/repo*/golangenv-*/bin -mindepth 1 -maxdepth 1 -type f \
+8
View File
@@ -319,6 +319,14 @@ class RuleTest(unittest.TestCase):
cbd.file_problem(".pre-commit-config.yaml", [" rev: a"], [])
)
def test_a_bump_of_the_real_zizmor_rev_line_is_allowed(self):
# The line as Renovate's git-tags lookup finds it in this repository's config.
config = (SCRIPTS.parent / ".pre-commit-config.yaml").read_text().splitlines()
repo = config.index(" - repo: https://github.com/zizmorcore/zizmor-pre-commit")
rev = config[repo + 1]
bumped = f" rev: {'f' * 40} # frozen: v99.0.0"
self.assertIsNone(cbd.file_problem(".pre-commit-config.yaml", [rev], [bumped]))
def test_patch_parser_keeps_dashed_content(self):
patch = "diff --git a/f b/f\n--- a/f\n+++ b/f\n@@ -1 +1 @@\n--- x\n+++ y\n\\ No newline at end of file\n"
self.assertEqual(cbd.parse_patch(patch), (["-- x"], ["++ y"]))