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
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:
commit
d30e32e49f
6 files changed
+50
-46
No files matched your search
+24
-40
@@ -22,12 +22,12 @@ name: Images
|
|||||||
# same Ubuntu release as the FROM lines of the image's Dockerfile (check_image_versions.py
|
# 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
|
# pins enforces it; run 2529 broke a 24.04 build in a 26.04 job container: GLIBC_2.42
|
||||||
# not found).
|
# not found).
|
||||||
# - Credentials: the job token is tried first (permissions: packages: write). Gitea 28
|
# - Credentials: the push uses the org secrets PACKAGE_PUSH_USER / PACKAGE_PUSH_TOKEN only.
|
||||||
# refuses it for an organisation-owned package (HTTP 401 on a write probe, run 2237:
|
# The job token cannot write an organisation-owned package on Gitea 28 (HTTP 401 on a
|
||||||
# the Actions user is not an org member, services/context/package.go, TODO ActionUser
|
# write probe: the Actions user is not an org member), so the workflow asks for no
|
||||||
# permission check). Only if a write probe is refused are the org secrets
|
# packages permission. One write probe checks the token before anything is built and
|
||||||
# PACKAGE_PUSH_USER / PACKAGE_PUSH_TOKEN used. The log names the method that worked,
|
# fails the job when it is refused. Revisit when a Gitea release lets the job token
|
||||||
# never a value.
|
# write organisation packages.
|
||||||
# - Layers: every layer stays far below Cloudflare's 100 MB request-body limit (see the
|
# - 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
|
# Dockerfile). No kaniko cache: a tiny, rarely rebuilt image gains little, and cache
|
||||||
# layers would be pushed through the same Cloudflare-limited path.
|
# layers would be pushed through the same Cloudflare-limited path.
|
||||||
@@ -48,7 +48,6 @@ on: # yamllint disable-line rule:truthy
|
|||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
|
||||||
|
|
||||||
# One image build at a time; a later run must not cancel a push in progress.
|
# One image build at a time; a later run must not cancel a push in progress.
|
||||||
concurrency:
|
concurrency:
|
||||||
@@ -88,7 +87,7 @@ jobs:
|
|||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||||
- name: ci
|
- name: ci
|
||||||
version: 0.2.31
|
version: 0.2.32
|
||||||
subpath: ""
|
subpath: ""
|
||||||
dockerfile: images/ci/Dockerfile
|
dockerfile: images/ci/Dockerfile
|
||||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
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
|
# Its CA bundle (layers[1]) and executor (layers[9], both 0-based) are fetched by content digest and
|
||||||
# verified with sha256sum.
|
# verified with sha256sum.
|
||||||
#
|
#
|
||||||
# The credential: the job token first; the org secrets only after a write probe was
|
# The credential: the org push token, checked by one write probe before the build.
|
||||||
# refused. Credentials reach commands only through the environment and curl's stdin
|
# Credentials reach commands only through the environment and curl's stdin
|
||||||
# config, never the argument list or the log. Writes /kaniko/.docker/config.json.
|
# 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:
|
env:
|
||||||
KANIKO_CA_LAYER_SHA256: 5ecab5922e6a5124fab96e8cb404b8cf93e8a96716af4fbbea2a9221b1216f86
|
KANIKO_CA_LAYER_SHA256: 5ecab5922e6a5124fab96e8cb404b8cf93e8a96716af4fbbea2a9221b1216f86
|
||||||
KANIKO_EXECUTOR_LAYER_SHA256: 49c71aa9e7197af5dcf12811395f182f831c7e714ba94241908c955dd1649ca7
|
KANIKO_EXECUTOR_LAYER_SHA256: 49c71aa9e7197af5dcf12811395f182f831c7e714ba94241908c955dd1649ca7
|
||||||
JOB_USER: ${{ github.actor }}
|
|
||||||
JOB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
PAT_USER: ${{ secrets.PACKAGE_PUSH_USER }}
|
PAT_USER: ${{ secrets.PACKAGE_PUSH_USER }}
|
||||||
PAT_TOKEN: ${{ secrets.PACKAGE_PUSH_TOKEN }}
|
PAT_TOKEN: ${{ secrets.PACKAGE_PUSH_TOKEN }}
|
||||||
SERVER_URL: ${{ github.server_url }}
|
SERVER_URL: ${{ github.server_url }}
|
||||||
@@ -196,33 +193,20 @@ jobs:
|
|||||||
(umask 077; printf '{"auths":{"%s":{"auth":"%s"}}}\n' "$registry" "$auth" > /kaniko/.docker/config.json)
|
(umask 077; printf '{"auths":{"%s":{"auth":"%s"}}}\n' "$registry" "$auth" > /kaniko/.docker/config.json)
|
||||||
}
|
}
|
||||||
|
|
||||||
code="$(probe "$JOB_USER" "$JOB_TOKEN")"
|
if [ -z "$PAT_USER" ] || [ -z "$PAT_TOKEN" ]; then
|
||||||
if [ "$code" = "202" ]; then
|
echo "::error::The org Actions secrets PACKAGE_PUSH_USER and PACKAGE_PUSH_TOKEN are not set." \
|
||||||
write_config "$JOB_USER" "$JOB_TOKEN"
|
"Create a bot user with write access to the mortis packages and a personal access token" \
|
||||||
method="job-token"
|
"with the write:package scope, and store them as those two org secrets."
|
||||||
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."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$method" > /kaniko/credential-method
|
code="$(probe "$PAT_USER" "$PAT_TOKEN")"
|
||||||
echo "Registry credential in use: $method"
|
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
|
# 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).
|
# 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
|
if [ -n "$SUBPATH" ]; then ctx+=(--context-sub-path "$SUBPATH"); fi
|
||||||
#
|
#
|
||||||
# When it finishes the executor has replaced the job container's filesystem with
|
# 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 built image and removed /kaniko, so nothing written there (a --digest-file)
|
||||||
# the credential method) can be read back. Take the digest from its
|
# can be read back. Take the digest from its
|
||||||
# "Pushed <image>@sha256:<digest>" log line into a variable of this shell, which
|
# "Pushed <image>@sha256:<digest>" log line into a variable of this shell, which
|
||||||
# needs only builtins by then.
|
# needs only builtins by then.
|
||||||
digest=""
|
digest=""
|
||||||
|
|||||||
@@ -63,6 +63,18 @@ repos:
|
|||||||
files: ^\.gitea/workflows/.*\.ya?ml$
|
files: ^\.gitea/workflows/.*\.ya?ml$
|
||||||
stages: ['pre-commit']
|
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
|
# 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
|
# 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
|
# CI and locally. ansible-lint is the slowest hook, so fail_fast stops the run
|
||||||
|
|||||||
+1
-2
@@ -72,8 +72,7 @@ outside contributions:
|
|||||||
- Protect `main`: pull request required, with the `Lint` and `Build` checks. Molecule has no path filter
|
- 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
|
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.
|
check as well; that is the operator's decision.
|
||||||
- The image workflow (`.gitea/workflows/image.yml`) tries the Actions job token first;
|
- The image workflow (`.gitea/workflows/image.yml`) pushes with the organisation secrets
|
||||||
Gitea 28 refuses it for an organisation's packages, so it pushes with the organisation secrets
|
|
||||||
`PACKAGE_PUSH_USER` and `PACKAGE_PUSH_TOKEN` (a bot user with write access to the
|
`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
|
organisation's packages and a token with only the `write:package` scope). Keep
|
||||||
those the only credentials stored at organisation level.
|
those the only credentials stored at organisation level.
|
||||||
+1
-1
@@ -13,7 +13,7 @@ Ubuntu 26.04 with:
|
|||||||
`requirements.yml`: `community.general` and `ansible.posix` at the exact versions CI tests against, so
|
`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.
|
`ansible-lint --offline` resolves their modules instead of mocking them.
|
||||||
- **Every pre-commit hook environment** of `.pre-commit-config.yaml` in `/opt/pre-commit`
|
- **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
|
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`,
|
keep layers small. The local hooks (`reuse-lint`,
|
||||||
`antsibull-changelog-lint`, `ansible-lint`) are `language: system`: they run from `/opt/venv`, which is why
|
`antsibull-changelog-lint`, `ansible-lint`) are `language: system`: they run from `/opt/venv`, which is why
|
||||||
|
|||||||
@@ -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
|
# 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
|
# 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
|
# 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
|
# 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
|
# 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 -- 'print("ok")\n' > ok.py; \
|
||||||
printf -- '#!/bin/sh\necho ok\n' > ok.sh; \
|
printf -- '#!/bin/sh\necho ok\n' > ok.sh; \
|
||||||
printf -- '---\nself-hosted-runner:\n labels:\n - kamino-docker\n' > .gitea/actionlint.yaml; \
|
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; \
|
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; \
|
smoke; \
|
||||||
rm -rf /opt/pre-commit/repo*/golangenv-*/.go /root/.cache/go-build; \
|
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 \
|
find /opt/pre-commit/repo*/golangenv-*/bin -mindepth 1 -maxdepth 1 -type f \
|
||||||
|
|||||||
@@ -319,6 +319,14 @@ class RuleTest(unittest.TestCase):
|
|||||||
cbd.file_problem(".pre-commit-config.yaml", [" rev: a"], [])
|
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):
|
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"
|
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"]))
|
self.assertEqual(cbd.parse_patch(patch), (["-- x"], ["++ y"]))
|
||||||
|
|||||||
Reference in new issue
Block a user