Compare commits
37
Commits
62ef930bee
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1db4fb0db | ||
|
|
5a130f143f | ||
|
|
cce3e54e7f | ||
|
|
33f4ee960e | ||
|
|
6d054b0f8b | ||
|
|
9dba48a30d | ||
|
|
2b0326801f | ||
|
|
1e95d8cbdd | ||
|
|
47641ae01d | ||
|
|
c617bee02a | ||
|
|
f7da80b326 | ||
|
|
1029d8ecce | ||
|
|
535926b36e | ||
|
|
595f517b49 | ||
|
|
d732ac0a71 | ||
|
|
f62097a748 | ||
|
|
b7b763e1fa | ||
|
|
1dfdaf48ec | ||
|
|
3d7b66072e | ||
|
|
83f4cc2c5b | ||
|
|
eaece480c8 | ||
|
|
191431a8e4 | ||
|
|
2158233241 | ||
|
|
74e574ee80 | ||
|
|
d88e5d237a | ||
|
|
e7eae3b219 | ||
|
|
cf99893855 | ||
|
|
508ed5ce12 | ||
|
|
9127ac565a | ||
|
|
e446e1e09a | ||
|
|
2f5a997dd7 | ||
|
|
22f5bc33e9 | ||
|
|
a48cd063ea | ||
|
|
6fee0ea8b2 | ||
|
|
39ec8e5b3c | ||
|
|
3414880d05 | ||
|
|
08c589e910 |
No files matched your search
@@ -6,6 +6,7 @@ profile: production
|
||||
exclude_paths:
|
||||
- .gitea
|
||||
- .venv
|
||||
- .venv-dev
|
||||
- apm_modules
|
||||
- apm.lock.yaml
|
||||
- changelogs
|
||||
|
||||
@@ -39,11 +39,14 @@ issue.
|
||||
while a content check must see the content it is given. *Held:* review (`CODEOWNERS`).
|
||||
- **A pull request from a `renovate/` branch changes only version, tag, digest and pin lines**
|
||||
(tool pins with their lock entries and hashes, hook `rev:` lines, Dockerfile `FROM` tags and
|
||||
digests, `job_image:` pins, consumer image pins).
|
||||
digests, `job_image:` pins, consumer image pins). In `pyproject.toml` only a pin's version
|
||||
moves; in `uv.lock` only apm-cli moves, to that pin, with its files from PyPI by sha256, and
|
||||
every other package stays as it is.
|
||||
*Why:* the bot's minor and patch pull requests automerge, so they must not be able to change
|
||||
anything else. *Held:* control: the Lint check's "Check a bot pull request only moves pins"
|
||||
step, `scripts/check_bot_pr_diff.py` run from `main`'s copy. The branch name is chosen by the
|
||||
pusher, so this constrains only the bot's own pull requests.
|
||||
anything else; uv installs whatever `uv.lock` names, so it is parsed, not read line by line.
|
||||
*Held:* control: the Lint check's "Check a bot pull request only moves pins" step,
|
||||
`scripts/check_bot_pr_diff.py` with `scripts/check_uv_lock.py`, run from `main`'s copy. The
|
||||
branch name is chosen by the pusher, so this constrains only the bot's own pull requests.
|
||||
- **Workflows never mention the image namespace this repository's CI must not use** (the string
|
||||
is in `scripts/check_image_versions.py`). *Why:* this repository's images are built and pulled
|
||||
only under its own organisation's namespace. *Held:* control: the Lint check's "Check image
|
||||
@@ -53,8 +56,8 @@ issue.
|
||||
|
||||
- **Lint and Build run in the pinned `ci` image and compare the pin files with the checksums
|
||||
baked into it (`/opt/ci-pins.sha256`).** A pull request that changes `requirements-dev.txt`,
|
||||
`requirements-dev.lock`, `requirements.yml`, `extensions/molecule/requirements.yml` or
|
||||
`.pre-commit-config.yaml` takes the slow path, which installs the pinned tools and collections.
|
||||
`requirements-dev.lock`, `requirements.yml` or `.pre-commit-config.yaml` takes the slow path,
|
||||
which installs the pinned tools and collections.
|
||||
*Why:* a pull request is tested on its own pins, and an unchanged one starts in seconds.
|
||||
*Held:* control: the "Check the baked tooling against the pins" step.
|
||||
- **On the fast path the network is cut by environment**: `PIP_NO_INDEX=1`, the proxy variables
|
||||
@@ -109,7 +112,7 @@ issue.
|
||||
(release versions, `build_ignore`) do not change what a scenario runs, and the Build check
|
||||
proves the collection builds; they had caused about a third of full pull request runs and their
|
||||
minutes (#338). *Held:* control: `scripts/check_scenarios_load_checkout.py`, which
|
||||
`run_molecule_in_ci_image.sh` runs on the selected scenarios before they start, fails the run
|
||||
`run_molecule_in_controller.sh` runs on the selected scenarios before they start, fails the run
|
||||
when the environment molecule gives `ansible-playbook` resolves `mortis.kamino` anywhere else,
|
||||
or when `prerun` is not off once the base config is merged as molecule's CLI merges it (a
|
||||
scenario turns it on, or the base config is moved or turns it on).
|
||||
@@ -148,7 +151,7 @@ issue.
|
||||
`requirements-molecule.lock` selects every scenario; `requirements-dev.*` pins only Lint's tools
|
||||
and selects none. *Why:* a pull request that bumps ansible-core or molecule must run its
|
||||
scenarios on them before it automerges. *Held:* control: the pin comparison in
|
||||
`run_molecule_in_ci_image.sh`, and the selector's tests for which pin files select what.
|
||||
`run_molecule_in_controller.sh`, and the selector's tests for which pin files select what.
|
||||
- **Every scenario sets `scenario.test_sequence` to molecule's default minus both `destroy`
|
||||
steps, with a role scenario's `check` right before and right after `converge`, names each
|
||||
platform `${KAMINO_RUN_ID:-local}-<name>` and labels it
|
||||
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
timeout-minutes: 30
|
||||
# The ci image (images/ci, built by image.yml): tag for the release, digest enforced.
|
||||
container:
|
||||
image: git.rkdr.net/mortis/ci:0.2.51@sha256:376e6319e1304f9fa9da1142e7884e39def496a1467528ccb4fe2d04017822db
|
||||
image: git.rkdr.net/mortis/ci:0.2.54@sha256:2742be4ba03f71f00b06f1d2b318e8fd3866a800247bbd7e52508dfb0da6312c
|
||||
env:
|
||||
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
||||
steps:
|
||||
@@ -66,8 +66,8 @@ jobs:
|
||||
HTTP_PROXY=http://127.0.0.1:9 HTTPS_PROXY=http://127.0.0.1:9 no_proxy= NO_PROXY= >> "$GITHUB_ENV"
|
||||
echo "::notice::Later steps run with a dead proxy; a download fails the job (bake it into images/ci)."
|
||||
else
|
||||
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml," \
|
||||
"extensions/molecule/requirements.yml or .pre-commit-config.yaml differ from the ci image;" \
|
||||
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml" \
|
||||
"or .pre-commit-config.yaml differ from the ci image;" \
|
||||
"installing the pinned tools for this run."
|
||||
/opt/venv/bin/pip install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.txt
|
||||
fi
|
||||
@@ -94,13 +94,13 @@ jobs:
|
||||
# ansible-galaxy dereferences symlinks when it builds, so a symlink in the source tree
|
||||
# reaches the archive as a regular file with the target's content, where
|
||||
# scripts/check_tarball.py cannot see it. Refuse them in the tree instead: this step
|
||||
# is the only guard against a file symlink. The two -prune paths below (./.venv,
|
||||
# ./.git) are skipped only because the build skips them too (galaxy.yml build_ignore,
|
||||
# is the only guard against a file symlink. The -prune paths below (./.git, ./.venv,
|
||||
# ./.venv-dev) are skipped only because the build skips them too (galaxy.yml build_ignore,
|
||||
# and ansible-galaxy's own .git exclusion): the two lists must stay in step, and
|
||||
# tests/scripts/test_check_tarball.py fails when a pruned directory is not ignored.
|
||||
- name: Refuse symlinks in the source tree
|
||||
run: |
|
||||
links="$(find . -path ./.git -prune -o -path ./.venv -prune -o -type l -print)"
|
||||
links="$(find . -path ./.git -prune -o -path ./.venv -prune -o -path ./.venv-dev -prune -o -type l -print)"
|
||||
if [ -n "$links" ]; then
|
||||
echo "::error::symlinks in the source tree would be dereferenced into the Collection archive:"
|
||||
echo "$links"
|
||||
|
||||
@@ -44,7 +44,7 @@ jobs:
|
||||
# The ci image (images/ci, built by image.yml), at the pin of lint.yml: tag for the
|
||||
# release, digest enforced. Only its /opt/venv Python (with PyYAML) is used here.
|
||||
container:
|
||||
image: git.rkdr.net/mortis/ci:0.2.51@sha256:376e6319e1304f9fa9da1142e7884e39def496a1467528ccb4fe2d04017822db
|
||||
image: git.rkdr.net/mortis/ci:0.2.54@sha256:2742be4ba03f71f00b06f1d2b318e8fd3866a800247bbd7e52508dfb0da6312c
|
||||
steps:
|
||||
# The container has no Node, so JavaScript actions such as actions/checkout
|
||||
# cannot run; clone with git and the job token.
|
||||
|
||||
+30
-32
@@ -39,15 +39,15 @@ on: # yamllint disable-line rule:truthy
|
||||
- main
|
||||
paths:
|
||||
- 'images/**'
|
||||
# The ci image bakes these files' contents in (images/ci/Dockerfile).
|
||||
# The ci image bakes these files' contents in (images/ci/Dockerfile); requirements.yml too.
|
||||
- 'requirements-dev.txt'
|
||||
- 'requirements-dev.lock'
|
||||
- 'requirements.yml'
|
||||
- 'extensions/molecule/requirements.yml'
|
||||
- '.pre-commit-config.yaml'
|
||||
# The molecule-controller image bakes these (images/molecule-controller/Dockerfile).
|
||||
# The molecule-controller image bakes these, and requirements.yml (its Dockerfile).
|
||||
- 'requirements-molecule.txt'
|
||||
- 'requirements-molecule.lock'
|
||||
- 'extensions/molecule/requirements.yml'
|
||||
- '.gitea/workflows/image.yml'
|
||||
workflow_dispatch: {}
|
||||
|
||||
@@ -83,22 +83,22 @@ jobs:
|
||||
base: "0.1"
|
||||
subpath: images/molecule-ubuntu2404
|
||||
dockerfile: Dockerfile
|
||||
job_image: ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b
|
||||
job_image: ubuntu:24.04@sha256:168a88cc61bdd95c8f871e3903d4e0a525e340c2b28a70dadd6d1503ecc7c391
|
||||
- name: molecule-ubuntu2604
|
||||
base: "0.1"
|
||||
subpath: images/molecule-ubuntu2604
|
||||
dockerfile: Dockerfile
|
||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||
job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
|
||||
- name: ci
|
||||
base: "0.2"
|
||||
subpath: ""
|
||||
dockerfile: images/ci/Dockerfile
|
||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||
job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
|
||||
- name: molecule-controller
|
||||
base: "0.1"
|
||||
subpath: ""
|
||||
dockerfile: images/molecule-controller/Dockerfile
|
||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||
job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
|
||||
container:
|
||||
image: ${{ matrix.job_image }}
|
||||
# Keeps a runaway build from taking the whole runner down with it.
|
||||
@@ -107,21 +107,17 @@ jobs:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
IMAGE_PATH: mortis/${{ matrix.name }}
|
||||
steps:
|
||||
# One step, in this order, so the filesystem the build starts from is the pristine
|
||||
# base image. Kaniko unpacks the base image into the job container's own root
|
||||
# filesystem and snapshots from there, so anything installed in the job container
|
||||
# first (curl and its libraries) would count as "already present" and be missing
|
||||
# from the layers that install the same packages (ca-certificates, libkrb5 ...).
|
||||
# Kaniko unpacks the base image into the job container's own root filesystem and
|
||||
# snapshots from there, so anything left in it (curl and its libraries) would count
|
||||
# as "already present" and be missing from the layers that install the same packages.
|
||||
# The build's --pre-cleanup empties that filesystem first; this step also cleans up
|
||||
# after itself, so a leftover fails the job instead of relying on that flag alone.
|
||||
# The tools are therefore installed, used, and exactly the packages the install
|
||||
# added are purged (not `autoremove`, which would also drop base packages that
|
||||
# are marked auto-installed). The result is compared with what was recorded
|
||||
# before the install: the package names and versions must be identical, and any
|
||||
# file difference under /usr, /lib, /bin, /sbin, /opt or /etc fails the job.
|
||||
# Names only, no sizes or modes, and /var/log, /run and dpkg's *-old files are
|
||||
# not compared: logs and dpkg state the install touched may end up in the first
|
||||
# layer as modified files. That is cosmetic. Not yet checked: listing the layers
|
||||
# (crane export | tar t, looking for run/act, root/ and var/log/apt) needs a
|
||||
# read:package token, which the Claude token lacks.
|
||||
# are marked auto-installed). The package names must then equal those recorded before
|
||||
# the install, and a new file under /usr, /lib, /bin, /sbin, /opt or /etc that no
|
||||
# package owns fails the job. Versions may differ: the install upgrades a base package
|
||||
# when Ubuntu has a newer one, and the build starts from the base image's copy again.
|
||||
#
|
||||
# The pinned kaniko v1.28.6 image has index digest
|
||||
# sha256:2fa20b0a4b40c7db72b479d57e55c2cf79f2178533b2d3bcbd129d6bd3c087ed and
|
||||
@@ -163,7 +159,6 @@ jobs:
|
||||
snapshot > /kaniko/fs.before
|
||||
pkgs() { dpkg-query -W -f='${Package}:${Architecture}\n' | LC_ALL=C sort; }
|
||||
pkgs > /kaniko/pkgs.before
|
||||
dpkg-query -W -f='${Package}:${Architecture} ${Version}\n' | LC_ALL=C sort > /kaniko/pkgv.before
|
||||
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends ca-certificates curl python3
|
||||
@@ -173,7 +168,7 @@ jobs:
|
||||
printf 'header = "Authorization: token %s"\n' "$JOB_TOKEN" \
|
||||
| curl -fsSL -K - "${SERVER_URL}/api/v1/repos/${REPO}/archive/${SHA}.tar.gz" \
|
||||
| tar -xz -C /tmp/src --strip-components=1
|
||||
# -B: no bytecode left behind to break the pristine-filesystem check below.
|
||||
# -B: no bytecode left behind to break the leftover check below.
|
||||
env -u PAT_USER -u PAT_TOKEN -u JOB_TOKEN python3 -B -E -s \
|
||||
/tmp/src/scripts/next_image_version.py /tmp/src "$IMAGE_NAME" "$SERVER_URL" > /kaniko/image-version
|
||||
if [ -s /kaniko/image-version ]; then
|
||||
@@ -243,25 +238,24 @@ jobs:
|
||||
fi
|
||||
fi
|
||||
|
||||
# Back to the pristine base image (see above): purge exactly what the install
|
||||
# added, then compare packages (names and versions) and files with the record.
|
||||
# Purge exactly what the install added, then compare packages and files with the record (see above).
|
||||
pkgs > /kaniko/pkgs.installed
|
||||
comm -13 /kaniko/pkgs.before /kaniko/pkgs.installed | xargs apt-get purge -y
|
||||
apt-get clean
|
||||
rm -rf /var/lib/apt/lists/* /tmp/*
|
||||
dpkg-query -W -f='${Package}:${Architecture} ${Version}\n' | LC_ALL=C sort > /kaniko/pkgv.after
|
||||
if ! diff /kaniko/pkgv.before /kaniko/pkgv.after; then
|
||||
echo "::error::The installed packages differ from the pristine base image (listed above): the install" \
|
||||
"upgraded or left packages behind, so the build would start from a modified filesystem."
|
||||
pkgs > /kaniko/pkgs.after
|
||||
if ! diff /kaniko/pkgs.before /kaniko/pkgs.after; then
|
||||
echo "::error::The installed packages are not those of the base image (differences above)."
|
||||
exit 1
|
||||
fi
|
||||
snapshot > /kaniko/fs.after
|
||||
diff /kaniko/fs.before /kaniko/fs.after > /kaniko/fs.diff || true
|
||||
if grep -E '^[<>] /(usr|lib|bin|sbin|opt|etc)/' /kaniko/fs.diff; then
|
||||
echo "::error::The job container differs from the pristine base image (listed above); the build would produce wrong layers."
|
||||
comm -13 /kaniko/fs.before /kaniko/fs.after > /kaniko/fs.new
|
||||
# dpkg -S fails on a path no package owns; an upgraded base package may bring new files of its own.
|
||||
if ! sed -nE '\#^/(usr|lib|bin|sbin|opt|etc)/#p' /kaniko/fs.new | xargs -r -d '\n' dpkg -S > /dev/null; then
|
||||
echo "::error::The install left files behind that no package owns (listed above)."
|
||||
exit 1
|
||||
fi
|
||||
echo "Package and filesystem check passed ($(grep -c '^[<>]' /kaniko/fs.diff || true) unrelated file differences outside the checked directories)"
|
||||
echo "Package and filesystem check passed"
|
||||
|
||||
- name: Build and push with kaniko
|
||||
env:
|
||||
@@ -279,6 +273,9 @@ jobs:
|
||||
set +x
|
||||
set -eu
|
||||
export DOCKER_CONFIG=/kaniko/.docker
|
||||
# A build that fails right after --pre-cleanup leaves no rm for the last step, so empty the
|
||||
# credential file with a shell builtin.
|
||||
trap '{ : > "$DOCKER_CONFIG/config.json"; } 2> /dev/null || true' EXIT
|
||||
# The CA bundle from the kaniko image: the base image has none.
|
||||
export SSL_CERT_DIR=/kaniko/ssl/certs
|
||||
registry="${SERVER_URL#https://}"
|
||||
@@ -331,6 +328,7 @@ jobs:
|
||||
"${ctx[@]}" \
|
||||
"${dests[@]}" \
|
||||
"${labels[@]}" \
|
||||
--pre-cleanup \
|
||||
--snapshot-mode=redo \
|
||||
--cache=false \
|
||||
--push-retry 3 \
|
||||
|
||||
@@ -6,8 +6,8 @@ name: Lint
|
||||
# The tools come from the ci image (images/ci, built by image.yml): the pinned Python
|
||||
# tools of requirements-dev.txt, the collections of requirements.yml and the hook
|
||||
# environments of .pre-commit-config.yaml are baked in. When a PR changes one of those
|
||||
# files or extensions/molecule/requirements.yml the checksum check below fails and the
|
||||
# job installs the pinned tools and collections itself for this run (slower, same result).
|
||||
# files the checksum check below fails and the job installs the pinned tools and
|
||||
# collections itself for this run (slower, same result).
|
||||
on: # yamllint disable-line rule:truthy
|
||||
pull_request:
|
||||
branches:
|
||||
@@ -31,7 +31,7 @@ jobs:
|
||||
# The tag says which release, the digest is what is enforced (bump both together
|
||||
# when image.yml publishes a new version).
|
||||
container:
|
||||
image: git.rkdr.net/mortis/ci:0.2.51@sha256:376e6319e1304f9fa9da1142e7884e39def496a1467528ccb4fe2d04017822db
|
||||
image: git.rkdr.net/mortis/ci:0.2.54@sha256:2742be4ba03f71f00b06f1d2b318e8fd3866a800247bbd7e52508dfb0da6312c
|
||||
env:
|
||||
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
||||
PRE_COMMIT_HOME: /opt/pre-commit
|
||||
@@ -65,8 +65,8 @@ jobs:
|
||||
HTTP_PROXY=http://127.0.0.1:9 HTTPS_PROXY=http://127.0.0.1:9 no_proxy= NO_PROXY= >> "$GITHUB_ENV"
|
||||
echo "::notice::Later steps run with a dead proxy; a download fails the job (bake it into images/ci)."
|
||||
else
|
||||
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml," \
|
||||
"extensions/molecule/requirements.yml or .pre-commit-config.yaml differ from the ci image;" \
|
||||
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml" \
|
||||
"or .pre-commit-config.yaml differ from the ci image;" \
|
||||
"installing the pinned tools and collections for this run."
|
||||
/opt/venv/bin/pip install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.txt
|
||||
# --force: the baked copy of a changed pin is replaced, not kept as "already installed".
|
||||
|
||||
@@ -64,7 +64,7 @@ jobs:
|
||||
# The molecule-controller pin, as CONTROLLER_IMAGE below: a ci pin here would make every ci
|
||||
# bump select every scenario (ADR 0003).
|
||||
container:
|
||||
image: git.rkdr.net/mortis/molecule-controller:0.1.3@sha256:4fa8a653e7af673f8e9921068dd504700679cc5bdefbfd55369e9cbca3fa9b44
|
||||
image: git.rkdr.net/mortis/molecule-controller:0.1.4@sha256:5658231afaff531161f02aef7a436ed875b1ad6c8d55a8d144e9763c71244420
|
||||
outputs:
|
||||
scenarios: ${{ steps.select.outputs.scenarios }}
|
||||
steps:
|
||||
@@ -134,15 +134,15 @@ jobs:
|
||||
# The tools and collections molecule runs with, apart from Lint's (ADR 0003), so a tool
|
||||
# bump only Lint uses selects no scenario.
|
||||
CONTROLLER_IMAGE: >-
|
||||
git.rkdr.net/mortis/molecule-controller:0.1.3@sha256:4fa8a653e7af673f8e9921068dd504700679cc5bdefbfd55369e9cbca3fa9b44
|
||||
git.rkdr.net/mortis/molecule-controller:0.1.4@sha256:5658231afaff531161f02aef7a436ed875b1ad6c8d55a8d144e9763c71244420
|
||||
# Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run
|
||||
# one locally.
|
||||
MOLECULE_IMAGE: >-
|
||||
git.rkdr.net/mortis/molecule-ubuntu2404:0.1.12@sha256:5f96ae95e16e205cc433607bab31307b36633ad73468aa7bdc57f4bbddb1c571
|
||||
git.rkdr.net/mortis/molecule-ubuntu2404:0.1.13@sha256:536cc31bb5ef5d5912b50afa98dc080bdb583baa601027298ec5e90e5712e178
|
||||
# The same for Ubuntu 26.04, the release the hosts are moving to; used by
|
||||
# `image: ${MOLECULE_IMAGE_2604}` in extensions/molecule/image-smoke-2604.
|
||||
MOLECULE_IMAGE_2604: >-
|
||||
git.rkdr.net/mortis/molecule-ubuntu2604:0.1.8@sha256:96496c7fb35e6091d08b057e53ba603256d07483769f27c19582d336ddc11173
|
||||
git.rkdr.net/mortis/molecule-ubuntu2604:0.1.9@sha256:8a9e75ecd53c630e56f4df3a2ced990bfcbd49c247103297114a2b9f30f75d62
|
||||
# Names and labels this run's containers: the scenarios' as `${KAMINO_RUN_ID:-local}-<name>`
|
||||
# with the label net.rkdr.mortis.molecule-run, and the one molecule runs in.
|
||||
KAMINO_RUN_ID: ${{ github.run_id }}-${{ github.run_attempt }}
|
||||
@@ -220,7 +220,7 @@ jobs:
|
||||
-v "$ac_root:$ac_root" -v "$ac_root/passwd:/etc/passwd:ro" -w "$PWD" \
|
||||
-e "AC_ROOT=$ac_root" -e "HOME=$ac_root/home" -e "USER=$(id -un)" \
|
||||
-e MOLECULE_IMAGE -e MOLECULE_IMAGE_2604 -e KAMINO_RUN_ID -e MOLECULE_LANES \
|
||||
"$CONTROLLER_IMAGE" scripts/run_molecule_in_ci_image.sh <<< "$SELECTED"
|
||||
"$CONTROLLER_IMAGE" scripts/run_molecule_in_controller.sh <<< "$SELECTED"
|
||||
|
||||
# A cancelled run can leave its containers running when the docker client is killed.
|
||||
- name: Remove this run's containers
|
||||
@@ -249,7 +249,7 @@ jobs:
|
||||
timeout-minutes: 5
|
||||
# The controller pin again, so this job adds no pin of its own to bump.
|
||||
container:
|
||||
image: git.rkdr.net/mortis/molecule-controller:0.1.3@sha256:4fa8a653e7af673f8e9921068dd504700679cc5bdefbfd55369e9cbca3fa9b44
|
||||
image: git.rkdr.net/mortis/molecule-controller:0.1.4@sha256:5658231afaff531161f02aef7a436ed875b1ad6c8d55a8d144e9763c71244420
|
||||
steps:
|
||||
- name: Check the select and scenarios jobs
|
||||
env:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Built collection archives and local tooling
|
||||
*.tar.gz
|
||||
/.venv/
|
||||
/.venv-dev/
|
||||
/venv/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
@@ -3,6 +3,7 @@ extends: default
|
||||
|
||||
ignore: |
|
||||
.venv/**
|
||||
.venv-dev/**
|
||||
apm_modules/**
|
||||
# Generated by apm install; its list indentation fails the rules below.
|
||||
apm.lock.yaml
|
||||
|
||||
@@ -4,6 +4,38 @@ mortis.kamino Release Notes
|
||||
|
||||
.. contents:: Topics
|
||||
|
||||
v3.5.0
|
||||
======
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- ufw - New input ``ufw_mask_nftables`` (default ``true``) and tag ``ufw_nftables``. Set the input to ``false`` on a host that loads its own ruleset through ``nftables.service``; the role never unmasks the unit.
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- ufw - An upgrade of the ``nftables`` package no longer deletes the firewall rules on hosts where ``nftables.service`` is enabled. The package's postinst restarts that unit, whose stock ``/etc/nftables.conf`` begins with ``flush ruleset``, so the rules ufw and Docker loaded were gone until they reloaded. The role now masks ``nftables.service`` without stopping it whenever ``ufw_enabled`` is true, also when the unit or the package is absent, so the first run reports ``changed`` once. A host that loads its own ruleset through ``nftables.service`` (NAT tables or sets, for example) would lose it at the next reboot without a warning, because a masked unit does not start: set ``ufw_mask_nftables: false`` on such a host before upgrading.
|
||||
|
||||
v3.4.0
|
||||
======
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- system_baseline - A name in ``system_baseline_sysctl_hardening`` may contain ``*``, which sets the key on every interface.
|
||||
- system_baseline - New input ``system_baseline_sysctl_file``, the path of the drop-in that persists the sysctl hardening.
|
||||
|
||||
Security Fixes
|
||||
--------------
|
||||
|
||||
- system_baseline - Every profile now refuses ICMP redirects on every interface, over IPv4 and IPv6. Before, only ``net.ipv4.conf.all`` was set, so a host that does not forward still accepted them on its interfaces.
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- system_baseline - The sysctl hardening survives a reboot on Debian 13, where ``systemd-sysctl`` no longer reads ``/etc/sysctl.conf``. The role now writes its values to ``/etc/sysctl.d/99-zz-system-baseline.conf`` and removes its keys from ``/etc/sysctl.conf``, so the first run reports ``changed`` once.
|
||||
|
||||
v3.3.0
|
||||
======
|
||||
|
||||
|
||||
@@ -34,4 +34,6 @@ GLOSSARY\\.md @Defame1297
|
||||
\\.claude/.* @Defame1297
|
||||
apm\\.yml @Defame1297
|
||||
apm\\.lock\\.yaml @Defame1297
|
||||
pyproject\\.toml @Defame1297
|
||||
uv\\.lock @Defame1297
|
||||
\\.mcp\\.json @Defame1297
|
||||
@@ -5,7 +5,7 @@ An Ansible Collection of reusable, hardened roles for a self-hosted home lab:
|
||||
`nfs_client`, `pihole`, `pve_lxc`, `pve_vm`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`,
|
||||
`ufw` and `user_management`, plus the internal `_binary_update`. Roles still to come are listed under [Roadmap](#roadmap).
|
||||
|
||||
Status: roles arrive in waves. Release 3.3.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `nfs_client`, `pihole`, `pve_lxc`, `pve_vm`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call).
|
||||
Status: roles arrive in waves. Release 3.5.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `nfs_client`, `pihole`, `pve_lxc`, `pve_vm`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call).
|
||||
|
||||
## Consuming
|
||||
|
||||
@@ -17,7 +17,7 @@ name (FQCN) only, `mortis.kamino.<role>`:
|
||||
collections:
|
||||
- name: https://git.rkdr.net/mortis/kamino.git
|
||||
type: git
|
||||
version: v3.3.0
|
||||
version: v3.5.0
|
||||
```
|
||||
|
||||
Its dependencies (`community.general`, `ansible.posix`, `community.proxmox`) are declared in `galaxy.yml`, so
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
lockfile_version: '4'
|
||||
generated_at: '2026-11-29T13:12:37.842657+00:00'
|
||||
apm_version: 0.38.1
|
||||
generated_at: '2026-12-04T21:33:07.493501+00:00'
|
||||
apm_version: 0.39.3
|
||||
manifest_targets:
|
||||
- claude
|
||||
dependencies:
|
||||
@@ -220,8 +220,8 @@ dependencies:
|
||||
.claude/agents/plan-researcher.md: sha256:eda0457d2007cf0c6cb4745383a0369d03a26ed252d7251a1f5250003a89ef85
|
||||
.claude/agents/plan-validator.md: sha256:a56e7a710fd9e7a9dd9e2601f1f2701b98fd229f3e014bba4bda4dfe5977ecae
|
||||
.claude/commands/next.md: sha256:8e16330ec0f16dbbc86d44fca94699e33e393c9a8af76f45d3f3bd2b9c8bfa1f
|
||||
.claude/commands/plan.md: sha256:2538b3dbb3860ebe93a39cad95cd5a1adcbeded19f404a84201b3e8aa7ce91c7
|
||||
.claude/commands/ship.md: sha256:f108f73e60a884f46285955027fba47d6309fed6a89812948f577e27be180af8
|
||||
.claude/commands/plan.md: sha256:c5216fb6c443ca9de45ad5cb69351a4e3193bcb5ffca4d59567495fcb5d7ec71
|
||||
.claude/commands/ship.md: sha256:c3c9f516b9b01cb7f879d7d331187b12f697f73104b0eafdc813d64b73091284
|
||||
.claude/skills/plan-track/LICENSE: sha256:9d3692e6b35e0e43b81e096352f11c6b884e7004d78d3dcd92768232c6704525
|
||||
.claude/skills/plan-track/SKILL.md: sha256:fee5062c8c63b49f66368b290c8ebd8cfff744137670d0c037da1a49c455c047
|
||||
.claude/skills/research-docs/LICENSE: sha256:9d3692e6b35e0e43b81e096352f11c6b884e7004d78d3dcd92768232c6704525
|
||||
@@ -843,7 +843,7 @@ deployments:
|
||||
owners:
|
||||
- git.rkdr.net/Mortis/Holocron/plugins/plan
|
||||
active_owner: git.rkdr.net/Mortis/Holocron/plugins/plan
|
||||
content_hash: sha256:2538b3dbb3860ebe93a39cad95cd5a1adcbeded19f404a84201b3e8aa7ce91c7
|
||||
content_hash: sha256:c5216fb6c443ca9de45ad5cb69351a4e3193bcb5ffca4d59567495fcb5d7ec71
|
||||
- kind: project-relative
|
||||
target: claude
|
||||
value: .claude/commands/ship.md
|
||||
@@ -852,7 +852,7 @@ deployments:
|
||||
owners:
|
||||
- git.rkdr.net/Mortis/Holocron/plugins/plan
|
||||
active_owner: git.rkdr.net/Mortis/Holocron/plugins/plan
|
||||
content_hash: sha256:f108f73e60a884f46285955027fba47d6309fed6a89812948f577e27be180af8
|
||||
content_hash: sha256:c3c9f516b9b01cb7f879d7d331187b12f697f73104b0eafdc813d64b73091284
|
||||
- kind: project-relative
|
||||
target: claude
|
||||
value: .claude/skills/code-review
|
||||
|
||||
@@ -93,4 +93,4 @@ plugins:
|
||||
strategy: {}
|
||||
test: {}
|
||||
vars: {}
|
||||
version: 3.3.0
|
||||
version: 3.5.0
|
||||
@@ -576,3 +576,47 @@ releases:
|
||||
- 482-pve-vm.yml
|
||||
- system-baseline-internal-registers.yml
|
||||
release_date: '2026-12-01'
|
||||
3.4.0:
|
||||
changes:
|
||||
bugfixes:
|
||||
- system_baseline - The sysctl hardening survives a reboot on Debian 13, where
|
||||
``systemd-sysctl`` no longer reads ``/etc/sysctl.conf``. The role now writes
|
||||
its values to ``/etc/sysctl.d/99-zz-system-baseline.conf`` and removes its
|
||||
keys from ``/etc/sysctl.conf``, so the first run reports ``changed`` once.
|
||||
minor_changes:
|
||||
- system_baseline - A name in ``system_baseline_sysctl_hardening`` may contain
|
||||
``*``, which sets the key on every interface.
|
||||
- system_baseline - New input ``system_baseline_sysctl_file``, the path of the
|
||||
drop-in that persists the sysctl hardening.
|
||||
security_fixes:
|
||||
- system_baseline - Every profile now refuses ICMP redirects on every interface,
|
||||
over IPv4 and IPv6. Before, only ``net.ipv4.conf.all`` was set, so a host
|
||||
that does not forward still accepted them on its interfaces.
|
||||
fragments:
|
||||
- 505-ufw-check-mode-probe.yml
|
||||
- 510-system-baseline-sysctl-dropin.yml
|
||||
- 510-system-baseline-sysctl-file.yml
|
||||
- 511-system-baseline-icmp-redirects.yml
|
||||
- 511-system-baseline-sysctl-wildcard.yml
|
||||
release_date: '2026-12-03'
|
||||
3.5.0:
|
||||
changes:
|
||||
bugfixes:
|
||||
- 'ufw - An upgrade of the ``nftables`` package no longer deletes the firewall
|
||||
rules on hosts where ``nftables.service`` is enabled. The package''s postinst
|
||||
restarts that unit, whose stock ``/etc/nftables.conf`` begins with ``flush
|
||||
ruleset``, so the rules ufw and Docker loaded were gone until they reloaded.
|
||||
The role now masks ``nftables.service`` without stopping it whenever ``ufw_enabled``
|
||||
is true, also when the unit or the package is absent, so the first run reports
|
||||
``changed`` once. A host that loads its own ruleset through ``nftables.service``
|
||||
(NAT tables or sets, for example) would lose it at the next reboot without
|
||||
a warning, because a masked unit does not start: set ``ufw_mask_nftables:
|
||||
false`` on such a host before upgrading.'
|
||||
minor_changes:
|
||||
- ufw - New input ``ufw_mask_nftables`` (default ``true``) and tag ``ufw_nftables``.
|
||||
Set the input to ``false`` on a host that loads its own ruleset through ``nftables.service``;
|
||||
the role never unmasks the unit.
|
||||
fragments:
|
||||
- ufw-mask-nftables-input.yml
|
||||
- ufw-mask-nftables.yml
|
||||
release_date: '2026-12-06'
|
||||
@@ -9,7 +9,7 @@ held by review until an offline link check exists.
|
||||
## The clone
|
||||
|
||||
- **Run `scripts/dev-setup.sh` once per clone, and again after a change to `requirements-dev.txt`, its
|
||||
lock `requirements-dev.lock`, `requirements.yml` or the hook types.** It creates `.venv` with the
|
||||
lock `requirements-dev.lock`, `requirements.yml` or the hook types.** It creates `.venv-dev` with the
|
||||
pinned tools on the Python named in `.python-version`, installs the collections of `requirements.yml`
|
||||
into `.ansible/collections`, and installs the git hooks (pre-commit, commit-msg, pre-push) with the
|
||||
virtualenv first on their `PATH`.
|
||||
@@ -63,6 +63,12 @@ held by review until an offline link check exists.
|
||||
pushed on an unmerged branch lets that branch's commands run without a prompt before anyone has
|
||||
reviewed it, while a `deny` or `ask` rule can only add prompts.
|
||||
*Held by:* review (`.claude/` is under `CODEOWNERS`).
|
||||
- **Install [uv](https://docs.astral.sh/uv/getting-started/installation/), run `uv sync --frozen` once per
|
||||
clone and again after a change to `uv.lock`, and run apm only as `uv run --frozen apm ...`** (for example
|
||||
`uv run --frozen apm install`). uv keeps apm in `.venv`, apart from the tools in `.venv-dev`.
|
||||
*Reason:* a bare `apm` is whatever version your machine has, and versions differ in which
|
||||
`apm.lock.yaml` they accept and in what they deploy.
|
||||
*Held by:* aspirational.
|
||||
- **Every hook in the tracked `.claude/settings.json` arrives through apm; personal hooks go in
|
||||
`.claude/settings.local.json`.**
|
||||
*Reason:* a hook nobody owns is checked by nothing.
|
||||
|
||||
+7
-8
@@ -10,13 +10,12 @@ runs in the [`molecule-controller`](molecule-controller.md) image instead
|
||||
Ubuntu 26.04 with:
|
||||
|
||||
- **Python tools** in `/opt/venv` (on `PATH`; it runs on Python 3.14, the version of `.python-version`, from the baked copy and not from the distribution's `python3`), from `requirements-dev.lock` (the hashed lock of `requirements-dev.txt`, installed with `pip install --require-hashes`): `ansible-core`,
|
||||
`ansible-lint`, `pre-commit`, `antsibull-changelog`, `galaxy-importer`, `reuse`, `molecule` and
|
||||
`molecule-plugins[docker]` (the Docker driver, with the `docker` Python SDK), and `proxmoxer`, the controller-side
|
||||
library the modules of `community.proxmox` import.
|
||||
`ansible-lint`, `pre-commit`, `antsibull-changelog`, `galaxy-importer`, `reuse`, `molecule`
|
||||
(without its Docker driver: Lint's "Test the repository scripts" step runs the tests that import it), and
|
||||
`proxmoxer`, the controller-side library the modules of `community.proxmox` import.
|
||||
- **The collections the roles call** in `/opt/collections` (`ANSIBLE_COLLECTIONS_PATH` is set to it), from
|
||||
`requirements.yml`: `community.general`, `ansible.posix` and `community.proxmox` at the exact versions CI tests against, so
|
||||
`ansible-lint --offline` resolves their modules instead of mocking them; and from
|
||||
`extensions/molecule/requirements.yml`, `community.docker`, which the Molecule Docker driver's own playbooks call.
|
||||
`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, actionlint and zizmor. The Go
|
||||
hooks are prebuilt; their toolchains, and the binaries of those repositories that no hook runs, are removed to
|
||||
@@ -28,7 +27,7 @@ Ubuntu 26.04 with:
|
||||
`python3`, so sanity runs its compile test for those interpreters instead of skipping it.
|
||||
- `git`, `shellcheck` (actionlint runs it over `run:` blocks), `python3`, `python3-venv` and `ca-certificates`.
|
||||
The image runs as root and sets no working directory.
|
||||
- `/opt/ci-pins.sha256`: the checksums of the five pin files this image was built from.
|
||||
- `/opt/ci-pins.sha256`: the checksums of the four pin files this image was built from.
|
||||
|
||||
It has no Node, so JavaScript actions (`actions/checkout`) cannot run in it: clone with `git`.
|
||||
|
||||
@@ -61,8 +60,8 @@ jobs:
|
||||
pre-commit run --all-files --show-diff-on-failure
|
||||
```
|
||||
|
||||
`/opt/ci-pins.sha256` lists the five pin files by their checkout-relative path, so `sha256sum -c` runs in the checkout root. When
|
||||
the checkout's `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml`, `extensions/molecule/requirements.yml` and `.pre-commit-config.yaml` match, the baked tools and
|
||||
`/opt/ci-pins.sha256` lists the four pin files by their checkout-relative path, so `sha256sum -c` runs in the checkout root. When
|
||||
the checkout's `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml` and `.pre-commit-config.yaml` match, the baked tools and
|
||||
collections are used as they are, and Lint and Build cut the network by environment (proxy variables and
|
||||
`PIP_NO_INDEX`) for all but the script tests, so a tool that downloads at run time fails the job. When a pull request changes a pin the check fails and the job installs the pinned
|
||||
tools and collections itself for that run
|
||||
|
||||
@@ -33,7 +33,7 @@ checkout). In the checkout root, run `sha256sum --quiet -c /opt/molecule-pins.sh
|
||||
and collections for that run first (slower, same result), until the image is rebuilt from `main`.
|
||||
|
||||
`.gitea/workflows/molecule.yml` is its consumer: it pins the image as `CONTROLLER_IMAGE`, and
|
||||
`scripts/run_molecule_in_ci_image.sh` runs the pin check inside it. Read the workflow for the full command.
|
||||
`scripts/run_molecule_in_controller.sh` runs the pin check inside it. Read the workflow for the full command.
|
||||
|
||||
## Tags and pinning
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ It is the release the hosts run today.
|
||||
|
||||
## What is in it
|
||||
|
||||
- Ubuntu 24.04 (the official `ubuntu:24.04` image, pinned by digest in the Dockerfile).
|
||||
- Ubuntu 24.04 (the official `ubuntu:24.04` image, pinned by digest in the Dockerfile, with its packages
|
||||
upgraded when the image is built).
|
||||
- systemd as the init system (`systemd`, `systemd-sysv`), D-Bus, `sudo`, `iproute2`,
|
||||
`ca-certificates`.
|
||||
- Python for Ansible on the target: `python3`, `python3-apt`, `python3-systemd`.
|
||||
|
||||
@@ -7,7 +7,8 @@ It is the release the hosts are moving to; every role scenario whose role declar
|
||||
|
||||
## What is in it
|
||||
|
||||
- Ubuntu 26.04 (the official `ubuntu:26.04` image, pinned by digest in the Dockerfile).
|
||||
- Ubuntu 26.04 (the official `ubuntu:26.04` image, pinned by digest in the Dockerfile, with its packages
|
||||
upgraded when the image is built).
|
||||
- systemd as the init system (`systemd`, `systemd-sysv`), D-Bus, `sudo`, `iproute2`,
|
||||
`ca-certificates`.
|
||||
- Python for Ansible on the target: `python3`, `python3-apt`, `python3-systemd`.
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
# Collections the Molecule test harness itself calls, as opposed to the roles under test (those are
|
||||
# in the requirements.yml at the repository root). The Docker driver of molecule-plugins runs
|
||||
# community.docker modules in its own create and destroy playbooks, so every scenario needs it.
|
||||
# The ci image (images/ci) bakes it into /opt/collections next to the root one; a pull request that
|
||||
# changes it fails the image's pin check, so the Molecule job installs it itself.
|
||||
# The molecule-controller image (images/molecule-controller) bakes it into /opt/collections next to the
|
||||
# root one; a pull request that changes it fails the image's pin check, so the Molecule job installs it itself.
|
||||
# Renovate (renovate.json, ansible-galaxy manager) bumps this pin.
|
||||
collections:
|
||||
- name: community.docker
|
||||
|
||||
+4
-1
@@ -1,7 +1,7 @@
|
||||
---
|
||||
namespace: mortis
|
||||
name: kamino
|
||||
version: 3.3.0
|
||||
version: 3.5.0
|
||||
readme: README.md
|
||||
authors:
|
||||
- Defame1297
|
||||
@@ -46,6 +46,7 @@ build_ignore:
|
||||
- .python-version
|
||||
- .ruff_cache
|
||||
- .venv
|
||||
- .venv-dev
|
||||
- .yamllint
|
||||
- docs
|
||||
- .ansible-lint
|
||||
@@ -59,6 +60,7 @@ build_ignore:
|
||||
- images
|
||||
- scripts
|
||||
- tests/scripts
|
||||
- pyproject.toml
|
||||
- renovate.json
|
||||
- ruff.toml
|
||||
- requirements-dev.txt
|
||||
@@ -66,6 +68,7 @@ build_ignore:
|
||||
- requirements-molecule.txt
|
||||
- requirements-molecule.lock
|
||||
- requirements.yml
|
||||
- uv.lock
|
||||
- gitleaks-report.json
|
||||
- importer_result.json
|
||||
- 'roles/*/molecule'
|
||||
|
||||
@@ -65,6 +65,8 @@ it to this repository's organisation in the Gitea registry as `<version>` and `l
|
||||
the fast path Lint and Build cut the network by environment, so a download through pip or a
|
||||
proxy-honouring client fails the job; review for a raw socket, for the script tests, which keep
|
||||
network, and for Molecule.
|
||||
- **Each Dockerfile upgrades the base image's packages in its first apt layer.** *Why:* Ubuntu
|
||||
publishes package updates before it refreshes the base image. *Held:* review.
|
||||
- **Recorded speed:** a speed optimisation that adds machinery states its measured saving where
|
||||
it lives (a comment next to it). *Why:* machinery is kept only for a saving someone can check.
|
||||
*Held:* review.
|
||||
|
||||
+17
-21
@@ -13,12 +13,13 @@
|
||||
# - OS packages: git, shellcheck (actionlint runs it over run: blocks), the
|
||||
# distribution's python3 and ca-certificates.
|
||||
# - /opt/venv: requirements-dev.lock, the hashed lock of requirements-dev.txt (ansible-core, ansible-lint, pre-commit,
|
||||
# antsibull-changelog, galaxy-importer, reuse, molecule and its Docker driver, proxmoxer), on the Python of
|
||||
# .python-version (PYTHON_VERSION below), the one the lock was resolved on and a clone's .venv uses.
|
||||
# antsibull-changelog, galaxy-importer, reuse, molecule, proxmoxer), on the Python of
|
||||
# .python-version (PYTHON_VERSION below), the one the lock was resolved on and a clone's .venv-dev uses.
|
||||
# molecule is there for Lint's "Test the repository scripts" step, whose molecule tests import it; its
|
||||
# Docker driver and community.docker are not: Molecule runs in the molecule-controller image.
|
||||
# - /opt/collections: the collections of requirements.yml (the versions the roles are
|
||||
# tested against), found through ANSIBLE_COLLECTIONS_PATH, so `ansible-lint --offline`
|
||||
# resolves their modules without a mock list; and those of extensions/molecule/requirements.yml
|
||||
# (community.docker), which the Molecule Docker driver's own playbooks call.
|
||||
# resolves their modules without a mock list.
|
||||
# - /opt/pre-commit: every hook environment of .pre-commit-config.yaml, installed by
|
||||
# `pre-commit install-hooks` (gitleaks and actionlint are built from source by
|
||||
# pre-commit, which downloads a Go toolchain: that is most of the time saved).
|
||||
@@ -27,8 +28,8 @@
|
||||
# - Python 3.11, 3.13 and PYTHON_VERSION as python<MINOR> on PATH, so that
|
||||
# `ansible-test sanity` runs its compile test for them instead of skipping it.
|
||||
# They come from python-build-standalone through uv, pinned by the uv version.
|
||||
# - /opt/ci-pins.sha256: the checksums of requirements-dev.txt, requirements-dev.lock, requirements.yml,
|
||||
# extensions/molecule/requirements.yml and .pre-commit-config.yaml this image was built from. A job runs
|
||||
# - /opt/ci-pins.sha256: the checksums of requirements-dev.txt, requirements-dev.lock, requirements.yml
|
||||
# and .pre-commit-config.yaml this image was built from. A job runs
|
||||
# `sha256sum -c /opt/ci-pins.sha256` in its checkout; when a pull request changes a
|
||||
# pin the check fails and the job installs the tools as before, until the image
|
||||
# is rebuilt from main.
|
||||
@@ -36,15 +37,16 @@
|
||||
# Layers: each COPY / RUN below is one layer, and a layer is pushed as one request,
|
||||
# so it must stay below Cloudflare's 100 MB request-body limit on git.rkdr.net. The
|
||||
# build stage prints the sizes it will copy; the first push is the real test.
|
||||
# Base image: ubuntu:26.04 index digest as of 2026-10-26, same as molecule-ubuntu2604.
|
||||
# Base image: ubuntu:26.04 index digest as of 2026-12-03, same as molecule-ubuntu2604.
|
||||
|
||||
FROM ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db AS os
|
||||
FROM ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd AS os
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# No python3-pip: tools are installed with the venv's own pip. python3-venv brings
|
||||
# ensurepip. apt lists are removed in the same layer.
|
||||
# ensurepip. The upgrade brings in updates newer than the base image. apt lists are removed in the same layer.
|
||||
RUN apt-get update \
|
||||
&& apt-get upgrade -y --with-new-pkgs --no-install-recommends \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
ca-certificates git python3 python3-venv shellcheck \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
@@ -66,12 +68,10 @@ ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
||||
|
||||
WORKDIR /src
|
||||
COPY requirements-dev.txt requirements-dev.lock requirements.yml .pre-commit-config.yaml ./
|
||||
# Kept at its checkout path: its name matches the root requirements.yml.
|
||||
COPY extensions/molecule/requirements.yml extensions/molecule/
|
||||
|
||||
# The interpreters come first: /opt/venv is built from the pinned one (PYTHON_VERSION, kept equal to
|
||||
# .python-version and to the lock header by `check_image_versions.py pins`), not from the distribution's
|
||||
# python3, so the tools run on the Python the lock was resolved on and a clone's .venv uses.
|
||||
# python3, so the tools run on the Python the lock was resolved on and a clone's .venv-dev uses.
|
||||
# uv only lives in the build stage (its own venv): the final image keeps the interpreters it
|
||||
# downloaded, not the installer. The distribution's python3 only bootstraps uv.
|
||||
RUN python3 -m venv /opt/uv-venv \
|
||||
@@ -99,13 +99,11 @@ RUN "$(echo /opt/python/cpython-${PYTHON_VERSION}.*/bin/python${PYTHON_VERSION})
|
||||
&& /opt/venv/bin/python --version \
|
||||
&& /opt/venv/bin/pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt
|
||||
|
||||
# The collections of requirements.yml and extensions/molecule/requirements.yml. ANSIBLE_COLLECTIONS_PATH is set to the target for the
|
||||
# The collections of requirements.yml. ANSIBLE_COLLECTIONS_PATH is set to the target for the
|
||||
# install only: a collection found anywhere else on the path would be skipped as "already
|
||||
# installed" and not copied here.
|
||||
RUN ANSIBLE_COLLECTIONS_PATH=/opt/collections \
|
||||
/opt/venv/bin/ansible-galaxy collection install -r requirements.yml -p /opt/collections \
|
||||
&& ANSIBLE_COLLECTIONS_PATH=/opt/collections \
|
||||
/opt/venv/bin/ansible-galaxy collection install -r extensions/molecule/requirements.yml -p /opt/collections \
|
||||
&& du -sh /opt/collections
|
||||
|
||||
# pre-commit needs a git repository to resolve a config. The hook repositories are
|
||||
@@ -178,7 +176,7 @@ FROM os AS final
|
||||
ARG PYTHON_VERSION=3.14
|
||||
|
||||
LABEL org.opencontainers.image.title="ci" \
|
||||
org.opencontainers.image.description="CI tooling image for the mortis.kamino Ansible Collection: the Lint and Build workflows run in it, so a job only checks out the code and runs; Molecule runs in the molecule-controller image. It bakes in ansible-core, ansible-lint, pre-commit with every hook environment of the repository, antsibull-changelog, galaxy-importer, reuse, molecule with its Docker driver, proxmoxer, the collections of requirements.yml and extensions/molecule/requirements.yml, git, shellcheck, Python 3.11, 3.13 and the version of .python-version (the tools in /opt/venv run on it) next to the distribution python3 and primed ansible-test sanity virtualenvs. Pin it by tag and digest, as a job container or with docker run; it has no Node, so clone with git." \
|
||||
org.opencontainers.image.description="CI tooling image for the mortis.kamino Ansible Collection: the Lint and Build workflows run in it, so a job only checks out the code and runs; Molecule runs in the molecule-controller image. It bakes in ansible-core, ansible-lint, pre-commit with every hook environment of the repository, antsibull-changelog, galaxy-importer, reuse, molecule (for the script tests), proxmoxer, the collections of requirements.yml, git, shellcheck, Python 3.11, 3.13 and the version of .python-version (the tools in /opt/venv run on it) next to the distribution python3 and primed ansible-test sanity virtualenvs. Pin it by tag and digest, as a job container or with docker run; it has no Node, so clone with git." \
|
||||
org.opencontainers.image.source="https://git.rkdr.net/mortis/kamino" \
|
||||
org.opencontainers.image.url="https://git.rkdr.net/mortis/kamino" \
|
||||
org.opencontainers.image.documentation="https://git.rkdr.net/mortis/kamino/src/branch/main/docs/images/ci.md" \
|
||||
@@ -186,7 +184,7 @@ LABEL org.opencontainers.image.title="ci" \
|
||||
org.opencontainers.image.authors="Defame1297 and contributors" \
|
||||
org.opencontainers.image.base.name="ubuntu:26.04" \
|
||||
net.rkdr.mortis.purpose="CI tooling image for the mortis.kamino Ansible Collection: the Lint and Build workflows run in it, so a job only checks out the code and runs." \
|
||||
net.rkdr.mortis.contents="Ubuntu 26.04, /opt/venv (ansible-core, ansible-lint, pre-commit, antsibull-changelog, galaxy-importer, reuse, molecule, molecule-plugins[docker], proxmoxer), /opt/collections (community.general, ansible.posix, community.proxmox, community.docker), /opt/pre-commit hook environments, ansible-test sanity venvs, python3 (distribution), python3.11, python3.13, python<PYTHON_VERSION> (the one of /opt/venv), git, shellcheck, /opt/ci-pins.sha256" \
|
||||
net.rkdr.mortis.contents="Ubuntu 26.04, /opt/venv (ansible-core, ansible-lint, pre-commit, antsibull-changelog, galaxy-importer, reuse, molecule, proxmoxer), /opt/collections (community.general, ansible.posix, community.proxmox), /opt/pre-commit hook environments, ansible-test sanity venvs, python3 (distribution), python3.11, python3.13, python<PYTHON_VERSION> (the one of /opt/venv), git, shellcheck, /opt/ci-pins.sha256" \
|
||||
net.rkdr.mortis.usage="Lint and Build: job container on the kamino-docker runner, git.rkdr.net/mortis/ci:version@sha256:digest with PRE_COMMIT_HOME set to /opt/pre-commit. Run sha256sum -c /opt/ci-pins.sha256 in the checkout root and install the pinned tools and collections when a pull request changed them, else use /opt/venv/bin and ANSIBLE_COLLECTIONS_PATH=/opt/collections. See the documentation label."
|
||||
|
||||
ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
||||
@@ -203,16 +201,14 @@ COPY --from=build /root/.ansible/test /root/.ansible/test
|
||||
|
||||
# The target interpreters ansible-test looks for on PATH, and the pin record.
|
||||
COPY --from=build /src/requirements-dev.txt /src/requirements-dev.lock /src/requirements.yml /src/.pre-commit-config.yaml /opt/ci-pins/
|
||||
# Under its checkout path, so `sha256sum -c` in a checkout root finds it.
|
||||
COPY --from=build /src/extensions/molecule/requirements.yml /opt/ci-pins/extensions/molecule/
|
||||
RUN set -eu; \
|
||||
for v in $(printf '%s\n' 3.11 3.13 "${PYTHON_VERSION}" | sort -u); do \
|
||||
ln -sf "$(echo /opt/python/cpython-${v}.*/bin/python${v})" "/usr/local/bin/python${v}"; \
|
||||
"python${v}" --version; \
|
||||
done; \
|
||||
cd /opt/ci-pins; \
|
||||
sha256sum requirements-dev.txt requirements-dev.lock requirements.yml extensions/molecule/requirements.yml \
|
||||
.pre-commit-config.yaml > /opt/ci-pins.sha256; \
|
||||
sha256sum requirements-dev.txt requirements-dev.lock requirements.yml .pre-commit-config.yaml \
|
||||
> /opt/ci-pins.sha256; \
|
||||
ansible --version | head -n1; \
|
||||
ansible-galaxy collection list; \
|
||||
pre-commit --version; \
|
||||
|
||||
@@ -24,14 +24,15 @@
|
||||
# stay below Cloudflare's 100 MB request-body limit on git.rkdr.net. The build stage prints the
|
||||
# compressed size of each directory it copies.
|
||||
|
||||
FROM ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db AS os
|
||||
FROM ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd AS os
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# python3 and python3-venv only bootstrap uv in the build stage; ca-certificates serve the
|
||||
# install a job runs when a pull request changes a pin; git lets the selector diff the checkout.
|
||||
# apt lists are removed in the same layer.
|
||||
# The upgrade brings in updates newer than the base image. apt lists are removed in the same layer.
|
||||
RUN apt-get update \
|
||||
&& apt-get upgrade -y --with-new-pkgs --no-install-recommends \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates git python3 python3-venv \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
|
||||
@@ -17,15 +17,16 @@
|
||||
# One RUN layer: at most about 30 MB compressed on top of the 29.8 MB base (estimated from
|
||||
# the real .debs, with the .pyc files the postinst scripts compile), far below
|
||||
# Cloudflare's 100 MB request-body limit on git.rkdr.net (kaniko pushes a layer as
|
||||
# one request; gnupg adds a few MB, not measured). apt packages are not version-pinned, as in the original image; the
|
||||
# one request; gnupg adds a few MB, not measured, and the upgraded base packages about 4 MB).
|
||||
# apt packages are not version-pinned, as in the original image; the
|
||||
# base image is pinned by digest and a rebuild is a reviewed digest bump downstream.
|
||||
#
|
||||
# The image carries SSH host keys and a machine-id generated at build time (the
|
||||
# openssh-server and systemd postinst scripts). ssh.service runs `sshd -t` and
|
||||
# fails without host keys, so they cannot be removed; image scanners will flag them.
|
||||
# They are throwaway keys of a test target that is never exposed.
|
||||
# ubuntu:24.04 index digest as of 2026-10-24 (24.04.5).
|
||||
FROM ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b
|
||||
# ubuntu:24.04 index digest as of 2026-12-03.
|
||||
FROM ubuntu:24.04@sha256:168a88cc61bdd95c8f871e3903d4e0a525e340c2b28a70dadd6d1503ecc7c391
|
||||
|
||||
LABEL org.opencontainers.image.title="molecule-ubuntu2404" \
|
||||
org.opencontainers.image.description="Disposable Ubuntu 24.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection. systemd runs as PID 1 with D-Bus, sudo, python3 and the test fixtures (iptables, openssh-server, gnupg) preinstalled. A package a role installs is not baked in and no APT lists are kept, so a scenario refreshes the APT cache before a role installs one. Start it as a molecule platform (usage label); it carries throwaway SSH host keys and is a test target only, never to be exposed." \
|
||||
@@ -41,11 +42,13 @@ LABEL org.opencontainers.image.title="molecule-ubuntu2404" \
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# The upgrade brings in updates newer than the base image.
|
||||
# systemd as PID 1 with D-Bus, sudo and networking tools; the Python Ansible needs on
|
||||
# the target (python3-apt for the apt module, python3-systemd for the journal); iptables;
|
||||
# sshd, enabled so a converge can test it under systemd; gnupg, which the docker scenario
|
||||
# signs its stand-in APT repository with. ufw and fail2ban are left out: their roles install them.
|
||||
RUN apt-get update \
|
||||
&& apt-get upgrade -y --with-new-pkgs --no-install-recommends \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
systemd systemd-sysv dbus sudo iproute2 ca-certificates \
|
||||
python3 python3-apt python3-systemd \
|
||||
|
||||
@@ -17,15 +17,16 @@
|
||||
# One RUN layer: at most about 30 MB compressed on top of the 29.8 MB base (estimated from
|
||||
# the real .debs, with the .pyc files the postinst scripts compile), far below
|
||||
# Cloudflare's 100 MB request-body limit on git.rkdr.net (kaniko pushes a layer as
|
||||
# one request; gnupg adds a few MB, not measured). apt packages are not version-pinned, as in the original image; the
|
||||
# one request; gnupg adds a few MB, not measured, and the upgraded base packages about 4 MB).
|
||||
# apt packages are not version-pinned, as in the original image; the
|
||||
# base image is pinned by digest and a rebuild is a reviewed digest bump downstream.
|
||||
#
|
||||
# The image carries SSH host keys and a machine-id generated at build time (the
|
||||
# openssh-server and systemd postinst scripts). ssh.service runs `sshd -t` and
|
||||
# fails without host keys, so they cannot be removed; image scanners will flag them.
|
||||
# They are throwaway keys of a test target that is never exposed.
|
||||
# ubuntu:26.04 index digest as of 2026-10-26.
|
||||
FROM ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||
# ubuntu:26.04 index digest as of 2026-12-03.
|
||||
FROM ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
|
||||
|
||||
LABEL org.opencontainers.image.title="molecule-ubuntu2604" \
|
||||
org.opencontainers.image.description="Disposable Ubuntu 26.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection. systemd runs as PID 1 with D-Bus, sudo, python3 and the test fixtures (iptables, openssh-server, gnupg) preinstalled. A package a role installs is not baked in and no APT lists are kept, so a scenario refreshes the APT cache before a role installs one. Start it as a molecule platform (usage label); it carries throwaway SSH host keys and is a test target only, never to be exposed." \
|
||||
@@ -41,6 +42,7 @@ LABEL org.opencontainers.image.title="molecule-ubuntu2604" \
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# The upgrade brings in updates newer than the base image.
|
||||
# systemd as PID 1 with D-Bus, sudo and networking tools; the Python Ansible needs on
|
||||
# the target (python3-apt for the apt module, python3-systemd for the journal); iptables;
|
||||
# sshd, enabled so a converge can test it under systemd; gnupg, which the docker scenario
|
||||
@@ -48,6 +50,7 @@ ENV DEBIAN_FRONTEND=noninteractive
|
||||
# root's sudo (Ansible's become here) skips pam_unix's account check, whose unix_chkpwd
|
||||
# helper fails inside the container; non-root callers still go through pam_unix.
|
||||
RUN apt-get update \
|
||||
&& apt-get upgrade -y --with-new-pkgs --no-install-recommends \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
systemd systemd-sysv dbus sudo iproute2 ca-certificates \
|
||||
python3 python3-apt python3-systemd \
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# Pins apm for contributors (docs/contributing/setup.md). The Lint and Build tools are pinned in requirements-dev.txt.
|
||||
[project]
|
||||
name = "kamino"
|
||||
version = "0"
|
||||
# ruff reads this floor too: a higher one makes it reformat existing files.
|
||||
requires-python = ">=3.11"
|
||||
|
||||
[dependency-groups]
|
||||
dev = ["apm-cli==0.39.3"]
|
||||
|
||||
[tool.uv]
|
||||
package = false
|
||||
+37
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"description": "Run by .gitea/workflows/renovate.yml on this repository's own runner. Policy: automerge minor and patch, majors by hand. Every bot pull request must pass scripts/check_bot_pr_diff.py (lint workflow), which allows only version, tag, digest and pin lines. Image versions are assigned by the Images workflow when an image's inputs change, so a bot pull request needs no version edit. Updates open on Mondays (UTC), so any Monday run can act; the own image pins and vulnerability fixes found on osv.dev open at any time. The weekly window and the groups bound the volume, so there is no hourly pull request limit. Vulnerability fixes skip the release-age wait, so they are never automerged: a person checks a fix that had no time to be pulled as a compromised release. Base-image bumps are manual: every Dockerfile is FROM ubuntu, grouped with the job containers.",
|
||||
"description": "Run by .gitea/workflows/renovate.yml on this repository's own runner. Policy: automerge minor and patch, majors by hand. Every bot pull request must pass scripts/check_bot_pr_diff.py (lint workflow), which allows only version, tag, digest and pin lines, and in uv.lock only the apm-cli bump to the pin in pyproject.toml (scripts/check_uv_lock.py). Image versions are assigned by the Images workflow when an image's inputs change, so a bot pull request needs no version edit. Updates open on Mondays (UTC), so any Monday run can act; the own image pins and vulnerability fixes found on osv.dev open at any time. The weekly window and the groups bound the volume, so there is no hourly pull request limit. Vulnerability fixes skip the release-age wait, so they are never automerged: a person checks a fix that had no time to be pulled as a compromised release. Base-image bumps are manual: every Dockerfile is FROM ubuntu, grouped with the job containers.",
|
||||
"extends": [
|
||||
"config:recommended",
|
||||
":enablePreCommit"
|
||||
@@ -11,6 +11,7 @@
|
||||
"semanticCommitScope": "deps",
|
||||
"enabledManagers": [
|
||||
"pip-compile",
|
||||
"pep621",
|
||||
"ansible-galaxy",
|
||||
"pre-commit",
|
||||
"github-actions",
|
||||
@@ -35,6 +36,11 @@
|
||||
"/^requirements-molecule\\.lock$/"
|
||||
]
|
||||
},
|
||||
"pep621": {
|
||||
"managerFilePatterns": [
|
||||
"/^pyproject\\.toml$/"
|
||||
]
|
||||
},
|
||||
"pre-commit": {
|
||||
"enabled": true,
|
||||
"managerFilePatterns": [
|
||||
@@ -196,7 +202,6 @@
|
||||
"pypi"
|
||||
],
|
||||
"matchPackageNames": [
|
||||
"apm-cli",
|
||||
"antsibull-changelog",
|
||||
"galaxy-importer",
|
||||
"reuse",
|
||||
@@ -211,6 +216,36 @@
|
||||
"pre-commit"
|
||||
],
|
||||
"groupName": "pre-commit hooks"
|
||||
},
|
||||
{
|
||||
"description": "requires-python in pyproject.toml is the floor ruff formats for, not a pin: never updated by the bot.",
|
||||
"matchManagers": [
|
||||
"pep621"
|
||||
],
|
||||
"matchDepTypes": [
|
||||
"requires-python"
|
||||
],
|
||||
"enabled": false
|
||||
},
|
||||
{
|
||||
"description": "No lock file maintenance for uv.lock: scripts/check_uv_lock.py refuses any change to a package other than apm-cli, so a person refreshes uv.lock by hand.",
|
||||
"matchManagers": [
|
||||
"pep621"
|
||||
],
|
||||
"matchUpdateTypes": [
|
||||
"lockFileMaintenance"
|
||||
],
|
||||
"enabled": false
|
||||
},
|
||||
{
|
||||
"description": "apm-cli (pyproject.toml and uv.lock) gets its own pull request, never automerged: CI never runs apm, so a green run says nothing about a new version. Placed last so no rule above turns automerge back on.",
|
||||
"matchManagers": [
|
||||
"pep621"
|
||||
],
|
||||
"matchPackageNames": [
|
||||
"apm-cli"
|
||||
],
|
||||
"automerge": false
|
||||
}
|
||||
],
|
||||
"lockFileMaintenance": {
|
||||
|
||||
+7
-1200
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,5 @@
|
||||
# Pinned tooling for lint, build and Molecule, used by CI (.gitea/workflows) and locally:
|
||||
# python3 -m venv .venv && . .venv/bin/activate && pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt
|
||||
# Pinned tooling for Lint and Build, used by CI (.gitea/workflows) and locally:
|
||||
# python3 -m venv .venv-dev && . .venv-dev/bin/activate && pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt
|
||||
# This file holds the direct pins; requirements-dev.lock is their hashed lock (every transitive
|
||||
# package too, with the sha256 of each release file) and is what gets installed; pip refuses an
|
||||
# install in which the two files disagree. Renovate bumps a pin here and regenerates the lock
|
||||
@@ -12,11 +12,9 @@ pre-commit==4.7.0
|
||||
antsibull-changelog==0.38.0
|
||||
galaxy-importer==0.4.45
|
||||
reuse==6.3.0
|
||||
# molecule without its Docker driver: Lint's "Test the repository scripts" step imports it in
|
||||
# test_check_scenarios_load_checkout.py and test_run_molecule_scenarios.py, which skip without it.
|
||||
molecule==26.11.1
|
||||
molecule-plugins[docker]==26.11.0
|
||||
# proxmoxer: the controller-side library community.proxmox's modules import (they refuse anything below 2.3),
|
||||
# so lint and Molecule run where a consumer's controller would.
|
||||
# so lint runs where a consumer's controller would.
|
||||
proxmoxer==2.3.0
|
||||
# apm-cli: for changing apm.yml (run apm install, commit the lock). Keep it at 0.36.1 or later (#252):
|
||||
# before 0.29.0, `apm audit --ci` compares the whole .claude/settings.json and fails on any hand-written key.
|
||||
apm-cli==0.39.1
|
||||
+3
-2
@@ -2,8 +2,9 @@
|
||||
# Collections the roles of this Collection call (the dependencies of galaxy.yml, pinned exactly).
|
||||
# galaxy.yml holds the lower bounds a consumer needs; this file holds the versions CI tests
|
||||
# against. One file feeds every consumer, so they cannot drift apart:
|
||||
# - the ci image (images/ci/Dockerfile) bakes it into /opt/collections for Lint and Molecule;
|
||||
# - the Molecule job (.gitea/workflows/molecule.yml) installs it itself when a pull request changes it;
|
||||
# - the ci image (images/ci/Dockerfile) bakes it into /opt/collections for Lint;
|
||||
# - the molecule-controller image (images/molecule-controller/Dockerfile) bakes it for Molecule,
|
||||
# and scripts/run_molecule_in_controller.sh installs it itself when a pull request changes it;
|
||||
# - scripts/dev-setup.sh installs it into .ansible/collections for local lint.
|
||||
# Renovate (renovate.json, ansible-galaxy manager) bumps these pins.
|
||||
collections:
|
||||
|
||||
@@ -15,7 +15,7 @@ The role targets Ubuntu guests (the `ubuntu_lxc` and `ubuntu_vm` profiles) and P
|
||||
- Facts must be gathered (`gather_facts: true`); `reboot.yml` reads `ansible_facts['os_family']`.
|
||||
- `system_baseline_system_type` is required and has no default (the role does not read a global such as `system_type`; map it in the inventory). Valid values: `ubuntu_lxc`, `ubuntu_vm` or `pve`.
|
||||
- Use it by its fully qualified name, `mortis.kamino.system_baseline`.
|
||||
- Collections: `community.general` (locale, timezone) and `ansible.posix` (sysctl, mount).
|
||||
- Collections: `community.general` (locale, timezone) and `ansible.posix` (mount).
|
||||
- Run it after the roles that manage users and SSH, and before the roles that harden services and manage firewalls and jails. A firewall role that rewrites sysctl values (ufw re-applies its stock `/etc/ufw/sysctl.conf` when it is enabled) must run after this role and needs the same values as this role's `sysctl_hardening` to keep them.
|
||||
- Role dependencies: none.
|
||||
|
||||
@@ -43,7 +43,8 @@ templating error instead of the role's own message.
|
||||
| `system_baseline_unattended_upgrade_settings` | from profile | no | Keys for `50unattended-upgrades` |
|
||||
| `system_baseline_unattended_upgrade_origins` | from profile | no | Pinned `Origins-Pattern` entries; `[]` keeps the distribution default (see below) |
|
||||
| `system_baseline_unattended_upgrade_package_blacklist` | `[]` | no | Packages unattended-upgrades must not touch, as regular expressions (see below) |
|
||||
| `system_baseline_sysctl_hardening` | from profile | no | List of `name` and `value` sysctl pairs |
|
||||
| `system_baseline_sysctl_hardening` | from profile | no | List of `name` and `value` sysctl pairs; `*` in a name matches every interface (see "Sysctl hardening") |
|
||||
| `system_baseline_sysctl_file` | `/etc/sysctl.d/99-zz-system-baseline.conf` | no | Drop-in that persists the sysctl pairs: a `.conf` file directly under `/etc/sysctl.d` (see "Sysctl hardening") |
|
||||
| `system_baseline_secure_tmp_mounts` | from profile | no | Paths remounted as tmpfs with `noexec,nosuid,nodev` |
|
||||
| `system_baseline_journal_max_use` | `200M` | no | Upper bound of the persistent journal (journald `SystemMaxUse`): a number with an optional upper-case `B`, `K`, `M`, `G`, `T`, `P` or `E`, such as `1.5G`; a bare number is bytes. journald does not take `infinity`. Empty leaves the host alone and removes nothing a former run wrote (see "Leaving journald alone") |
|
||||
| `system_baseline_tmux_autostart` | `false` | no | Attach interactive SSH logins to a tmux session (`ubuntu_lxc` and `ubuntu_vm` only) |
|
||||
@@ -129,18 +130,19 @@ The two task files besides `main` are a supported interface, for a caller that d
|
||||
|
||||
The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It installs packages from the Ubuntu mirrors, so the runner needs outbound network. It runs `check` before the converge (a fresh host) and after it (a configured host).
|
||||
|
||||
- Verify first checks, on the controller, that the role refuses a bad input with its own message before any change: an unknown `system_baseline_system_type`, an unknown `system_baseline_apt_upgrade` (main flow and `update` entry point), a negative reboot throttle or a negative or boolean post-reboot delay (main flow and `reboot` entry point), a line break in `system_baseline_apt_daily_timeout`, a bad `system_baseline_journal_max_use` (`infinity`, a lower-case unit, a unit with a trailing `B`, a line break, a number), and a bad package blacklist (a quote, a null item, a bare string).
|
||||
- Verify first checks, on the controller, that the role refuses a bad input with its own message before any change: an unknown `system_baseline_system_type`, an unknown `system_baseline_apt_upgrade` (main flow and `update` entry point), a negative reboot throttle or a negative or boolean post-reboot delay (main flow and `reboot` entry point), a line break in `system_baseline_apt_daily_timeout`, a bad `system_baseline_journal_max_use` (`infinity`, a lower-case unit, a unit with a trailing `B`, a line break, a number), a bad `system_baseline_sysctl_file` (`/etc/sysctl.conf`, `99-sysctl.conf`, a path with `..`, a name without `.conf`, empty), and a bad package blacklist (a quote, a null item, a bare string).
|
||||
- Converge applies the `ubuntu_lxc` profile, with tmux autostart and `system_baseline_apt_daily_timeout: 1h`. Verify only resolves the `pve` and `ubuntu_vm` profiles and a consumer override, on the controller, asserting the resolved inputs.
|
||||
- Verify checks the installed and removed packages, the journal size cap, the apt settings in `20auto-upgrades` and `50unattended-upgrades`, the locale, and that systemd loaded the `apt-daily.service` timeout.
|
||||
- Verify checks the tmux snippet: root-owned, valid shell, the session and quoted window command, no effect without a terminal, a session name or window command ending in a newline refused, and the file removed when autostart is off.
|
||||
- Verify refuses bad items in `system_baseline_extra_packages` and `system_baseline_extra_remove_packages` (whitespace, a null, an empty string, a trailing minus, upper case, a bare string) and a package that one input installs and another purges; converge applies the `ubuntu_lxc` profile with `jq` as an extra package and `ed` as an extra removal; verify checks that `jq` is installed, `ed` is gone and the profile's packages are still there, and that an extra `tmux` installs the snippet where a flat list without it installs none.
|
||||
- Verify also checks that a bad `system_baseline_apt_tmpdir` (under `/tmp` or `/var/tmp`, relative, with `..`, empty) is refused in the main flow and in the `update` entry point. It reads `tasks/update.yml` and checks that the scratch directory is created with mode `0700`, that both apt tasks set `TMPDIR` to it, that the connection is reset afterwards, and that the vzdump guard is imported before the upgrade, whose `when` reads the guard's fact: the scenario skips the `update` tag, so the upgrade itself never runs there.
|
||||
- Verify runs the vzdump guard in check mode on the Ubuntu container with `system_baseline_system_type: pve` and a `pvesh` stub, in seven cases (a running, a finished or no vzdump task, the input off, `ubuntu_lxc`); six run the guard's task file alone and the `ubuntu_lxc` case runs the whole `update` entry point. Each case asserts the fact that decides the upgrade and that `pvesh` was run, with `--source active`, only when it should be. It does not assert that the apt task itself was skipped. The stub stands for the real answer, which no CI image has.
|
||||
- Prepare seeds `/etc/sysctl.conf` with keys of the role and other lines. Verify checks that the drop-in holds exactly the profile's keys, that only the role's keys left `/etc/sysctl.conf`, that a key removed from the list leaves the drop-in and that a missing `/etc/sysctl.conf` is not created. It runs the runtime apply on the container's read-only `/proc/sys`: no change for the live value, a reported change in check mode and a failure for a value that cannot be set, each for a plain key and for a `*`, and a failure for a `*` that matches no key.
|
||||
- Verify ends by running the role once with `system_baseline_journal_max_use: ""` after removing the drop-in, and asserts that no drop-in is written and that `systemd-journald` was not restarted.
|
||||
- Verify runs the `reboot` entry point with `system_baseline_reboot_if_required: false`, without and with `/var/run/reboot-required`, and checks the fact and that the host did not reboot.
|
||||
- The `pve` origins pin is applied to the Ubuntu container and read back with `apt-config dump`, then removed again. The package blacklist is written, read back as a list, left alone by a second run and removed by an empty list.
|
||||
|
||||
Not covered: Molecule skips `sysctl`, `secure_tmp`, `update` and `timezone` (no privileged container); see `molecule/default/molecule.yml`. So `system_baseline_update` is checked only for its default; the skip itself is not exercised by a test. No host reboots, and the `pve` profile is not converged: Debian 13 is not verified by a test.
|
||||
Not covered: Molecule skips the sysctl runtime apply in the role run, `secure_tmp`, `update` and `timezone` (no privileged container); see `molecule/default/molecule.yml`. So `system_baseline_update` is checked only for its default; the skip itself is not exercised by a test. No test writes a live sysctl value, runs without IPv6 or reboots to see `systemd-sysctl` load the drop-in. No host reboots, and the `pve` profile is not converged: Debian 13 is not verified by a test.
|
||||
|
||||
## Notes
|
||||
|
||||
@@ -228,6 +230,20 @@ An upgrade of a Proxmox node can restart Proxmox services while a backup holds a
|
||||
|
||||
`system_baseline_journal_max_use: ""` skips the journald task: no drop-in directory, no `50-system-baseline.conf` and no restart of `systemd-journald`. Use it where another drop-in, role or policy owns the journal size. A file an earlier run wrote stays, as for an empty `system_baseline_apt_daily_timeout`; remove it by hand if the cap should go. A value that is not empty and not a size journald reads (`infinity`, `10m`, one with a line break) stops the run before any change, in the same way as the apt-daily value.
|
||||
|
||||
### Sysctl hardening
|
||||
|
||||
The role sets each pair of `system_baseline_sysctl_hardening` on the running kernel when the live value differs, then writes the list to `system_baseline_sysctl_file`, which `systemd-sysctl` loads at boot. A value that cannot be set stops the run before the file is written. `--tags sysctl` does both.
|
||||
|
||||
- Every profile refuses ICMP redirects on every interface: `accept_redirects` is `0` for `all`, `default` and `*` (each interface that exists) over IPv4 and IPv6. `secure_redirects` is `0` for `all` and `default` over IPv4; the kernel reads it only for an interface that accepts redirects. An inventory that overrides the list or a profile's `sysctl_hardening` has to add these keys itself.
|
||||
- A `*` sets every matching key except those with an entry of their own, so `net.ipv4.conf.eth1.accept_redirects` in the list keeps its value. At boot an entry in any other `sysctl.d` file also wins over a `*`. Write names with dots, and a dot in an interface name as a slash: `net.ipv4.conf.eth0/100.accept_redirects`. Use a `*` only for keys with a single-word value, and no two patterns that match the same key.
|
||||
- Without IPv6 in the kernel the role skips the `net.ipv6` keys on the running kernel and still persists them. `systemd-sysctl` ignores them at boot; `sysctl -p` on the drop-in reports them as missing and exits 1.
|
||||
- The role owns the whole drop-in: a key removed from the list leaves the file, and its live value stays until the next reboot. When the list repeats a key, the last entry wins.
|
||||
- At boot the last file that sets a key wins, in the order of the file names. The default sorts after `99-sysctl.conf`, but a name that starts with a letter loads later: for example Proxmox VE's `/usr/lib/sysctl.d/pve-firewall.conf`, which sets `net.ipv4.conf.all.rp_filter`. To override such a file, choose a name that sorts after it.
|
||||
- Changing `system_baseline_sysctl_file` does not remove the old file, which is still loaded at boot; remove it by hand.
|
||||
- The keys of the list are removed from `/etc/sysctl.conf`, where earlier releases of the role wrote them. Other lines stay, including a key that had already been dropped from the list.
|
||||
- ufw applies its own `/etc/ufw/sysctl.conf` when it starts and can override values such as `net.ipv4.conf.all.log_martians`. Set the same values there (`ufw_sysctl_overrides` of the `ufw` role).
|
||||
- A container may not run `systemd-sysctl` at boot (the unit is skipped when `/proc/sys` is read-only). The values then apply only when the role runs.
|
||||
|
||||
### Apt scratch directory
|
||||
|
||||
The upgrade runs over the SSH connection Ansible uses. An `openssh-server` upgrade restarts `ssh.service`, and a unit with `PrivateTmp=yes` (the `systemd_hardening` role sets it) has its own `/tmp` and `/var/tmp`, which systemd deletes when the unit stops. The files apt staged there for the running upgrade then disappear and dpkg fails, leaving packages unpacked but not configured. So the `update` flow creates `system_baseline_apt_tmpdir` (root, mode `0700`), runs the upgrade and the autoremove with `TMPDIR` set to it, and opens a new connection afterwards, so that later tasks get a fresh private `/tmp`.
|
||||
|
||||
@@ -24,6 +24,9 @@ system_baseline_skip_upgrade_during_vzdump: false
|
||||
# Upper bound of the persistent journal (journald SystemMaxUse); older archived files are removed above it. Empty leaves the host alone
|
||||
# (tasks/journald.yml is not run; a drop-in an earlier run wrote stays).
|
||||
system_baseline_journal_max_use: 200M
|
||||
# Drop-in that persists the sysctl hardening (tasks/sysctl.yml). The last file that sets a key wins at boot, so the name sorts after
|
||||
# 99-sysctl.conf. A file whose name starts with a letter still loads later.
|
||||
system_baseline_sysctl_file: /etc/sysctl.d/99-zz-system-baseline.conf
|
||||
# Attach an interactive SSH login to a tmux session (see tasks/tmux.yml). Off by default: it changes what every login does.
|
||||
# Installed only when tmux is among the packages to install: the ubuntu_lxc and ubuntu_vm profiles have it, the pve profile has none unless
|
||||
# system_baseline_extra_packages adds it.
|
||||
@@ -107,7 +110,13 @@ system_baseline_profiles:
|
||||
- { name: "kernel.randomize_va_space", value: 2 }
|
||||
- { name: "net.ipv4.conf.all.accept_source_route", value: 0 }
|
||||
- { name: "net.ipv4.conf.all.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.default.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.*.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.all.secure_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.default.secure_redirects", value: 0 }
|
||||
- { name: "net.ipv6.conf.all.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv6.conf.default.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv6.conf.*.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.icmp_echo_ignore_broadcasts", value: 1 }
|
||||
- { name: "net.ipv4.icmp_ignore_bogus_error_responses", value: 1 }
|
||||
- { name: "net.ipv4.conf.all.log_martians", value: 1 }
|
||||
@@ -170,7 +179,13 @@ system_baseline_profiles:
|
||||
- { name: "net.ipv4.tcp_syncookies", value: 1 }
|
||||
- { name: "net.ipv4.conf.all.accept_source_route", value: 0 }
|
||||
- { name: "net.ipv4.conf.all.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.default.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.*.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.all.secure_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.default.secure_redirects", value: 0 }
|
||||
- { name: "net.ipv6.conf.all.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv6.conf.default.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv6.conf.*.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.icmp_echo_ignore_broadcasts", value: 1 }
|
||||
- { name: "net.ipv4.icmp_ignore_bogus_error_responses", value: 1 }
|
||||
|
||||
@@ -231,7 +246,13 @@ system_baseline_profiles:
|
||||
- { name: "kernel.randomize_va_space", value: 2 }
|
||||
- { name: "net.ipv4.conf.all.accept_source_route", value: 0 }
|
||||
- { name: "net.ipv4.conf.all.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.default.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.*.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.all.secure_redirects", value: 0 }
|
||||
- { name: "net.ipv4.conf.default.secure_redirects", value: 0 }
|
||||
- { name: "net.ipv6.conf.all.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv6.conf.default.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv6.conf.*.accept_redirects", value: 0 }
|
||||
- { name: "net.ipv4.icmp_echo_ignore_broadcasts", value: 1 }
|
||||
- { name: "net.ipv4.icmp_ignore_bogus_error_responses", value: 1 }
|
||||
- { name: "net.ipv4.conf.all.log_martians", value: 1 }
|
||||
@@ -276,4 +297,8 @@ system_baseline_unattended_upgrade_origins: "{{ system_baseline_profile.unattend
|
||||
# package blacklist"). Entries are regular expressions matched against the package name.
|
||||
system_baseline_unattended_upgrade_package_blacklist: []
|
||||
system_baseline_sysctl_hardening: "{{ system_baseline_profile.sysctl_hardening }}"
|
||||
# What the role acts on, as {name: value}. Internal. The last entry of a repeated key wins, and a boolean word becomes the number sysctl takes.
|
||||
__system_baseline_sysctl: >-
|
||||
{{ dict(system_baseline_sysctl_hardening | map(attribute='name') | zip(system_baseline_sysctl_hardening | map(attribute='value') | map('string')
|
||||
| map('regex_replace', '(?i)^(y|yes|on|t|true)$', '1') | map('regex_replace', '(?i)^(n|no|off|f|false)$', '0'))) }}
|
||||
system_baseline_secure_tmp_mounts: "{{ system_baseline_profile.secure_tmp_mounts }}"
|
||||
@@ -60,6 +60,15 @@ argument_specs:
|
||||
is bytes); anything else (C(infinity), a lower-case unit, a line break) is refused before any change. Empty leaves the host
|
||||
alone: no drop-in is written and journald is not restarted.
|
||||
Clearing the value later does not remove a file already written.
|
||||
system_baseline_sysctl_file:
|
||||
type: str
|
||||
default: /etc/sysctl.d/99-zz-system-baseline.conf
|
||||
description:
|
||||
- >-
|
||||
Drop-in that persists C(system_baseline_sysctl_hardening) across reboots. The role owns the whole file. It must be a C(.conf)
|
||||
file directly under C(/etc/sysctl.d), other than C(99-sysctl.conf); anything else is refused before any change.
|
||||
- The last file that sets a key wins at boot, in the order of the file names; a name that starts with a letter sorts after the default.
|
||||
- Changing the value later does not remove the old file.
|
||||
system_baseline_tmux_autostart:
|
||||
type: bool
|
||||
default: false
|
||||
|
||||
@@ -45,9 +45,9 @@ platforms:
|
||||
provisioner:
|
||||
name: ansible
|
||||
options:
|
||||
# sysctl and tmpfs mounts need a privileged container; a full upgrade adds only
|
||||
# time; the timezone needs timedatectl. The rest of the role runs for real.
|
||||
skip-tags: molecule-notest,notest,sysctl,secure_tmp,update,timezone
|
||||
# Applying sysctls (molecule-notest) and tmpfs mounts need a privileged container; a full upgrade
|
||||
# adds only time; the timezone needs timedatectl. The rest of the role runs for real.
|
||||
skip-tags: molecule-notest,notest,secure_tmp,update,timezone
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
---
|
||||
# A package the role must remove, and the locales tool the role assumes exists
|
||||
# (it does on a stock Ubuntu host). jq (system_baseline_extra_packages) must be absent, so that the role is what installs it, and ed
|
||||
# (system_baseline_extra_remove_packages, on no profile list) must be present, so that the role is what purges it.
|
||||
# (system_baseline_extra_remove_packages, on no profile list) must be present, so that the role is what purges it. procps has the sysctl
|
||||
# command verify needs.
|
||||
- name: Prepare
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Install a package on the role's remove list and locale-gen
|
||||
- name: Install packages the role removes and tools it assumes
|
||||
ansible.builtin.apt:
|
||||
name: [telnet, locales, ed]
|
||||
name: [telnet, locales, ed, procps]
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
@@ -16,3 +17,13 @@
|
||||
ansible.builtin.apt:
|
||||
name: jq
|
||||
state: absent
|
||||
|
||||
- name: Seed /etc/sysctl.conf with keys of the role and lines it must leave alone
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/sysctl.conf
|
||||
mode: "0644"
|
||||
content: |
|
||||
# net.ipv4.tcp_syncookies=1
|
||||
net.ipv4.tcp_syncookies=1
|
||||
vm.max_map_count = 262144
|
||||
net.ipv4.conf.all.accept_redirects = 0
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
# One refusal: the role must stop on validation, before it changes anything, with a message that names the variable.
|
||||
- name: Run the role with a bad system_baseline_sysctl_file
|
||||
block:
|
||||
- name: Include system_baseline
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
vars:
|
||||
system_baseline_system_type: ubuntu_lxc
|
||||
system_baseline_sysctl_file: "{{ system_baseline_refused_sysctl_file }}"
|
||||
- name: Unreachable when validation works
|
||||
ansible.builtin.fail:
|
||||
msg: system_baseline ran with an invalid system_baseline_sysctl_file
|
||||
rescue:
|
||||
- name: The validation stopped the play
|
||||
ansible.builtin.assert:
|
||||
that: "'system_baseline_sysctl_file must be' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
@@ -151,6 +151,25 @@
|
||||
- "200M\nStorage=none"
|
||||
- 300
|
||||
|
||||
# The role overwrites the whole drop-in: /etc/sysctl.conf, the link to it, another directory and a name systemd-sysctl does not read
|
||||
# each stop the run before any change.
|
||||
- name: A bad sysctl drop-in path is refused
|
||||
hosts: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Refuse each bad value
|
||||
ansible.builtin.include_tasks: tasks/refuse_sysctl_file.yml
|
||||
vars:
|
||||
system_baseline_refused_sysctl_file: "{{ item }}"
|
||||
loop:
|
||||
- /etc/sysctl.conf
|
||||
- /etc/sysctl.d/99-sysctl.conf
|
||||
- /etc/sysctl.d/../sysctl.conf
|
||||
- /etc/sysctl.d/baseline
|
||||
- ""
|
||||
|
||||
# A quote, a null item and a bare string (not a list) each stop the run: the bare string would otherwise be split into one-character
|
||||
# patterns, and the null item would become an empty pattern that matches every package.
|
||||
- name: A bad package blacklist is refused
|
||||
@@ -818,6 +837,208 @@
|
||||
- {type: pve, input: false, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}]}
|
||||
- {type: ubuntu_lxc, input: true, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}], tasks_from: update}
|
||||
|
||||
# The converge persisted the ubuntu_lxc list and cleaned /etc/sysctl.conf. The rest runs the task files directly: persisting a shorter list
|
||||
# without /etc/sysctl.conf, then the runtime apply against the container's read-only /proc/sys.
|
||||
- name: The sysctl hardening is persisted in its own drop-in
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars:
|
||||
system_baseline_system_type: ubuntu_lxc
|
||||
tasks:
|
||||
- name: Read the drop-in and /etc/sysctl.conf
|
||||
ansible.builtin.command:
|
||||
argv: [cat, "{{ item }}"]
|
||||
loop:
|
||||
- /etc/sysctl.d/99-zz-system-baseline.conf
|
||||
- /etc/sysctl.conf
|
||||
register: system_baseline_verify_sysctl
|
||||
changed_when: false
|
||||
|
||||
- name: The drop-in holds the profile's keys and only they left /etc/sysctl.conf
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_baseline_verify_sysctl.results[0].stdout_lines | reject('match', '#') | list == system_baseline_verify_sysctl_expected
|
||||
- system_baseline_verify_sysctl.results[1].stdout_lines == ['# net.ipv4.tcp_syncookies=1', 'vm.max_map_count = 262144']
|
||||
quiet: true
|
||||
vars:
|
||||
system_baseline_verify_sysctl_expected:
|
||||
- net.ipv4.tcp_syncookies=1
|
||||
- net.ipv4.conf.all.accept_source_route=0
|
||||
- net.ipv4.conf.all.accept_redirects=0
|
||||
- net.ipv4.conf.default.accept_redirects=0
|
||||
- net.ipv4.conf.*.accept_redirects=0
|
||||
- net.ipv4.conf.all.secure_redirects=0
|
||||
- net.ipv4.conf.default.secure_redirects=0
|
||||
- net.ipv6.conf.all.accept_redirects=0
|
||||
- net.ipv6.conf.default.accept_redirects=0
|
||||
- net.ipv6.conf.*.accept_redirects=0
|
||||
- net.ipv4.icmp_echo_ignore_broadcasts=1
|
||||
- net.ipv4.icmp_ignore_bogus_error_responses=1
|
||||
|
||||
- name: Remove /etc/sysctl.conf
|
||||
ansible.builtin.file:
|
||||
path: /etc/sysctl.conf
|
||||
state: absent
|
||||
|
||||
- name: Persist a list that repeats one key
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: sysctl
|
||||
vars:
|
||||
system_baseline_sysctl_hardening:
|
||||
- { name: net.ipv4.tcp_syncookies, value: 0 }
|
||||
- { name: net.ipv4.tcp_syncookies, value: "yes" }
|
||||
|
||||
- name: Read the drop-in again
|
||||
ansible.builtin.command:
|
||||
argv: [cat, /etc/sysctl.d/99-zz-system-baseline.conf]
|
||||
register: system_baseline_verify_sysctl_short
|
||||
changed_when: false
|
||||
|
||||
- name: Stat /etc/sysctl.conf
|
||||
ansible.builtin.stat:
|
||||
path: /etc/sysctl.conf
|
||||
register: system_baseline_verify_sysctl_conf
|
||||
|
||||
- name: Only the last entry is left and /etc/sysctl.conf was not created
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_baseline_verify_sysctl_short.stdout_lines | reject('match', '#') | list == ['net.ipv4.tcp_syncookies=1']
|
||||
- not system_baseline_verify_sysctl_conf.stat.exists
|
||||
quiet: true
|
||||
|
||||
- name: Read a live value
|
||||
ansible.builtin.command:
|
||||
argv: [cat, /proc/sys/net/ipv4/tcp_syncookies]
|
||||
register: system_baseline_verify_sysctl_live
|
||||
changed_when: false
|
||||
|
||||
- name: Apply the value the kernel already has
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: sysctl_apply
|
||||
vars:
|
||||
system_baseline_sysctl_hardening:
|
||||
- { name: net.ipv4.tcp_syncookies, value: "{{ system_baseline_verify_sysctl_live.stdout }}" }
|
||||
|
||||
- name: Nothing was applied
|
||||
ansible.builtin.assert:
|
||||
that: __system_baseline_sysctl_apply is not changed
|
||||
quiet: true
|
||||
|
||||
- name: Preview a different value in check mode
|
||||
check_mode: true
|
||||
block:
|
||||
- name: Include system_baseline, tasks_from sysctl_apply
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: sysctl_apply
|
||||
vars:
|
||||
system_baseline_sysctl_hardening:
|
||||
- { name: net.ipv4.tcp_syncookies, value: "{{ 1 - system_baseline_verify_sysctl_live.stdout | int }}" }
|
||||
|
||||
- name: The pending change is reported
|
||||
ansible.builtin.assert:
|
||||
that: __system_baseline_sysctl_apply is changed
|
||||
quiet: true
|
||||
|
||||
- name: Apply a value that cannot be set
|
||||
block:
|
||||
- name: Include system_baseline, tasks_from sysctl_apply
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: sysctl_apply
|
||||
vars:
|
||||
system_baseline_sysctl_hardening:
|
||||
- { name: net.ipv4.tcp_syncookies, value: "{{ 1 - system_baseline_verify_sysctl_live.stdout | int }}" }
|
||||
- name: Unreachable when a refused value fails
|
||||
ansible.builtin.fail:
|
||||
msg: system_baseline ignored a sysctl that could not be set
|
||||
rescue:
|
||||
- name: The refused write stopped the play
|
||||
ansible.builtin.assert:
|
||||
that: ansible_failed_task.name is search('Apply the sysctl hardening settings')
|
||||
quiet: true
|
||||
|
||||
# The container can inherit the runner host's values. The interfaces share the value of `default`; `all` has its own.
|
||||
- name: Read the live arp_accept values
|
||||
ansible.builtin.command:
|
||||
argv: [cat, /proc/sys/net/ipv4/conf/all/arp_accept, /proc/sys/net/ipv4/conf/default/arp_accept]
|
||||
register: system_baseline_verify_sysctl_arp
|
||||
changed_when: false
|
||||
|
||||
- name: Apply a wildcard value that every interface already has
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: sysctl_apply
|
||||
vars:
|
||||
system_baseline_sysctl_hardening:
|
||||
- { name: net.ipv4.conf.all.arp_accept, value: "{{ system_baseline_verify_sysctl_arp.stdout_lines[0] }}" }
|
||||
- { name: "net.ipv4.conf.*.arp_accept", value: "{{ system_baseline_verify_sysctl_arp.stdout_lines[1] }}" }
|
||||
|
||||
- name: No interface was changed
|
||||
ansible.builtin.assert:
|
||||
that: __system_baseline_sysctl_wildcard_apply is not changed
|
||||
quiet: true
|
||||
|
||||
- name: Preview a different wildcard value in check mode
|
||||
check_mode: true
|
||||
block:
|
||||
- name: Include system_baseline, tasks_from sysctl_apply
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: sysctl_apply
|
||||
vars:
|
||||
system_baseline_sysctl_hardening:
|
||||
- { name: net.ipv4.conf.all.arp_accept, value: "{{ system_baseline_verify_sysctl_arp.stdout_lines[0] }}" }
|
||||
- { name: "net.ipv4.conf.*.arp_accept", value: "{{ (system_baseline_verify_sysctl_arp.stdout_lines[1] == '0') | ternary(1, 0) }}" }
|
||||
|
||||
- name: The pending change covers the interfaces and not the key with its own entry
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __system_baseline_sysctl_wildcard_apply is changed
|
||||
- system_baseline_verify_sysctl_cmd is search('net.ipv4.conf.lo.arp_accept=')
|
||||
- system_baseline_verify_sysctl_cmd is not search('net.ipv4.conf.all.arp_accept=')
|
||||
quiet: true
|
||||
vars:
|
||||
system_baseline_verify_sysctl_cmd: "{{ __system_baseline_sysctl_wildcard_apply.results[0].cmd | join(' ') }}"
|
||||
|
||||
- name: Apply a wildcard value that cannot be set
|
||||
block:
|
||||
- name: Include system_baseline, tasks_from sysctl_apply
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: sysctl_apply
|
||||
vars:
|
||||
system_baseline_sysctl_hardening:
|
||||
- { name: "net.ipv4.conf.*.arp_accept", value: "{{ (system_baseline_verify_sysctl_arp.stdout_lines[1] == '0') | ternary(1, 0) }}" }
|
||||
- name: Unreachable when a refused wildcard value fails
|
||||
ansible.builtin.fail:
|
||||
msg: system_baseline ignored a sysctl wildcard that could not be set
|
||||
rescue:
|
||||
- name: The refused wildcard write stopped the play
|
||||
ansible.builtin.assert:
|
||||
that: ansible_failed_task.name is search('Apply the sysctl wildcards')
|
||||
quiet: true
|
||||
|
||||
- name: Apply a wildcard that matches no key
|
||||
block:
|
||||
- name: Include system_baseline, tasks_from sysctl_apply
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: sysctl_apply
|
||||
vars:
|
||||
system_baseline_sysctl_hardening:
|
||||
- { name: "net.ipv4.conf.*.accept_redirect", value: 0 }
|
||||
- name: Unreachable when a wildcard without a match fails
|
||||
ansible.builtin.fail:
|
||||
msg: system_baseline ignored a sysctl wildcard that matches no key
|
||||
rescue:
|
||||
- name: The wildcard without a match stopped the play
|
||||
ansible.builtin.assert:
|
||||
that: ansible_failed_task.name is search('Read the live values a wildcard matches')
|
||||
quiet: true
|
||||
|
||||
# An empty system_baseline_journal_max_use leaves journald alone: with the drop-in gone, the role neither writes it again nor restarts
|
||||
# systemd-journald. It runs last, because it applies the role with its defaults (the converge's tmux autostart and apt-daily timeout are
|
||||
# not set here) and the checks above read what the converge wrote.
|
||||
|
||||
@@ -38,7 +38,12 @@
|
||||
when: system_baseline_apt_daily_timeout | length > 0
|
||||
tags: apt-daily-timeout
|
||||
|
||||
- name: Harden sysctl
|
||||
# Applied first, so a value the kernel refuses stops the run before it is persisted. molecule's containers have a read-only /proc/sys.
|
||||
- name: Apply the sysctl hardening
|
||||
ansible.builtin.import_tasks: sysctl_apply.yml
|
||||
tags: [sysctl, molecule-notest]
|
||||
|
||||
- name: Persist the sysctl hardening
|
||||
ansible.builtin.import_tasks: sysctl.yml
|
||||
tags: sysctl
|
||||
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
---
|
||||
- name: Apply sysctl hardening settings
|
||||
ansible.posix.sysctl:
|
||||
name: "{{ item.name }}"
|
||||
value: "{{ item.value }}"
|
||||
sysctl_set: true
|
||||
reload: true
|
||||
loop: "{{ system_baseline_sysctl_hardening }}"
|
||||
# Values persist in the role's own drop-in: systemd-sysctl does not read /etc/sysctl.conf on every supported release.
|
||||
- name: Persist the sysctl hardening settings
|
||||
ansible.builtin.template:
|
||||
src: sysctl.conf.j2
|
||||
dest: "{{ system_baseline_sysctl_file }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
become: true
|
||||
|
||||
# Not ansible.posix.sysctl, which rewrites every other line of the file. A missing file is left missing.
|
||||
- name: Remove the role's keys from /etc/sysctl.conf
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/sysctl.conf
|
||||
regexp: '^\s*{{ item | regex_escape }}\s*='
|
||||
state: absent
|
||||
loop: "{{ __system_baseline_sysctl.keys() | list }}"
|
||||
become: true
|
||||
@@ -0,0 +1,73 @@
|
||||
---
|
||||
# Not ansible.posix.sysctl, which always manages a file too. The absolute path is for a PATH without the sbin directories.
|
||||
# A key that cannot be read (unknown or write-only) counts as different, so the write below decides.
|
||||
- name: Read the live sysctl values
|
||||
ansible.builtin.command:
|
||||
argv: [/usr/sbin/sysctl, -e, -n, "{{ item.key }}"]
|
||||
loop: "{{ __system_baseline_sysctl | dict2items | rejectattr('key', 'search', '[*]') }}"
|
||||
register: __system_baseline_sysctl_live
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
check_mode: false
|
||||
become: true
|
||||
|
||||
# The directory is missing when the kernel runs without IPv6; a mistyped IPv6 key still fails when it exists.
|
||||
- name: Check that the kernel has IPv6
|
||||
ansible.builtin.stat:
|
||||
path: /proc/sys/net/ipv6/conf
|
||||
register: __system_baseline_sysctl_ipv6
|
||||
|
||||
# `removes` names a path that always exists: with it, check mode reports the pending write as changed instead of skipping the command.
|
||||
# sysctl exits 0 for a read-only key and only warns (`setting key ...`), so stderr counts too.
|
||||
- name: Apply the sysctl hardening settings
|
||||
ansible.builtin.command:
|
||||
argv: [/usr/sbin/sysctl, -w, "{{ item.item.key }}={{ item.item.value }}"]
|
||||
removes: /proc/sys
|
||||
environment:
|
||||
LC_ALL: C
|
||||
loop: "{{ __system_baseline_sysctl_live.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item.key }}={{ item.item.value }}"
|
||||
when:
|
||||
- item.stdout | default('') | split != item.item.value | split
|
||||
- __system_baseline_sysctl_ipv6.stat.exists or item.item.key is not match('net[.]ipv6[.]')
|
||||
register: __system_baseline_sysctl_apply
|
||||
failed_when: >-
|
||||
__system_baseline_sysctl_apply.rc | default(0) != 0
|
||||
or __system_baseline_sysctl_apply.stderr | default('') is search('setting key')
|
||||
become: true
|
||||
|
||||
# After the plain keys: an interface created from here on inherits the new `default`. A wildcard without a match is a typo, as
|
||||
# an unknown plain key is, unless the kernel has no IPv6. sysctl exits 0 when an interface disappears while it lists them.
|
||||
- name: Read the live values a wildcard matches
|
||||
ansible.builtin.command:
|
||||
argv: [/usr/sbin/sysctl, -a, -e, -r, "^{{ item.key | replace('.', '[.]') | replace('*', '[^.]*') }}$"]
|
||||
loop: "{{ __system_baseline_sysctl | dict2items | selectattr('key', 'search', '[*]') }}"
|
||||
register: __system_baseline_sysctl_wildcard
|
||||
changed_when: false
|
||||
failed_when: >-
|
||||
__system_baseline_sysctl_wildcard.rc != 0
|
||||
or (__system_baseline_sysctl_wildcard.stdout | length == 0
|
||||
and (__system_baseline_sysctl_ipv6.stat.exists or item.key is not match('net[.]ipv6[.]')))
|
||||
check_mode: false
|
||||
become: true
|
||||
|
||||
# A key with its own entry keeps that value, as at boot. -e skips an interface that is gone, unless it goes during the write itself.
|
||||
- name: Apply the sysctl wildcards
|
||||
ansible.builtin.command:
|
||||
argv: "{{ ['/usr/sbin/sysctl', '-e', '-w'] + (__system_baseline_sysctl_pending | product([item.item.value]) | map('join', '=')) }}"
|
||||
removes: /proc/sys
|
||||
environment:
|
||||
LC_ALL: C
|
||||
vars:
|
||||
__system_baseline_sysctl_pending: >-
|
||||
{{ item.stdout_lines | reject('search', ' = ' ~ (item.item.value | regex_escape) ~ '$')
|
||||
| map('regex_replace', ' = .*', '') | difference(__system_baseline_sysctl.keys() | list) }}
|
||||
loop: "{{ __system_baseline_sysctl_wildcard.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item.key }}={{ item.item.value }}"
|
||||
when: __system_baseline_sysctl_pending | length > 0
|
||||
register: __system_baseline_sysctl_wildcard_apply
|
||||
failed_when: >-
|
||||
__system_baseline_sysctl_wildcard_apply.stderr_lines | default([]) | reject('search', 'No such file or directory') | length > 0
|
||||
become: true
|
||||
@@ -62,6 +62,18 @@
|
||||
quiet: true
|
||||
tags: always
|
||||
|
||||
# The role owns the whole file, and systemd-sysctl reads only *.conf. 99-sysctl.conf can be the distribution's link to /etc/sysctl.conf.
|
||||
- name: Validate the sysctl drop-in path
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_baseline_sysctl_file is match('^/etc/sysctl\.d/[A-Za-z0-9_][A-Za-z0-9._-]*\.conf\Z')
|
||||
- system_baseline_sysctl_file != '/etc/sysctl.d/99-sysctl.conf'
|
||||
fail_msg: >-
|
||||
system_baseline_sysctl_file must be a .conf file directly under /etc/sysctl.d (letters, digits, . _ and - in the name), other than
|
||||
99-sysctl.conf.
|
||||
quiet: true
|
||||
tags: always
|
||||
|
||||
# The value is written into a unit file: one line, starting with a digit, so no line break can add a second directive. systemd itself
|
||||
# refuses a value it cannot parse (it ignores the setting and logs it).
|
||||
- name: Validate the apt-daily start timeout
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# Managed by Ansible (mortis.kamino.system_baseline, tasks/sysctl.yml). Do not edit: the next run overwrites it.
|
||||
{% for name, value in __system_baseline_sysctl.items() %}
|
||||
{{ name }}={{ value }}
|
||||
{% endfor %}
|
||||
+6
-3
@@ -29,6 +29,7 @@ Main entry point:
|
||||
| `ufw_manage_rules` | `true` | no | Skip the `ufw_rules` schema check, the lock-out guard and rule application when false. Before-rules validation and `before.rules`, defaults and enable still run (gated on `ufw_enabled`). |
|
||||
| `ufw_defaults` | `incoming: deny`, `outgoing: allow`, `routed: deny` | no | Default policies. All three keys are read, so override all of them. |
|
||||
| `ufw_logging` | `"on"` | no | UFW logging level. |
|
||||
| `ufw_mask_nftables` | `true` | no | Mask `nftables.service` without stopping it, so a package upgrade cannot flush the rules ufw loaded (see Notes). Set false on a host that loads its own ruleset through that unit. Gated on `ufw_enabled`. |
|
||||
| `ufw_require_ssh_allow` | `true` | no | Enable the SSH lock-out guard. |
|
||||
| `ufw_ssh_port` | `ansible_port` or 22 | no | TCP port the guard looks for. |
|
||||
| `ufw_rules` | `[]` | no | Base rule list: `rule` (allow, deny, reject, limit), `port`, `proto`, `from`, `to`, `interface`, `direction`, `comment`, `delete` (see Notes). |
|
||||
@@ -45,7 +46,7 @@ There is no discovery by variable name, and a variable that looks like one fails
|
||||
|
||||
### `service_rules`
|
||||
|
||||
A service role that owns firewall rules calls the role with `include_role` and `tasks_from: service_rules` after the main entry has run, with `apply: {tags: [...]}` so `--tags <role>` reaches these tasks. The entry point installs nothing and touches no default policy, no `before.rules` and no base rule. Outside check mode (`--check` or the `check_mode` keyword; the role detects it with a skipped probe task, not `ansible_check_mode`) it fails when ufw is not installed and active. In check mode it skips the reconcile only when `ufw status` fails (ufw not installed yet, the main entry may not have reached the host); a host with ufw installed but inactive is reconciled as usual.
|
||||
A service role that owns firewall rules calls the role with `include_role` and `tasks_from: service_rules` after the main entry has run, with `apply: {tags: [...]}` so `--tags <role>` reaches these tasks. The entry point installs nothing and touches no default policy, no `before.rules` and no base rule. Outside check mode (`--check` or the `check_mode` keyword; the role detects it with a probe command that does not run there, not `ansible_check_mode`) it fails when ufw is not installed and active. In check mode it skips the reconcile only when `ufw status` fails (ufw not installed yet, the main entry may not have reached the host); a host with ufw installed but inactive is reconciled as usual.
|
||||
|
||||
| Variable | Default | Required | Description |
|
||||
|---|---|---|---|
|
||||
@@ -117,7 +118,7 @@ An **orphan** is a rule tagged `ansible-ufw[<owner>:<key>]` whose owner is neith
|
||||
|
||||
## Tags
|
||||
|
||||
`ufw` (everything), `ufw_install`, `ufw_sysctl`, `ufw_aggregate`, `ufw_validate`, `ufw_before_rules`, `ufw_defaults`, `ufw_rules`, `ufw_enable`.
|
||||
`ufw` (everything), `ufw_install`, `ufw_sysctl`, `ufw_aggregate`, `ufw_validate`, `ufw_nftables`, `ufw_before_rules`, `ufw_defaults`, `ufw_rules`, `ufw_enable`.
|
||||
|
||||
Skipping `ufw_aggregate` leaves the lists the later tasks read (`ufw_aggregated_rules`, `ufw_aggregated_before_rules`) undefined or stale, so do not select a later tag alone.
|
||||
|
||||
@@ -144,10 +145,11 @@ The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_
|
||||
- Verify then reads `ufw status verbose` and `ufw show added`: ufw is active with default deny incoming, the base rules are loaded, the deleted rule is gone, the manual and SSH rules are untouched, the service rules carry their owner tag, stale and orphan rules are deleted only where purging was on and only when they cannot carry SSH.
|
||||
- Verify checks `before.rules`: the loopback accept, the INVALID-state drop behind its logging rule and in its place among the input rules.
|
||||
- Verify runs `service_rules` under the `check_mode` keyword and checks that the rule list did not change.
|
||||
- Verify checks the nftables mask: prepare installs `nftables`, enables and starts its unit; after the converge the unit is masked and still active, ufw's chains survive `apt-get install --reinstall nftables` (whose postinst runs the upgrade restart), the same reinstall with the mask removed flushes them (the control), and after the package is purged and the mask removed the role masks the absent unit again without failing.
|
||||
|
||||
The scenario `molecule/check-absent/` runs on the same two platforms: prepare purges ufw and refreshes the APT cache, then `check` runs the main entry point and `service_rules` under `--check`, which must pass with ufw not installed. Nothing is applied.
|
||||
|
||||
Not covered: `ufw_before_rules` entries and `ufw_sysctl_overrides` are never set, and `orphan_rules` runs in check mode only under `--check` (the `check` steps), not under the `check_mode` keyword.
|
||||
Not covered: `ufw_mask_nftables: false` is never set, `ufw_before_rules` entries and `ufw_sysctl_overrides` are never set, and `orphan_rules` runs in check mode only under `--check` (the `check` steps), not under the `check_mode` keyword.
|
||||
|
||||
## Notes
|
||||
|
||||
@@ -158,5 +160,6 @@ Not covered: `ufw_before_rules` entries and `ufw_sysctl_overrides` are never set
|
||||
- Rule schema is asserted before anything changes: `rule` must be allow, deny, reject or limit, `port` a positive integer, `proto` tcp or udp, and each rule needs `port`, `from`, `to` or `interface`.
|
||||
- UFW is only re-enabled when `ufw status verbose` shows it inactive or the logging line differs, because the module rewrites rules and re-applies sysctl on every call.
|
||||
- The `Reload UFW` handler runs `ufw reload`.
|
||||
- nftables: when `nftables.service` is enabled (a preset can do that), the `nftables` package's postinst restarts it on upgrade (`dh_installsystemd --no-enable --no-start --restart-after-upgrade` emits `deb-systemd-invoke try-restart`), and both the restart and the unit's `ExecStop=/usr/sbin/nft flush ruleset` delete every rule ufw (and Docker) loaded, since the stock `/etc/nftables.conf` begins with `flush ruleset`. The role masks the unit and does not stop it, so nothing is flushed during the run. systemd refuses every job but a stop on a masked unit, so the postinst's restart fails before anything runs and the postinst ignores the failure (`|| true`); at boot the unit is not started either. The mask also applies when the unit or the package is absent, so a later install cannot enable it; the package's postinst removes only a mask its own helper created. The role never unmasks: with `ufw_mask_nftables: false` or `ufw_enabled: false` an existing mask stays. `--check` reports the mask without applying it. When `/etc/systemd/system/nftables.service` is a unit file of its own rather than a link, `systemctl mask` refuses with "already exists" and the play fails; set `ufw_mask_nftables: false` on such a host.
|
||||
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. On a host without ufw the preview reports the install and skips the configuration (`before.rules`, default policies, rules, enable), which needs the `ufw` binary.
|
||||
- `no_log` is not used: the role handles no secrets.
|
||||
@@ -9,6 +9,10 @@ ufw_defaults:
|
||||
|
||||
ufw_logging: "on"
|
||||
|
||||
# Mask nftables.service (not stopped), so a restart by a package upgrade cannot flush the rules
|
||||
# ufw loaded. false: leave the unit alone, for hosts that load their own ruleset through it.
|
||||
ufw_mask_nftables: true
|
||||
|
||||
# Lock-out guard: with a deny/reject incoming default the play refuses to run
|
||||
# unless an allow/limit rule for this TCP port is in the rule list, since the
|
||||
# default is applied before the rules and a missing rule cuts the SSH session.
|
||||
|
||||
@@ -49,6 +49,18 @@ argument_specs:
|
||||
choices: ["on", "off", low, medium, high, full]
|
||||
description:
|
||||
- UFW logging setting. UFW is only re-enabled when it is inactive or its current logging line differs from this value.
|
||||
ufw_mask_nftables:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- >-
|
||||
When true (and C(ufw_enabled) is true) C(nftables.service) is masked, without being stopped, also when the
|
||||
unit or the C(nftables) package is absent. A restart of the enabled unit, which the package runs on upgrade,
|
||||
loads the stock C(/etc/nftables.conf) that begins with C(flush ruleset), and its stop flushes the ruleset,
|
||||
which deletes the rules ufw loaded. A masked unit is never started, also not at boot.
|
||||
- >-
|
||||
Set false on hosts that load their own ruleset through C(nftables.service). The role never unmasks the unit,
|
||||
so switching to false leaves an existing mask in place.
|
||||
ufw_require_ssh_allow:
|
||||
type: bool
|
||||
default: true
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
# svc_o2 that looks like the SSH rule, and a rule of svc_m. The managed owners below are
|
||||
# the ones used above plus svc_m (listed but never called), so svc_o1 and svc_o2 are
|
||||
# orphans. The cases that must change nothing run first and the purge last, so the
|
||||
# idempotence run finds nothing left to delete. Under --check the role's own skipped probe
|
||||
# idempotence run finds nothing left to delete. Under --check the role's own check-mode probe
|
||||
# keeps the purge from deleting, and orphan_check.yml skips its counts.
|
||||
- name: Report and purge the rules of unmanaged owners
|
||||
hosts: all
|
||||
|
||||
@@ -84,3 +84,40 @@
|
||||
- {port: "40:50", comment: "ansible-ufw[svc_c:6666666663]: range"}
|
||||
loop_control:
|
||||
loop_var: ufw_prepare_rule
|
||||
|
||||
# An enabled, active nftables.service with the stock /etc/nftables.conf, as a preset leaves
|
||||
# it; verify.yml checks that the role's mask keeps a package upgrade from flushing ufw's rules.
|
||||
- name: Install nftables
|
||||
ansible.builtin.apt:
|
||||
name: nftables
|
||||
state: present
|
||||
|
||||
# A policy-rc.d that refuses actions would make the postinst skip the restart verify.yml tests.
|
||||
- name: Let maintainer scripts act on units as on a host
|
||||
ansible.builtin.file:
|
||||
path: /usr/sbin/policy-rc.d
|
||||
state: absent
|
||||
|
||||
# ProtectSystem and ProtectHome need a mount namespace, which needs CAP_SYS_ADMIN; without
|
||||
# it the unit fails with 226/NAMESPACE in this unprivileged container.
|
||||
- name: Create the drop-in directory of nftables.service
|
||||
ansible.builtin.file:
|
||||
path: /etc/systemd/system/nftables.service.d
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: Disable the namespace-based sandboxing of nftables.service for the container
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/systemd/system/nftables.service.d/molecule.conf
|
||||
mode: "0644"
|
||||
content: |
|
||||
[Service]
|
||||
ProtectSystem=no
|
||||
ProtectHome=no
|
||||
|
||||
- name: Enable and start nftables.service
|
||||
ansible.builtin.systemd_service:
|
||||
name: nftables.service
|
||||
enabled: true
|
||||
state: started
|
||||
daemon_reload: true
|
||||
@@ -474,8 +474,8 @@
|
||||
# apply of community.general.ufw reports changed for the would-be rule, so molecule's
|
||||
# idempotence run (a second converge) would fail on it. Verify runs once, outside that count.
|
||||
# The play runs under the check_mode keyword, which does not set ansible_check_mode in the
|
||||
# included role; the role detects check mode with a probe task instead (a command task is
|
||||
# skipped under the keyword). A present call that would add a rule and an absent call for an
|
||||
# included role; the role detects check mode with a probe task instead (a command does
|
||||
# not run under the keyword). A present call that would add a rule and an absent call for an
|
||||
# owner that holds rules must change nothing. The two reads of the rule list are forced to
|
||||
# run (check_mode: false) and compared as a whole.
|
||||
- name: Check mode of service_rules changes nothing
|
||||
@@ -521,3 +521,110 @@
|
||||
- ufw_verify_chk_after.stdout_lines == ufw_verify_chk_before.stdout_lines
|
||||
- ufw_verify_chk_after.stdout_lines | select('search', 'svc_chk|7701') | list | length == 0
|
||||
quiet: true
|
||||
|
||||
# prepare.yml left nftables.service enabled and active. The package's postinst runs
|
||||
# `deb-systemd-invoke try-restart nftables.service` on upgrade (and on a reinstall, which passes
|
||||
# the old version too); the stock config and ExecStop flush the ruleset. The masked case runs
|
||||
# first, then a control without the mask proves the reinstall reaches the unit here, then the
|
||||
# absent-package case. Last, because the control flushes ufw's rules.
|
||||
- name: The nftables mask keeps a package upgrade from flushing the rules
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars:
|
||||
ufw_verify_nft_reinstall:
|
||||
- apt-get
|
||||
- install
|
||||
- --reinstall
|
||||
- -y
|
||||
- -o
|
||||
- Dpkg::Options::=--force-confold
|
||||
- nftables
|
||||
tasks:
|
||||
# A mask request in check mode changes nothing and returns the unit's properties.
|
||||
- name: Read the state of nftables.service
|
||||
ansible.builtin.systemd_service:
|
||||
name: nftables.service
|
||||
masked: true
|
||||
check_mode: true
|
||||
register: ufw_verify_nft_unit
|
||||
|
||||
- name: The role masked the unit and did not stop it
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ufw_verify_nft_unit is not changed
|
||||
- ufw_verify_nft_unit.status.LoadState == 'masked'
|
||||
- ufw_verify_nft_unit.status.ActiveState == 'active'
|
||||
quiet: true
|
||||
|
||||
- name: Reinstall nftables while the unit is masked
|
||||
ansible.builtin.command:
|
||||
argv: "{{ ufw_verify_nft_reinstall }}"
|
||||
environment: {DEBIAN_FRONTEND: noninteractive}
|
||||
changed_when: true
|
||||
|
||||
- name: Read the iptables rules after the masked reinstall
|
||||
ansible.builtin.command: iptables -S
|
||||
register: ufw_verify_nft_masked_rules
|
||||
changed_when: false
|
||||
|
||||
- name: The rules of ufw survived the reinstall
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ufw_verify_nft_masked_rules.stdout_lines | select('search', '^-N ufw-user-input$') | list | length == 1
|
||||
- ufw_verify_nft_masked_rules.stdout_lines | select('search', '^-A ufw-user-input .*--dport 22 ') | list | length > 0
|
||||
quiet: true
|
||||
|
||||
- name: Remove the mask for the control case
|
||||
ansible.builtin.systemd_service:
|
||||
name: nftables.service
|
||||
masked: false
|
||||
|
||||
- name: Reinstall nftables while the unit is enabled and active
|
||||
ansible.builtin.command:
|
||||
argv: "{{ ufw_verify_nft_reinstall }}"
|
||||
environment: {DEBIAN_FRONTEND: noninteractive}
|
||||
changed_when: true
|
||||
|
||||
- name: Read the iptables rules after the unmasked reinstall
|
||||
ansible.builtin.command: iptables -S
|
||||
register: ufw_verify_nft_unmasked_rules
|
||||
changed_when: false
|
||||
|
||||
- name: Without the mask the reinstall flushed the rules of ufw
|
||||
ansible.builtin.assert:
|
||||
that: ufw_verify_nft_unmasked_rules.stdout_lines | select('search', '^-N ufw-user-input$') | list | length == 0
|
||||
quiet: true
|
||||
|
||||
- name: Purge nftables
|
||||
ansible.builtin.apt:
|
||||
name: nftables
|
||||
state: absent
|
||||
purge: true
|
||||
|
||||
- name: Read the state of nftables.service with the package gone
|
||||
ansible.builtin.systemd_service:
|
||||
name: nftables.service
|
||||
masked: true
|
||||
check_mode: true
|
||||
register: ufw_verify_nft_gone
|
||||
|
||||
- name: Run the role on a host without the nftables package
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
vars:
|
||||
ufw_rules:
|
||||
- {rule: allow, port: 22, proto: tcp, comment: ssh}
|
||||
|
||||
- name: Read the state of nftables.service after the role
|
||||
ansible.builtin.systemd_service:
|
||||
name: nftables.service
|
||||
masked: true
|
||||
check_mode: true
|
||||
register: ufw_verify_nft_absent
|
||||
|
||||
- name: The role masked the absent unit without failing
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ufw_verify_nft_gone is changed
|
||||
- ufw_verify_nft_absent is not changed
|
||||
quiet: true
|
||||
@@ -6,10 +6,10 @@
|
||||
state: present
|
||||
register: __ufw_install
|
||||
|
||||
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set it inside
|
||||
# include_role tasks. A command task is skipped in both forms, the same probe as tasks/sysctl.yml.
|
||||
# Not ansible_check_mode, which the play-level `check_mode: true` keyword does not set in include_role
|
||||
# tasks, nor `is skipped`, which ansible-core 2.25 drops: the probe's stdout is empty in check mode.
|
||||
- name: Probe whether the run is in check mode
|
||||
ansible.builtin.command: "true"
|
||||
ansible.builtin.command: echo ran
|
||||
register: __ufw_install_probe
|
||||
changed_when: false
|
||||
|
||||
@@ -17,4 +17,4 @@
|
||||
# Undefined when this file's tags are skipped; the guards then default it to true.
|
||||
- name: Remember whether ufw can be configured
|
||||
ansible.builtin.set_fact:
|
||||
__ufw_can_configure: "{{ __ufw_install is not changed or __ufw_install_probe is not skipped }}"
|
||||
__ufw_can_configure: "{{ __ufw_install is not changed or __ufw_install_probe.stdout == 'ran' }}"
|
||||
@@ -35,6 +35,10 @@
|
||||
ansible.builtin.import_tasks: validate.yml
|
||||
tags: [ufw, ufw_validate]
|
||||
|
||||
- name: Import UFW nftables task
|
||||
ansible.builtin.import_tasks: nftables.yml
|
||||
tags: [ufw, ufw_nftables]
|
||||
|
||||
- name: Import UFW before rules task
|
||||
ansible.builtin.import_tasks: before_rules.yml
|
||||
tags: [ufw, ufw_before_rules]
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
# A restart of nftables.service (on a package upgrade) flushes the rules ufw loaded. Mask only:
|
||||
# a stop would flush them now. README Notes has the detail.
|
||||
- name: Mask nftables.service without stopping it
|
||||
become: true
|
||||
ansible.builtin.systemd_service:
|
||||
name: nftables.service
|
||||
masked: true
|
||||
when:
|
||||
- ufw_enabled
|
||||
- ufw_mask_nftables
|
||||
@@ -63,17 +63,16 @@
|
||||
the rule tags): {{ ufw_managed_owners }}
|
||||
quiet: true
|
||||
|
||||
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set
|
||||
# that magic variable inside include_role tasks (only --check does). A command task is
|
||||
# skipped in both forms and its result says so, which is the one signal that holds for both.
|
||||
# Not ansible_check_mode, which the play-level `check_mode: true` keyword does not set in include_role
|
||||
# tasks, nor `is skipped`, which ansible-core 2.25 drops: the probe's stdout is empty in check mode.
|
||||
- name: Probe whether the run is in check mode
|
||||
ansible.builtin.command: "true"
|
||||
ansible.builtin.command: echo ran
|
||||
register: ufw_oa_probe
|
||||
changed_when: false
|
||||
|
||||
- name: Remember whether the run is in check mode
|
||||
ansible.builtin.set_fact:
|
||||
ufw_oa_check: "{{ ufw_oa_probe is skipped }}"
|
||||
ufw_oa_check: "{{ ufw_oa_probe.stdout != 'ran' }}"
|
||||
|
||||
- name: Read the firewall status
|
||||
become: true
|
||||
|
||||
@@ -121,17 +121,16 @@
|
||||
- ufw_manage_rules
|
||||
tags: [ufw, ufw_service_rules]
|
||||
block:
|
||||
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set
|
||||
# that magic variable inside include_role tasks (only --check does). A command task is
|
||||
# skipped in both forms and its result says so, which is the one signal that holds for both.
|
||||
# Not ansible_check_mode, which the play-level `check_mode: true` keyword does not set in include_role
|
||||
# tasks, nor `is skipped`, which ansible-core 2.25 drops: the probe's stdout is empty in check mode.
|
||||
- name: Probe whether the run is in check mode
|
||||
ansible.builtin.command: "true"
|
||||
ansible.builtin.command: echo ran
|
||||
register: ufw_sr_probe
|
||||
changed_when: false
|
||||
|
||||
- name: Remember whether the run is in check mode
|
||||
ansible.builtin.set_fact:
|
||||
ufw_sr_check: "{{ ufw_sr_probe is skipped }}"
|
||||
ufw_sr_check: "{{ ufw_sr_probe.stdout != 'ran' }}"
|
||||
|
||||
- name: Read the firewall status
|
||||
become: true
|
||||
|
||||
@@ -7,18 +7,17 @@
|
||||
check_mode: false
|
||||
when: ufw_enabled and ufw_sysctl_overrides | length > 0
|
||||
|
||||
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set that
|
||||
# magic variable inside include_role tasks (only --check does). A command task
|
||||
# is skipped in both forms and its result says so, the same probe as tasks/service_rules.yml.
|
||||
# Not ansible_check_mode, which the play-level `check_mode: true` keyword does not set in include_role
|
||||
# tasks, nor `is skipped`, which ansible-core 2.25 drops: the probe's stdout is empty in check mode.
|
||||
- name: Probe whether the run is in check mode
|
||||
ansible.builtin.command: "true"
|
||||
ansible.builtin.command: echo ran
|
||||
register: ufw_sysctl_probe
|
||||
changed_when: false
|
||||
when: ufw_enabled and ufw_sysctl_overrides | length > 0
|
||||
|
||||
- name: Remember whether the run is in check mode
|
||||
ansible.builtin.set_fact:
|
||||
ufw_sysctl_check: "{{ ufw_sysctl_probe is skipped }}"
|
||||
ufw_sysctl_check: "{{ ufw_sysctl_probe.stdout != 'ran' }}"
|
||||
when: ufw_enabled and ufw_sysctl_overrides | length > 0
|
||||
|
||||
# In check mode on a fresh host ufw is not installed yet, so the file is absent.
|
||||
|
||||
@@ -19,7 +19,7 @@ cd "$root"
|
||||
|
||||
for tool in ansible ansible-test; do
|
||||
if ! command -v "$tool" >/dev/null 2>&1; then
|
||||
echo "error: $tool is not on PATH; run scripts/dev-setup.sh and use its virtualenv (.venv/bin)" >&2
|
||||
echo "error: $tool is not on PATH; run scripts/dev-setup.sh and use its virtualenv (.venv-dev/bin)" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -12,6 +12,10 @@ When <head-ref> starts with `renovate/`, the diff of <base-ref>...HEAD may only
|
||||
`name==version` entries, `--hash=sha256:<64 hex>` lines and plain `# via` or prose comments,
|
||||
nothing else; packages may be added or removed (a transitive dependency), but the
|
||||
`# pip-compile ...` command in the header, which Renovate runs again, must stay as it is;
|
||||
* pyproject.toml: the version of a quoted `"name==version"` pin (the names, spelled as they
|
||||
are, and every other line, stay), only together with uv.lock;
|
||||
* uv.lock: the apm-cli bump to the pin of the new pyproject.toml, and nothing else
|
||||
(check_uv_lock.py), only together with pyproject.toml;
|
||||
* requirements.yml and extensions/molecule/requirements.yml: `version:` lines (the collection
|
||||
names, and every other line, stay);
|
||||
* .pre-commit-config.yaml: `rev:` lines (a tag, or a commit SHA with its `# frozen: <tag>` comment);
|
||||
@@ -50,6 +54,7 @@ import re
|
||||
import sys
|
||||
|
||||
import check_image_versions as civ
|
||||
import check_uv_lock
|
||||
|
||||
PREFIX = "renovate/"
|
||||
TAG = r"[A-Za-z0-9._-]+"
|
||||
@@ -73,6 +78,7 @@ COLLECTION_PINS = {"requirements.yml", "extensions/molecule/requirements.yml"}
|
||||
# Lint's and the molecule-controller image's requirements, each with its pip-compile lock.
|
||||
REQUIREMENTS = {"requirements-dev.txt", "requirements-molecule.txt"}
|
||||
LOCKS = {"requirements-dev.lock", "requirements-molecule.lock"}
|
||||
UV_LOCK = "uv.lock"
|
||||
CONSUMERS = {
|
||||
".gitea/workflows/lint.yml",
|
||||
".gitea/workflows/build.yml",
|
||||
@@ -144,6 +150,16 @@ def lock_problem(removed, added):
|
||||
return None
|
||||
|
||||
|
||||
# A quoted `name==version` pin in a pyproject.toml dependency array.
|
||||
PYPROJECT_PIN = re.compile(r'"([A-Za-z0-9][A-Za-z0-9._-]*)==[0-9][0-9A-Za-z.+!_-]*"')
|
||||
|
||||
|
||||
def reduce_pyproject(line):
|
||||
if not PYPROJECT_PIN.search(line):
|
||||
return None
|
||||
return PYPROJECT_PIN.sub(lambda m: f'"{m[1]}==X"', line)
|
||||
|
||||
|
||||
def reduce_rev(line):
|
||||
return "rev" if REV_LINE.match(line) else None
|
||||
|
||||
@@ -178,6 +194,10 @@ def file_problem(path, removed, added):
|
||||
)
|
||||
if path in LOCKS:
|
||||
return lock_problem(removed, added)
|
||||
if path == "pyproject.toml":
|
||||
return same_shape(
|
||||
removed, added, reduce_pyproject, "a quoted `name==version` pin"
|
||||
)
|
||||
if path in COLLECTION_PINS:
|
||||
return same_shape(removed, added, reduce_version, "a `version:` line")
|
||||
if path == ".pre-commit-config.yaml":
|
||||
@@ -254,15 +274,22 @@ def moved_problem(removed, added):
|
||||
return None
|
||||
|
||||
|
||||
def check(entries, patch_of):
|
||||
"""One message per offending file; patch_of(path) returns that file's -U0 patch text."""
|
||||
def check(entries, patch_of, show=None):
|
||||
"""One message per offending file; patch_of(path) returns that file's -U0 patch text and
|
||||
show(side, path) its text on the "base" or "head" side (needed for uv.lock)."""
|
||||
problems = []
|
||||
# The pin and its lock move together, so neither can change what the other one locks.
|
||||
partners = {"pyproject.toml": UV_LOCK, UV_LOCK: "pyproject.toml"}
|
||||
paths = {path for unused, unused, unused, path in entries}
|
||||
for old_mode, new_mode, status, path in entries:
|
||||
if status != "M" or old_mode != new_mode or new_mode != "100644":
|
||||
problems.append(
|
||||
f"{path}: a bot pull request may not add, delete, rename or change the mode of a file"
|
||||
)
|
||||
continue
|
||||
if path in partners and partners[path] not in paths:
|
||||
problems.append(f"{path}: changes without {partners[path]}")
|
||||
continue
|
||||
patch = patch_of(path)
|
||||
if BINARY.search(patch):
|
||||
problems.append(
|
||||
@@ -276,9 +303,22 @@ def check(entries, patch_of):
|
||||
f"{len(removed)} removed and {len(added)} added (binary or empty change?)"
|
||||
)
|
||||
continue
|
||||
reason = file_problem(
|
||||
path, [line for unused, line in removed], [line for unused, line in added]
|
||||
)
|
||||
if path == UV_LOCK:
|
||||
reason = (
|
||||
check_uv_lock.lock_problem(
|
||||
show("base", path),
|
||||
show("head", path),
|
||||
show("head", "pyproject.toml"),
|
||||
)
|
||||
if show
|
||||
else "is not a file a bot pull request may change"
|
||||
)
|
||||
else:
|
||||
reason = file_problem(
|
||||
path,
|
||||
[line for unused, line in removed],
|
||||
[line for unused, line in added],
|
||||
)
|
||||
if not reason and path == civ.MATRIX_FILE:
|
||||
reason = moved_problem(removed, added)
|
||||
if reason:
|
||||
@@ -336,8 +376,14 @@ def run(argv):
|
||||
path,
|
||||
)
|
||||
|
||||
def show(side, path):
|
||||
rev = base if side == "base" else "HEAD"
|
||||
return civ.git("cat-file", "blob", f"{rev}:{path}")
|
||||
|
||||
entries = parse_raw(raw)
|
||||
return check(entries, patch_of), f"{len(entries)} file(s) within the bot allowance"
|
||||
return check(
|
||||
entries, patch_of, show
|
||||
), f"{len(entries)} file(s) within the bot allowance"
|
||||
|
||||
|
||||
def main(argv):
|
||||
|
||||
@@ -27,7 +27,7 @@ allow list. It fails the build for:
|
||||
ansible-galaxy dereferences FILE symlinks while building, so a symlink to a file reaches
|
||||
the archive as a regular file with the target's content and this check cannot see it. The
|
||||
`Refuse symlinks in the source tree` step of .gitea/workflows/build.yml is the only guard
|
||||
against that. Its `find` prunes ./.venv and ./.git only because both are in galaxy.yml
|
||||
against that. Its `find` prunes ./.git, ./.venv and ./.venv-dev only because they are in galaxy.yml
|
||||
`build_ignore` (or excluded by ansible-galaxy itself, as .git is): the two lists must stay
|
||||
in step, and tests/scripts/test_check_tarball.py fails when a pruned directory is not
|
||||
ignored by the build.
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
# SPDX-FileCopyrightText: Defame1297 and contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""The uv.lock rule of check_bot_pr_diff.py: a bot may move apm-cli to its pin, nothing else.
|
||||
|
||||
Both locks are parsed. The top level stays as it is, except `revision`. The same packages are
|
||||
locked, and every one but apm-cli and the root project is unchanged. The root project changes
|
||||
only its apm-cli specifier, to the pin in pyproject.toml. apm-cli changes only its version, up
|
||||
to that pin, and its files: the same kinds (an sdist if it had one, the same wheel tags), each
|
||||
on PyPI's download host, named for apm-cli at the pin, by sha256. Versions are plain releases
|
||||
compared as numbers. A bump that moves anything else fails, and a person makes it by hand.
|
||||
"""
|
||||
|
||||
import copy
|
||||
import re
|
||||
import tomllib
|
||||
import urllib.parse
|
||||
|
||||
PACKAGE = "apm-cli"
|
||||
REGISTRY = {"registry": "https://pypi.org/simple"}
|
||||
ROOT_SOURCE = {"virtual": "."}
|
||||
FILE_KEYS = {"url", "hash", "size", "upload-time"}
|
||||
SHA256 = re.compile(r"sha256:[0-9a-f]{64}")
|
||||
PIN = re.compile(rf"{re.escape(PACKAGE)}==([0-9][0-9A-Za-z.+!_-]*)")
|
||||
# A plain release; pre-, post- and dev-releases, epochs and local versions are bumped by hand.
|
||||
RELEASE = re.compile(r"[0-9]+(?:\.[0-9]+)*")
|
||||
DIST = re.sub(r"[-_.]+", "_", PACKAGE).lower()
|
||||
|
||||
|
||||
class Refused(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def parse(text, what):
|
||||
try:
|
||||
return tomllib.loads(text)
|
||||
except tomllib.TOMLDecodeError as exc:
|
||||
raise Refused(f"{what} is not valid TOML ({exc})") from None
|
||||
|
||||
|
||||
def pinned_version(pyproject):
|
||||
pins = [
|
||||
m[1]
|
||||
for entry in parse(pyproject, "pyproject.toml")
|
||||
.get("dependency-groups", {})
|
||||
.get("dev", [])
|
||||
if isinstance(entry, str) and (m := PIN.fullmatch(entry))
|
||||
]
|
||||
if len(pins) != 1:
|
||||
raise Refused(f"pyproject.toml does not pin {PACKAGE} once with ==")
|
||||
return pins[0]
|
||||
|
||||
|
||||
def by_name(lock):
|
||||
packages = {}
|
||||
for package in lock.get("package", []):
|
||||
packages.setdefault(package.get("name"), []).append(package)
|
||||
return packages
|
||||
|
||||
|
||||
def only(packages, what):
|
||||
if len(packages) != 1:
|
||||
raise Refused(f"the lock does not hold exactly one {what}")
|
||||
return packages[0]
|
||||
|
||||
|
||||
def without_apm_specifier(root):
|
||||
"""The root project with its apm-cli dev specifier blanked, and that specifier."""
|
||||
root = copy.deepcopy(root)
|
||||
entries = [
|
||||
entry
|
||||
for entry in root.get("metadata", {}).get("requires-dev", {}).get("dev", [])
|
||||
if entry.get("name") == PACKAGE
|
||||
]
|
||||
entry = only(entries, f"{PACKAGE} dev requirement in the root project")
|
||||
specifier = entry.pop("specifier", None)
|
||||
return root, specifier
|
||||
|
||||
|
||||
def release(version):
|
||||
"""A plain release as a tuple of numbers without trailing zeros, or None."""
|
||||
if not isinstance(version, str) or not RELEASE.fullmatch(version):
|
||||
return None
|
||||
parts = [int(part) for part in version.split(".")]
|
||||
while len(parts) > 1 and parts[-1] == 0:
|
||||
parts.pop()
|
||||
return tuple(parts)
|
||||
|
||||
|
||||
def file_kinds(package):
|
||||
"""The kinds of file a package locks: "sdist" and the tag of each wheel."""
|
||||
version = package.get("version")
|
||||
kinds = {"sdist"} if "sdist" in package else set()
|
||||
for wheel in package.get("wheels", []):
|
||||
name = urllib.parse.urlsplit(wheel.get("url", "")).path.rsplit("/", 1)[-1]
|
||||
prefix = f"{DIST}-{version}-"
|
||||
if not (name.startswith(prefix) and name.endswith(".whl")):
|
||||
raise Refused(f"the {PACKAGE} wheel {name} is not {PACKAGE} {version}")
|
||||
kinds.add(name[len(prefix) : -len(".whl")])
|
||||
return kinds
|
||||
|
||||
|
||||
def file_problem(pin, file):
|
||||
url = urllib.parse.urlsplit(file.get("url", ""))
|
||||
segments = url.path.split("/")
|
||||
name = segments[-1]
|
||||
if not (
|
||||
set(file) <= FILE_KEYS
|
||||
and url.scheme == "https"
|
||||
and url.netloc == "files.pythonhosted.org"
|
||||
and segments[:2] == ["", "packages"]
|
||||
and not any(part in ("", ".", "..") for part in segments[1:])
|
||||
and "%" not in url.path
|
||||
and not (url.query or url.fragment)
|
||||
):
|
||||
return f"an {PACKAGE} file is not a plain download from files.pythonhosted.org"
|
||||
if not (
|
||||
name == f"{DIST}-{pin}.tar.gz"
|
||||
or (name.startswith(f"{DIST}-{pin}-") and name.endswith(".whl"))
|
||||
):
|
||||
return f"the {PACKAGE} file {name} is not {PACKAGE} {pin}"
|
||||
if not SHA256.fullmatch(str(file.get("hash", ""))):
|
||||
return f"the {PACKAGE} file {name} has no sha256 hash"
|
||||
return None
|
||||
|
||||
|
||||
def apm_problem(old, new, pin):
|
||||
if new.get("version") != pin:
|
||||
return f"{PACKAGE} is locked at {new.get('version')}, not at the pin {pin}"
|
||||
old_release, new_release = release(old.get("version")), release(pin)
|
||||
if old_release is None or new_release is None:
|
||||
return f"{PACKAGE} {old.get('version')} or {pin} is not a plain release"
|
||||
if new_release <= old_release:
|
||||
return f"{PACKAGE} does not move up from {old.get('version')} to {pin}"
|
||||
rest = {"version", "sdist", "wheels"}
|
||||
if {k: v for k, v in old.items() if k not in rest} != {
|
||||
k: v for k, v in new.items() if k not in rest
|
||||
}:
|
||||
return f"changes the source or dependencies of {PACKAGE}"
|
||||
files = ([new["sdist"]] if "sdist" in new else []) + new.get("wheels", [])
|
||||
if not files:
|
||||
return f"locks no file for {PACKAGE}"
|
||||
for file in files:
|
||||
reason = file_problem(pin, file)
|
||||
if reason:
|
||||
return reason
|
||||
if file_kinds(old) != file_kinds(new):
|
||||
return f"changes which kinds of file {PACKAGE} locks (sdist, wheel tags)"
|
||||
return None
|
||||
|
||||
|
||||
def compare(old, new, pin):
|
||||
rest = {"revision", "package"}
|
||||
if {k: v for k, v in old.items() if k not in rest} != {
|
||||
k: v for k, v in new.items() if k not in rest
|
||||
}:
|
||||
return "changes a top-level setting other than revision"
|
||||
if not isinstance(new.get("revision"), int):
|
||||
return "the lock revision is not a number"
|
||||
old_packages, new_packages = by_name(old), by_name(new)
|
||||
if set(old_packages) != set(new_packages):
|
||||
return "adds or removes a package"
|
||||
roots = [
|
||||
name
|
||||
for name, entries in new_packages.items()
|
||||
if any(e.get("source") == ROOT_SOURCE for e in entries)
|
||||
]
|
||||
root = only(roots, "root project")
|
||||
for name in new_packages:
|
||||
if name not in (PACKAGE, root) and old_packages[name] != new_packages[name]:
|
||||
return f"changes the package {name}"
|
||||
old_root, _unused = without_apm_specifier(only(old_packages[root], "root project"))
|
||||
new_root, specifier = without_apm_specifier(
|
||||
only(new_packages[root], "root project")
|
||||
)
|
||||
if old_root != new_root:
|
||||
return "changes the root project beyond its apm-cli specifier"
|
||||
if specifier != f"=={pin}":
|
||||
return f"the root project's {PACKAGE} specifier is not =={pin}"
|
||||
return apm_problem(
|
||||
only(old_packages.get(PACKAGE, []), PACKAGE),
|
||||
only(new_packages.get(PACKAGE, []), PACKAGE),
|
||||
pin,
|
||||
)
|
||||
|
||||
|
||||
def lock_problem(old_lock, new_lock, pyproject):
|
||||
"""None when new_lock differs from old_lock only by the apm-cli bump to the pin of
|
||||
pyproject (the new pyproject.toml's text); else a one-line reason."""
|
||||
try:
|
||||
return compare(
|
||||
parse(old_lock, "the old uv.lock"),
|
||||
parse(new_lock, "the new uv.lock"),
|
||||
pinned_version(pyproject),
|
||||
)
|
||||
except Refused as exc:
|
||||
return str(exc)
|
||||
except (AttributeError, TypeError):
|
||||
return "the lock does not have the shape uv writes"
|
||||
@@ -26,7 +26,7 @@ set -euo pipefail
|
||||
|
||||
# The repository is derived from this script's own location (symlinks resolved), never
|
||||
# from the caller's working directory: running it from another repository must not
|
||||
# create or remove that repository's .venv.
|
||||
# create or remove that repository's .venv-dev.
|
||||
script="$(readlink -f "${BASH_SOURCE[0]}")"
|
||||
root="$(git -C "$(dirname "$script")/.." rev-parse --show-toplevel)"
|
||||
cd "$root"
|
||||
@@ -122,19 +122,19 @@ if still="$(git -C "$root" config --get core.hooksPath)" && [ -n "$still" ]; the
|
||||
fi
|
||||
|
||||
# A virtualenv made by an older Python is rebuilt rather than reused.
|
||||
if [ -x .venv/bin/python ] && ! .venv/bin/python -c "$py_ok" 2>/dev/null; then
|
||||
rm -rf "$root/.venv"
|
||||
if [ -x .venv-dev/bin/python ] && ! .venv-dev/bin/python -c "$py_ok" 2>/dev/null; then
|
||||
rm -rf "$root/.venv-dev"
|
||||
fi
|
||||
[ -x .venv/bin/python ] || "$python" -m venv .venv
|
||||
.venv/bin/pip install --quiet --disable-pip-version-check --require-hashes -r requirements-dev.lock -r requirements-dev.txt
|
||||
.venv/bin/pre-commit install --install-hooks
|
||||
[ -x .venv-dev/bin/python ] || "$python" -m venv .venv-dev
|
||||
.venv-dev/bin/pip install --quiet --disable-pip-version-check --require-hashes -r requirements-dev.lock -r requirements-dev.txt
|
||||
.venv-dev/bin/pre-commit install --install-hooks
|
||||
|
||||
# The collections of requirements.yml, exactly as pinned, into this clone (.ansible/ is ignored by
|
||||
# git and by the Collection build). ANSIBLE_COLLECTIONS_PATH is set to the target for the install:
|
||||
# a copy found elsewhere (~/.ansible/collections) would be skipped as already installed.
|
||||
collections="$root/.ansible/collections"
|
||||
mkdir -p "$collections"
|
||||
ANSIBLE_COLLECTIONS_PATH="$collections" .venv/bin/ansible-galaxy collection install \
|
||||
ANSIBLE_COLLECTIONS_PATH="$collections" .venv-dev/bin/ansible-galaxy collection install \
|
||||
-r requirements.yml -p "$collections"
|
||||
|
||||
marker="# kamino-dev-setup: virtualenv first on PATH"
|
||||
@@ -150,7 +150,7 @@ for hook in pre-commit commit-msg pre-push; do
|
||||
{
|
||||
head -n 1 "$file"
|
||||
# %q shell-quotes the path: a repository path with spaces, quotes or $(...) is data.
|
||||
printf '%s\n' "$marker" "export PATH=$(printf '%q' "$root/.venv/bin"):\"\$PATH\""
|
||||
printf '%s\n' "$marker" "export PATH=$(printf '%q' "$root/.venv-dev/bin"):\"\$PATH\""
|
||||
tail -n +2 "$file"
|
||||
} > "$tmp"
|
||||
cat "$tmp" > "$file" # keeps the file mode of the hook
|
||||
@@ -179,4 +179,4 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Done: git commit now runs the hooks with the tools in $root/.venv/bin and the collections in $collections."
|
||||
echo "Done: git commit now runs the hooks with the tools in $root/.venv-dev/bin and the collections in $collections."
|
||||
@@ -11,7 +11,7 @@
|
||||
# Needs the network (PyPI) and the Python of .python-version (python<MINOR>; KAMINO_PYTHON overrides it): the
|
||||
# header of the lock records it, and check_image_versions.py pins fails when it differs.
|
||||
# pip and pip-tools are installed, at the pinned versions below, into a throwaway virtualenv, never
|
||||
# into the project's .venv. pip is pinned too: pip-tools breaks on newer pip releases (7.5.2 on pip 26). Commit
|
||||
# into the project's .venv-dev. pip is pinned too: pip-tools breaks on newer pip releases (7.5.2 on pip 26). Commit
|
||||
# the lock with its requirements file; pip refuses an install of the two when they disagree
|
||||
# (`pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt`).
|
||||
# The pins are not hash-checked themselves: they come from PyPI over TLS, like the pip that
|
||||
|
||||
@@ -70,9 +70,18 @@ USER_AGENT = "kamino-next-image-version"
|
||||
|
||||
|
||||
class RegistryError(Exception):
|
||||
def __init__(self, url, status, text, challenge=""):
|
||||
def __init__(self, url, status, text, challenge="", codes=()):
|
||||
super().__init__(f"GET {url}: HTTP {status}: {text}")
|
||||
self.status, self.challenge = status, challenge
|
||||
self.status, self.challenge, self.codes = status, challenge, codes
|
||||
|
||||
|
||||
def _error_codes(raw):
|
||||
"""The OCI error codes of an error body (`{"errors": [{"code": ...}]}`), or () for any other body."""
|
||||
try:
|
||||
errors = json.loads(raw).get("errors") or []
|
||||
return tuple(e.get("code") for e in errors if isinstance(e, dict))
|
||||
except (ValueError, AttributeError, TypeError):
|
||||
return ()
|
||||
|
||||
|
||||
def _readable(raw):
|
||||
@@ -92,7 +101,9 @@ def _fetch(url, headers):
|
||||
except urllib.error.HTTPError as exc:
|
||||
raw = exc.read(20000).decode("utf-8", errors="replace")
|
||||
challenge = exc.headers.get("WWW-Authenticate", "")
|
||||
raise RegistryError(url, exc.code, _readable(raw), challenge) from exc
|
||||
raise RegistryError(
|
||||
url, exc.code, _readable(raw), challenge, _error_codes(raw)
|
||||
) from exc
|
||||
|
||||
|
||||
class Registry:
|
||||
@@ -139,7 +150,8 @@ class Registry:
|
||||
body, headers = self._get(path)
|
||||
except RegistryError as exc:
|
||||
# A repository not pushed yet is 404 NAME_UNKNOWN (OCI distribution spec): no tags.
|
||||
if exc.status == 404 and not tags:
|
||||
# Any other 404, such as a wrong registry path, must fail rather than restart at .0.
|
||||
if exc.status == 404 and "NAME_UNKNOWN" in exc.codes and not tags:
|
||||
return []
|
||||
raise
|
||||
tags += body.get("tags") or []
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
# writable for the runner user) and put them first, then check that the scenarios on stdin load this
|
||||
# checkout and run them. CI_BASE_PYTHON is a test seam.
|
||||
#
|
||||
# AC_ROOT=<dir holding ansible_collections> scripts/run_molecule_in_ci_image.sh < scenario-dirs
|
||||
# AC_ROOT=<dir holding ansible_collections> scripts/run_molecule_in_controller.sh < scenario-dirs
|
||||
set -euo pipefail
|
||||
|
||||
selected="$(cat)"
|
||||
@@ -92,6 +92,8 @@ IGNORED = (
|
||||
"ruff.toml",
|
||||
"apm.yml",
|
||||
"apm.lock.yaml",
|
||||
"pyproject.toml",
|
||||
"uv.lock",
|
||||
".claude/*",
|
||||
"tests/sanity/*",
|
||||
"tests/scripts/*",
|
||||
@@ -105,6 +107,7 @@ IGNORED = (
|
||||
".gitea/workflows/renovate.yml",
|
||||
".gitea/workflows/gitea-release-key.yml",
|
||||
"scripts/check_bot_pr_diff.py",
|
||||
"scripts/check_uv_lock.py",
|
||||
"scripts/check_image_versions.py",
|
||||
"scripts/next_image_version.py",
|
||||
"scripts/check_tarball.py",
|
||||
|
||||
@@ -13,6 +13,7 @@ from unittest import mock
|
||||
SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts"
|
||||
sys.path.insert(0, str(SCRIPTS))
|
||||
import check_bot_pr_diff as cbd
|
||||
from test_check_uv_lock import APM_NEW, APM_OLD, CLICK_OLD, UV_LOCK, uv_files
|
||||
|
||||
D1, D2 = "sha256:" + "a" * 64, "sha256:" + "b" * 64
|
||||
FILES = {
|
||||
@@ -30,6 +31,7 @@ FILES = {
|
||||
".gitea/workflows/lint.yml": f"container:\n image: git.rkdr.net/mortis/ci:0.2.0@{D1}\nrun: echo a\n",
|
||||
".gitea/workflows/molecule.yml": f"env:\n MOLECULE_IMAGE: >-\n git.rkdr.net/mortis/mol:0.1.0@{D1}\n",
|
||||
"renovate.json": "{}\n",
|
||||
"pyproject.toml": '[project]\nrequires-python = ">=3.11"\n\n[dependency-groups]\ndev = ["apm-cli==0.39.3"]\n',
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +51,7 @@ def run(cwd, *cmd):
|
||||
|
||||
|
||||
H1, H2 = "a" * 64, "b" * 64
|
||||
FILES["uv.lock"] = UV_LOCK
|
||||
|
||||
|
||||
class LockRuleTest(unittest.TestCase):
|
||||
@@ -113,6 +116,69 @@ class LockRuleTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class PyprojectRuleTest(unittest.TestCase):
|
||||
def test_an_apm_cli_bump_is_allowed(self):
|
||||
self.assertIsNone(
|
||||
cbd.file_problem(
|
||||
"pyproject.toml",
|
||||
['dev = ["apm-cli==0.39.3"]'],
|
||||
['dev = ["apm-cli==0.39.4"]'],
|
||||
)
|
||||
)
|
||||
|
||||
def test_a_new_dependency_is_refused(self):
|
||||
old = 'dev = ["apm-cli==0.39.3"]'
|
||||
for new in (
|
||||
'dev = ["apm-cli==0.39.4", "evil==1.0"]',
|
||||
'dev = ["evil==0.39.4"]',
|
||||
'dev = ["apm-cli==0.39.4"]\nprod = ["evil==1.0"]',
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assertIsNotNone(
|
||||
cbd.file_problem("pyproject.toml", [old], new.split("\n"))
|
||||
)
|
||||
|
||||
def test_a_pinned_name_keeps_its_spelling(self):
|
||||
self.assertIsNotNone(
|
||||
cbd.file_problem(
|
||||
"pyproject.toml",
|
||||
['dev = ["apm-cli==0.39.3"]'],
|
||||
['dev = ["APM-CLI==0.39.4"]'],
|
||||
)
|
||||
)
|
||||
|
||||
def test_an_edit_to_another_setting_is_refused(self):
|
||||
for old, new in (
|
||||
('requires-python = ">=3.11"', 'requires-python = ">=3.12"'),
|
||||
("package = false", "package = true"),
|
||||
(
|
||||
'dev = ["apm-cli==0.39.3"]',
|
||||
'dev = ["apm-cli @ https://evil.example/apm.tgz"]',
|
||||
),
|
||||
(
|
||||
'dev = ["apm-cli==0.39.3"]',
|
||||
'dev = ["apm-cli==0.39.4"] # index-url = "https://evil/simple"',
|
||||
),
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assertIsNotNone(cbd.file_problem("pyproject.toml", [old], [new]))
|
||||
|
||||
|
||||
class UvLockTest(unittest.TestCase):
|
||||
def test_uv_lock_is_refused_without_both_sides_to_parse(self):
|
||||
entries = [
|
||||
("100644", "100644", "M", "pyproject.toml"),
|
||||
("100644", "100644", "M", "uv.lock"),
|
||||
]
|
||||
patches = {
|
||||
"pyproject.toml": '@@ -1 +1 @@\n-dev = ["apm-cli==0.39.3"]\n+dev = ["apm-cli==0.39.4"]\n',
|
||||
"uv.lock": "@@ -1 +1 @@\n-revision = 3\n+revision = 5\n",
|
||||
}
|
||||
problems = cbd.check(entries, patches.get)
|
||||
self.assertEqual(len(problems), 1, problems)
|
||||
self.assertTrue(problems[0].startswith("uv.lock: "), problems)
|
||||
|
||||
|
||||
class RuleTest(unittest.TestCase):
|
||||
def problem(self, path, old, new):
|
||||
return cbd.file_problem(path, [old], [new])
|
||||
@@ -499,6 +565,109 @@ class RepoTest(unittest.TestCase):
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("5 file(s)", out)
|
||||
|
||||
def bump_apm_cli(self):
|
||||
"""The change Renovate makes for apm-cli 0.39.4, as uv 0.13.1 writes it."""
|
||||
self.edit("pyproject.toml", "apm-cli==0.39.3", "apm-cli==0.39.4")
|
||||
self.edit("uv.lock", 'version = "0.39.3"', 'version = "0.39.4"')
|
||||
self.edit("uv.lock", '"==0.39.3"', '"==0.39.4"')
|
||||
self.edit("uv.lock", "apm_cli-0.39.3", "apm_cli-0.39.4")
|
||||
self.edit("uv.lock", APM_OLD, APM_NEW)
|
||||
|
||||
def assert_lock_refused(self):
|
||||
self.commit("bot")
|
||||
code, _unused, err = self.gate()
|
||||
self.assertEqual(code, 1, err)
|
||||
self.assertIn("uv.lock", err)
|
||||
|
||||
def test_an_apm_cli_bump_with_its_lock_passes(self):
|
||||
self.bump_apm_cli()
|
||||
self.commit("bot")
|
||||
code, out, err = self.gate()
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("2 file(s)", out)
|
||||
|
||||
def test_another_packages_file_under_the_apm_cli_entry_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
lock = (self.repo / "uv.lock").read_text()
|
||||
start = lock.index('version = "0.39.4"')
|
||||
end = lock.index("[[package]]", start)
|
||||
six = (
|
||||
'version = "1.17.0"\nsource = { registry = "https://pypi.org/simple" }\n'
|
||||
'dependencies = [\n { name = "click" },\n { name = "watchdog" },\n]\n'
|
||||
'wheels = [\n { url = "https://files.pythonhosted.org/packages/b7/ce/'
|
||||
'149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl", '
|
||||
'hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274", '
|
||||
'size = 11050, upload-time = "2024-12-04T17:35:26.475Z" },\n]\n\n'
|
||||
)
|
||||
self.write("uv.lock", lock[:start] + six + lock[end:])
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_new_package_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
self.edit(
|
||||
"uv.lock",
|
||||
'dev = [\n { name = "apm-cli" },\n]',
|
||||
'dev = [\n { name = "apm-cli" },\n { name = "six" },\n]',
|
||||
)
|
||||
self.write(
|
||||
"uv.lock",
|
||||
(self.repo / "uv.lock").read_text()
|
||||
+ '\n[[package]]\nname = "six"\nversion = "1.17.0"\n'
|
||||
'source = { registry = "https://pypi.org/simple" }\n'
|
||||
+ uv_files("six", "1.17.0", H2),
|
||||
)
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_marker_that_drops_a_dependency_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
self.edit(
|
||||
"uv.lock",
|
||||
' { name = "watchdog" },',
|
||||
' { name = "watchdog", marker = "sys_platform == \'never\'" },',
|
||||
)
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_downgraded_transitive_package_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
self.edit("uv.lock", 'version = "8.5.1"', 'version = "8.5.0"')
|
||||
self.edit("uv.lock", "click-8.5.1", "click-8.5.0")
|
||||
self.edit("uv.lock", CLICK_OLD, H2)
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_pyproject_change_without_its_lock_is_refused(self):
|
||||
self.edit("pyproject.toml", "apm-cli==0.39.3", "apm-cli==0.39.4")
|
||||
self.commit("bot")
|
||||
code, _unused, err = self.gate()
|
||||
self.assertEqual(code, 1, err)
|
||||
self.assertIn("pyproject.toml", err)
|
||||
|
||||
def test_an_apm_cli_lock_change_without_pyproject_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
self.edit("pyproject.toml", "apm-cli==0.39.4", "apm-cli==0.39.3")
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_changed_apm_cli_source_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
lock = (self.repo / "uv.lock").read_text()
|
||||
start = lock.index('name = "apm-cli"')
|
||||
self.write(
|
||||
"uv.lock",
|
||||
lock[:start]
|
||||
+ lock[start:].replace(
|
||||
"https://pypi.org/simple", "https://evil.example/simple", 1
|
||||
),
|
||||
)
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_changed_apm_cli_download_host_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
self.edit(
|
||||
"uv.lock",
|
||||
"https://files.pythonhosted.org/packages/ab/cd/apm_cli-0.39.4-py3",
|
||||
"https://files.evil.example/packages/ab/cd/apm_cli-0.39.4-py3",
|
||||
)
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_each_violation_gets_one_line(self):
|
||||
self.edit(".gitea/workflows/lint.yml", "echo a", "echo b")
|
||||
self.write("roles/x/main.yml", "a\n")
|
||||
|
||||
@@ -511,11 +511,12 @@ class PureTest(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(civ.dockerfile_labels('FROM c\nLABEL a="unbalanced\n'), {})
|
||||
|
||||
def test_the_molecule_collections_are_an_input_of_the_ci_image(self):
|
||||
def test_the_molecule_collections_are_not_an_input_of_the_ci_image(self):
|
||||
# Lint uses no collection of them, so their bump must not publish a ci version.
|
||||
root = pathlib.Path(__file__).resolve().parents[2]
|
||||
entry = civ.matrix_of((root / civ.MATRIX_FILE).read_text())["ci"]
|
||||
files = civ.inputs_of(entry, (root / entry["dockerfile"]).read_text())[1]
|
||||
self.assertIn("extensions/molecule/requirements.yml", files)
|
||||
self.assertNotIn("extensions/molecule/requirements.yml", files)
|
||||
|
||||
def test_the_controller_pins_are_inputs_of_the_controller_image(self):
|
||||
root = pathlib.Path(__file__).resolve().parents[2]
|
||||
|
||||
@@ -267,7 +267,7 @@ class CraftedTarballTest(unittest.TestCase):
|
||||
REPO,
|
||||
src,
|
||||
ignore=shutil.ignore_patterns(
|
||||
".git", ".venv", "__pycache__", "output", "*.tar.gz"
|
||||
".git", ".venv", ".venv-dev", "__pycache__", "output", "*.tar.gz"
|
||||
),
|
||||
)
|
||||
out = pathlib.Path(self.tmp.name) / "dist"
|
||||
|
||||
@@ -0,0 +1,321 @@
|
||||
# SPDX-FileCopyrightText: Defame1297 and contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Run with: python3 -m unittest discover -s tests/scripts"""
|
||||
|
||||
import pathlib
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts"
|
||||
sys.path.insert(0, str(SCRIPTS))
|
||||
import check_uv_lock as cul
|
||||
|
||||
APM_OLD, APM_NEW, CLICK_OLD, OTHER = "c" * 64, "d" * 64, "e" * 64, "f" * 64
|
||||
PYPI_FILES = "https://files.pythonhosted.org/packages/ab/cd/"
|
||||
|
||||
|
||||
def uv_files(dist, version, digest):
|
||||
return (
|
||||
f'sdist = {{ url = "{PYPI_FILES}{dist}-{version}.tar.gz", hash = "sha256:{digest}", '
|
||||
f'size = 3132901, upload-time = "2026-12-01T18:11:22.037Z" }}\n'
|
||||
f'wheels = [\n {{ url = "{PYPI_FILES}{dist}-{version}-py3-none-any.whl", '
|
||||
f'hash = "sha256:{digest}", size = 3536708, upload-time = "2026-12-01T18:11:19.761Z" }},\n]\n'
|
||||
)
|
||||
|
||||
|
||||
# A uv.lock as uv 0.13.1 writes it: apm-cli, two of its dependencies and the root project.
|
||||
UV_LOCK = (
|
||||
'version = 1\nrevision = 5\nrequires-python = ">=3.11"\n\n'
|
||||
'[[package]]\nname = "apm-cli"\nversion = "0.39.3"\n'
|
||||
'source = { registry = "https://pypi.org/simple" }\n'
|
||||
'dependencies = [\n { name = "click" },\n { name = "watchdog" },\n]\n'
|
||||
+ uv_files("apm_cli", "0.39.3", APM_OLD)
|
||||
+ '\n[[package]]\nname = "click"\nversion = "8.5.1"\n'
|
||||
'source = { registry = "https://pypi.org/simple" }\n'
|
||||
+ uv_files("click", "8.5.1", CLICK_OLD)
|
||||
+ '\n[[package]]\nname = "kamino"\nversion = "0"\nsource = { virtual = "." }\n\n'
|
||||
'[package.dev-dependencies]\ndev = [\n { name = "apm-cli" },\n]\n\n'
|
||||
"[package.metadata]\n\n[package.metadata.requires-dev]\n"
|
||||
'dev = [{ name = "apm-cli", specifier = "==0.39.3" }]\n'
|
||||
'\n[[package]]\nname = "watchdog"\nversion = "7.1.1"\n'
|
||||
'source = { registry = "https://pypi.org/simple" }\n'
|
||||
+ uv_files("watchdog", "7.1.1", OTHER)
|
||||
)
|
||||
PYPROJECT = (
|
||||
'[project]\nname = "kamino"\n\n[dependency-groups]\ndev = ["apm-cli==VERSION"]\n'
|
||||
)
|
||||
|
||||
|
||||
def bumped(lock=UV_LOCK):
|
||||
"""The lock after Renovate's apm-cli 0.39.4 bump."""
|
||||
return (
|
||||
lock.replace('version = "0.39.3"', 'version = "0.39.4"')
|
||||
.replace('"==0.39.3"', '"==0.39.4"')
|
||||
.replace("apm_cli-0.39.3", "apm_cli-0.39.4")
|
||||
.replace(APM_OLD, APM_NEW)
|
||||
)
|
||||
|
||||
|
||||
def problem(new, pin="0.39.4", old=UV_LOCK):
|
||||
return cul.lock_problem(old, new, PYPROJECT.replace("VERSION", pin))
|
||||
|
||||
|
||||
class AllowedTest(unittest.TestCase):
|
||||
def test_an_apm_cli_bump_is_allowed(self):
|
||||
self.assertIsNone(problem(bumped()))
|
||||
|
||||
def test_a_new_lock_revision_is_allowed(self):
|
||||
old = UV_LOCK.replace("revision = 5", "revision = 3")
|
||||
self.assertIsNone(problem(bumped(), old=old))
|
||||
|
||||
def test_a_package_without_an_sdist_is_allowed(self):
|
||||
start = UV_LOCK.index("sdist = { url")
|
||||
old = UV_LOCK[:start] + UV_LOCK[UV_LOCK.index("wheels = [", start) :]
|
||||
self.assertIsNone(problem(bumped(old), old=old))
|
||||
|
||||
|
||||
class RefusedTest(unittest.TestCase):
|
||||
def assert_refused(self, new, **kwargs):
|
||||
self.assertIsNotNone(problem(new, **kwargs))
|
||||
|
||||
def test_a_lock_that_is_not_toml_is_refused(self):
|
||||
self.assert_refused(bumped() + "[[package\n")
|
||||
|
||||
def test_a_lock_of_another_shape_is_refused(self):
|
||||
top = 'version = 1\nrevision = 5\nrequires-python = ">=3.11"\n'
|
||||
for package in ('package = ["x"]\n', "package = 1\n"):
|
||||
with self.subTest(package=package):
|
||||
self.assertEqual(
|
||||
problem(top + package), "the lock does not have the shape uv writes"
|
||||
)
|
||||
|
||||
def test_the_lock_version_must_be_the_pin(self):
|
||||
self.assert_refused(bumped(), pin="0.39.5")
|
||||
self.assert_refused(
|
||||
bumped().replace('version = "0.39.4"', 'version = "0.39.5"')
|
||||
)
|
||||
|
||||
def test_the_dev_specifier_must_be_the_pin(self):
|
||||
self.assert_refused(bumped().replace('"==0.39.4"', '"==0.39.3"'))
|
||||
self.assert_refused(bumped().replace('"==0.39.4"', '">=0.39.4"'))
|
||||
|
||||
def test_a_pyproject_without_one_apm_cli_pin_is_refused(self):
|
||||
for pyproject in (
|
||||
'[dependency-groups]\ndev = ["apm-cli>=0.39.4"]\n',
|
||||
'[dependency-groups]\ndev = ["apm-cli==0.39.4", "apm-cli==0.39.5"]\n',
|
||||
"[dependency-groups]\ndev = [\n",
|
||||
):
|
||||
with self.subTest(pyproject=pyproject):
|
||||
self.assertIsNotNone(cul.lock_problem(UV_LOCK, bumped(), pyproject))
|
||||
|
||||
def test_another_top_level_setting_is_refused(self):
|
||||
for old, new in (
|
||||
('requires-python = ">=3.11"', 'requires-python = ">=3.12"'),
|
||||
("version = 1\n", "version = 2\n"),
|
||||
("revision = 5", 'revision = "5"'),
|
||||
(
|
||||
"revision = 5",
|
||||
'revision = 5\n[options]\nexclude-newer = "2026-01-01T00:00:00Z"',
|
||||
),
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assert_refused(bumped().replace(old, new, 1))
|
||||
|
||||
def test_an_apm_cli_dependency_change_is_refused(self):
|
||||
for new in (
|
||||
' { name = "click" },\n { name = "watchdog" },\n { name = "six" },\n',
|
||||
' { name = "click" },\n',
|
||||
' { name = "click", marker = "sys_platform == \'never\'" },\n { name = "watchdog" },\n',
|
||||
' { name = "click", extra = ["evil"] },\n { name = "watchdog" },\n',
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assert_refused(
|
||||
bumped().replace(
|
||||
' { name = "click" },\n { name = "watchdog" },\n', new, 1
|
||||
)
|
||||
)
|
||||
|
||||
def test_a_changed_apm_cli_source_is_refused(self):
|
||||
lock = bumped()
|
||||
start = lock.index('name = "apm-cli"')
|
||||
for source in (
|
||||
'source = { registry = "https://evil.example/simple" }',
|
||||
'source = { git = "https://evil.example/apm.git?rev=main#0123abc" }',
|
||||
'source = { url = "https://evil.example/apm_cli-0.39.4.tar.gz" }',
|
||||
):
|
||||
with self.subTest(source=source):
|
||||
self.assert_refused(
|
||||
lock[:start]
|
||||
+ lock[start:].replace(
|
||||
'source = { registry = "https://pypi.org/simple" }', source, 1
|
||||
)
|
||||
)
|
||||
|
||||
def test_a_file_that_is_not_the_pinned_apm_cli_from_pypi_is_refused(self):
|
||||
wheel = f"{PYPI_FILES}apm_cli-0.39.4-py3-none-any.whl"
|
||||
for old, new in (
|
||||
(wheel, wheel.replace("files.pythonhosted.org", "files.evil.example")),
|
||||
(wheel, wheel.replace("https://", "http://")),
|
||||
(
|
||||
wheel,
|
||||
wheel.replace(
|
||||
"files.pythonhosted.org", "files.pythonhosted.org.evil.example"
|
||||
),
|
||||
),
|
||||
(wheel, wheel.replace("/packages/", "/other/")),
|
||||
(wheel, wheel + "?x=/packages/apm_cli-0.39.4-py3-none-any.whl"),
|
||||
(wheel, wheel.replace("apm_cli-0.39.4", "six-1.17.0")),
|
||||
(wheel, wheel.replace("apm_cli-0.39.4", "apm_cli-0.39.3")),
|
||||
(wheel, wheel.replace("apm_cli-0.39.4", "apm_cli-0.39.40")),
|
||||
(wheel, wheel.replace(".whl", ".exe")),
|
||||
(f"sha256:{APM_NEW}", "md5:" + "d" * 32),
|
||||
(f"sha256:{APM_NEW}", "sha256:" + "d" * 63),
|
||||
(f"sha256:{APM_NEW}", "sha256:" + "D" * 64),
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assert_refused(bumped().replace(old, new))
|
||||
|
||||
def test_a_file_with_another_key_is_refused(self):
|
||||
wheel = f'{{ url = "{PYPI_FILES}apm_cli-0.39.4-py3-none-any.whl", '
|
||||
self.assert_refused(
|
||||
bumped().replace(wheel, wheel + 'path = "../evil.whl", ', 1)
|
||||
)
|
||||
|
||||
def test_an_apm_cli_without_files_is_refused(self):
|
||||
lock = bumped()
|
||||
start = lock.index("sdist = { url", lock.index('name = "apm-cli"'))
|
||||
end = lock.index("]\n", start) + 2
|
||||
self.assert_refused(lock[:start] + lock[end:])
|
||||
|
||||
def test_a_change_to_another_package_is_refused(self):
|
||||
for old, new in (
|
||||
('version = "8.5.1"', 'version = "8.5.0"'),
|
||||
(CLICK_OLD, OTHER),
|
||||
(
|
||||
'name = "watchdog"\n',
|
||||
'name = "watchdog"\ndependencies = [{ name = "click" }]\n',
|
||||
),
|
||||
(
|
||||
'version = "0"\nsource = { virtual = "." }',
|
||||
'version = "1"\nsource = { virtual = "." }',
|
||||
),
|
||||
(
|
||||
'dev = [\n { name = "apm-cli" },\n]',
|
||||
'dev = [\n { name = "apm-cli" },\n { name = "click" },\n]',
|
||||
),
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assert_refused(bumped().replace(old, new, 1))
|
||||
|
||||
def test_an_added_or_removed_package_is_refused(self):
|
||||
six = (
|
||||
'\n[[package]]\nname = "six"\nversion = "1.17.0"\n'
|
||||
'source = { registry = "https://pypi.org/simple" }\n'
|
||||
+ uv_files("six", "1.17.0", OTHER)
|
||||
)
|
||||
self.assert_refused(bumped() + six)
|
||||
watchdog = bumped().index('\n[[package]]\nname = "watchdog"')
|
||||
self.assert_refused(bumped()[:watchdog])
|
||||
|
||||
def test_a_second_apm_cli_or_root_entry_is_refused(self):
|
||||
apm = bumped()
|
||||
start = apm.index('[[package]]\nname = "apm-cli"')
|
||||
end = apm.index("[[package]]", start + 1)
|
||||
self.assert_refused(apm + "\n" + apm[start:end])
|
||||
root = apm.index('[[package]]\nname = "kamino"')
|
||||
self.assert_refused(
|
||||
apm
|
||||
+ '\n[[package]]\nname = "other"\nversion = "0"\nsource = { virtual = "." }\n',
|
||||
old=UV_LOCK
|
||||
+ '\n[[package]]\nname = "other"\nversion = "0"\nsource = { virtual = "." }\n',
|
||||
)
|
||||
self.assertGreater(root, 0)
|
||||
|
||||
|
||||
def moved(lock, old, new):
|
||||
"""lock with apm-cli moved from version old to new."""
|
||||
return (
|
||||
lock.replace(f'version = "{old}"', f'version = "{new}"')
|
||||
.replace(f'"=={old}"', f'"=={new}"')
|
||||
.replace(f"apm_cli-{old}", f"apm_cli-{new}")
|
||||
)
|
||||
|
||||
|
||||
def without_apm_wheels(lock):
|
||||
start = lock.index("wheels = [", lock.index('name = "apm-cli"'))
|
||||
return lock[:start] + lock[lock.index("]\n", start) + 2 :]
|
||||
|
||||
|
||||
class FileKindsAndOrderTest(unittest.TestCase):
|
||||
def test_dropped_wheels_without_a_version_change_are_refused(self):
|
||||
new = without_apm_wheels(UV_LOCK).replace("size = 3132901", "size = 3132902", 1)
|
||||
self.assertIsNotNone(problem(new, pin="0.39.3"))
|
||||
|
||||
def test_a_downgrade_is_refused(self):
|
||||
self.assertIsNotNone(problem(UV_LOCK, pin="0.39.3", old=bumped()))
|
||||
|
||||
def test_the_version_must_rise(self):
|
||||
self.assertIsNotNone(problem(UV_LOCK.replace(APM_OLD, APM_NEW), pin="0.39.3"))
|
||||
|
||||
def test_versions_are_compared_as_numbers(self):
|
||||
old = moved(UV_LOCK, "0.39.3", "0.39.9")
|
||||
self.assertIsNone(
|
||||
problem(moved(old, "0.39.9", "0.39.10"), pin="0.39.10", old=old)
|
||||
)
|
||||
old = moved(UV_LOCK, "0.39.3", "0.9.0")
|
||||
self.assertIsNone(problem(moved(old, "0.9.0", "0.10.0"), pin="0.10.0", old=old))
|
||||
old = moved(UV_LOCK, "0.39.3", "0.40.0")
|
||||
self.assertIsNotNone(
|
||||
problem(moved(old, "0.40.0", "0.39.10"), pin="0.39.10", old=old)
|
||||
)
|
||||
|
||||
def test_a_version_that_is_not_a_plain_release_is_refused(self):
|
||||
for version in (
|
||||
"0.40.0rc1",
|
||||
"0.40.0.post1",
|
||||
"0.40.0.dev1",
|
||||
"1!0.1.0",
|
||||
"0.40.0+local",
|
||||
):
|
||||
with self.subTest(version=version):
|
||||
self.assertIsNotNone(
|
||||
problem(moved(UV_LOCK, "0.39.3", version), pin=version)
|
||||
)
|
||||
|
||||
def test_the_kinds_of_file_stay_the_same(self):
|
||||
self.assertIsNotNone(problem(without_apm_wheels(bumped())))
|
||||
start = bumped().index("sdist = { url", bumped().index('name = "apm-cli"'))
|
||||
no_sdist = bumped()[:start] + bumped()[bumped().index("wheels = [", start) :]
|
||||
self.assertIsNotNone(problem(no_sdist))
|
||||
old_no_sdist = (
|
||||
UV_LOCK[: UV_LOCK.index("sdist = { url")]
|
||||
+ UV_LOCK[UV_LOCK.index("wheels = [") :]
|
||||
)
|
||||
self.assertIsNotNone(problem(bumped(), old=old_no_sdist))
|
||||
self.assertIsNone(problem(no_sdist, old=old_no_sdist))
|
||||
for tag in ("cp311-cp311-manylinux_2_17_x86_64", "py2.py3-none-any"):
|
||||
with self.subTest(tag=tag):
|
||||
self.assertIsNotNone(
|
||||
problem(bumped().replace("0.39.4-py3-none-any", f"0.39.4-{tag}"))
|
||||
)
|
||||
|
||||
def test_a_path_that_leaves_packages_is_refused(self):
|
||||
wheel = f"{PYPI_FILES}apm_cli-0.39.4-py3-none-any.whl"
|
||||
for path in (
|
||||
"/packages/../../simple/x/",
|
||||
"/packages/ab/./cd/",
|
||||
"/packages//ab/",
|
||||
"/packages/%2e%2e/%2e%2e/simple/x/",
|
||||
"/packages/ab/cd%2F/",
|
||||
):
|
||||
with self.subTest(path=path):
|
||||
bad = (
|
||||
"https://files.pythonhosted.org"
|
||||
+ path
|
||||
+ "apm_cli-0.39.4-py3-none-any.whl"
|
||||
)
|
||||
self.assertIsNotNone(problem(bumped().replace(wheel, bad)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -192,7 +192,7 @@ class DevSetupTest(unittest.TestCase):
|
||||
proc = self.run_setup(repo, KAMINO_PYTHON=str(wrong))
|
||||
self.assertNotEqual(proc.returncode, 0)
|
||||
self.assertIn("is not Python 3.13 (.python-version)", proc.stderr)
|
||||
self.assertFalse((repo / ".venv").exists())
|
||||
self.assertFalse((repo / ".venv-dev").exists())
|
||||
|
||||
def test_an_interpreter_of_another_minor_is_refused_and_the_pinned_one_accepted(
|
||||
self,
|
||||
@@ -201,10 +201,10 @@ class DevSetupTest(unittest.TestCase):
|
||||
proc = self.run_setup(repo, STUB_PY_MINOR="3.12")
|
||||
self.assertNotEqual(proc.returncode, 0)
|
||||
self.assertIn("is not Python 3.13 (.python-version)", proc.stderr)
|
||||
self.assertFalse((repo / ".venv").exists())
|
||||
self.assertFalse((repo / ".venv-dev").exists())
|
||||
proc = self.run_setup(repo, STUB_PY_MINOR="3.13")
|
||||
self.assertEqual(proc.returncode, 0, proc.stderr)
|
||||
self.assertTrue((repo / ".venv").is_dir())
|
||||
self.assertTrue((repo / ".venv-dev").is_dir())
|
||||
|
||||
def test_a_missing_pin_file_is_refused_with_a_message(self) -> None:
|
||||
repo = self.make_repo()
|
||||
@@ -228,6 +228,30 @@ class DevSetupTest(unittest.TestCase):
|
||||
text = self.hook(repo, name).read_text()
|
||||
self.assertIn("# kamino-dev-setup: virtualenv first on PATH", text)
|
||||
self.assertEqual(self.hooks_z(repo), b"")
|
||||
self.assertFalse((repo / ".venv").exists())
|
||||
|
||||
def test_a_rerun_moves_the_hooks_of_an_older_setup_to_venv_dev(self) -> None:
|
||||
repo = self.make_repo()
|
||||
kept = repo / ".venv" / "kept"
|
||||
kept.parent.mkdir()
|
||||
kept.write_text("")
|
||||
names = ("pre-commit", "commit-msg", "pre-push")
|
||||
for name in names:
|
||||
hook = self.hook(repo, name)
|
||||
hook.parent.mkdir(exist_ok=True)
|
||||
hook.write_text(
|
||||
"#!/usr/bin/env bash\n"
|
||||
"# kamino-dev-setup: virtualenv first on PATH\n"
|
||||
f'export PATH={repo}/.venv/bin:"$PATH"\n'
|
||||
)
|
||||
hook.chmod(0o755)
|
||||
result = self.run_setup(repo)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
for name in names:
|
||||
text = self.hook(repo, name).read_text()
|
||||
self.assertIn(f'export PATH={repo}/.venv-dev/bin:"$PATH"\n', text)
|
||||
self.assertNotIn("/.venv/bin", text)
|
||||
self.assertTrue(kept.exists())
|
||||
|
||||
def test_a_missing_tea_warns_and_setup_succeeds(self) -> None:
|
||||
repo = self.make_repo()
|
||||
@@ -403,12 +427,12 @@ class DevSetupTest(unittest.TestCase):
|
||||
self.git(other, "init", "--quiet")
|
||||
result = self.run_setup(repo, cwd=other)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertFalse((other / ".venv").exists())
|
||||
self.assertFalse((other / ".venv-dev").exists())
|
||||
self.assertEqual(
|
||||
os.listdir(other / ".git" / "hooks"),
|
||||
[n for n in os.listdir(other / ".git" / "hooks") if n.endswith(".sample")],
|
||||
)
|
||||
self.assertTrue((repo / ".venv").is_dir())
|
||||
self.assertTrue((repo / ".venv-dev").is_dir())
|
||||
self.assertTrue(self.hook(repo).exists())
|
||||
|
||||
def test_crafted_repository_path_is_not_executed(self) -> None:
|
||||
@@ -428,7 +452,7 @@ class DevSetupTest(unittest.TestCase):
|
||||
self.assertEqual(hook.returncode, 0, hook.stderr)
|
||||
lines = hook.stdout.splitlines()
|
||||
self.assertEqual(lines[0], "hook-ran")
|
||||
self.assertTrue(lines[1].startswith(f"{repo}/.venv/bin:"), lines[1])
|
||||
self.assertTrue(lines[1].startswith(f"{repo}/.venv-dev/bin:"), lines[1])
|
||||
for place in (workdir, repo, self.tmp, Path.cwd()):
|
||||
self.assertFalse((place / "PWNED").exists(), place)
|
||||
self.assertFalse((place / "PWNED2").exists(), place)
|
||||
|
||||
@@ -105,6 +105,7 @@ class FakeRegistry(http.server.BaseHTTPRequestHandler):
|
||||
no_realm = False
|
||||
empty_token = False
|
||||
unknown = False # the repository does not exist yet
|
||||
not_found = None # a 404 body without NAME_UNKNOWN
|
||||
agents = None # a fresh list per test, set in setUp
|
||||
|
||||
def do_GET(self):
|
||||
@@ -128,6 +129,8 @@ class FakeRegistry(http.server.BaseHTTPRequestHandler):
|
||||
b"{}",
|
||||
extra={"WWW-Authenticate": f'Bearer realm="{realm}",service="reg"'},
|
||||
)
|
||||
elif self.not_found is not None:
|
||||
self.reply(404, self.not_found, "text/plain")
|
||||
elif self.unknown:
|
||||
body = {"errors": [{"code": "NAME_UNKNOWN", "message": "unknown"}]}
|
||||
self.reply(404, json.dumps(body).encode())
|
||||
@@ -155,6 +158,7 @@ class RegistryClient(unittest.TestCase):
|
||||
def setUp(self):
|
||||
FakeRegistry.refuse = FakeRegistry.refuse_token = FakeRegistry.no_realm = False
|
||||
FakeRegistry.empty_token = FakeRegistry.unknown = False
|
||||
FakeRegistry.not_found = None
|
||||
FakeRegistry.agents = []
|
||||
server = QuietServer(("127.0.0.1", 0), FakeRegistry)
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
@@ -176,6 +180,17 @@ class RegistryClient(unittest.TestCase):
|
||||
niv.next_version("0.1", self.registry.tags(), "c", no_label), "0.1.0"
|
||||
)
|
||||
|
||||
def test_a_404_without_name_unknown_is_a_registry_error(self):
|
||||
for body in (
|
||||
b"404 page not found",
|
||||
b'{"errors":[{"code":"NOT_FOUND","message":"no such route"}]}',
|
||||
):
|
||||
with self.subTest(body=body):
|
||||
FakeRegistry.not_found = body
|
||||
with self.assertRaises(niv.RegistryError) as caught:
|
||||
self.registry.tags()
|
||||
self.assertEqual(caught.exception.status, 404)
|
||||
|
||||
def test_a_missing_manifest_is_still_a_registry_error(self):
|
||||
FakeRegistry.unknown = True
|
||||
with self.assertRaises(niv.RegistryError) as caught:
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
# SPDX-FileCopyrightText: Defame1297 and contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Tests for scripts/run_molecule_in_ci_image.sh with stub tools in place of the molecule-controller
|
||||
"""Tests for scripts/run_molecule_in_controller.sh with stub tools in place of the molecule-controller
|
||||
image's.
|
||||
|
||||
Run with: python3 -m unittest discover -s tests/scripts
|
||||
@@ -14,7 +14,7 @@ import tempfile
|
||||
import unittest
|
||||
|
||||
REPO = pathlib.Path(__file__).resolve().parents[2]
|
||||
SCRIPT = REPO / "scripts" / "run_molecule_in_ci_image.sh"
|
||||
SCRIPT = REPO / "scripts" / "run_molecule_in_controller.sh"
|
||||
|
||||
# Each stub appends its name, arguments and the paths it saw to STUB_LOG; STUB_FAIL_<name> fails it.
|
||||
STUB = """#!/usr/bin/env bash
|
||||
@@ -50,7 +50,7 @@ echo "runner args=$* path=$PATH acp=$ANSIBLE_COLLECTIONS_PATH" \\
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which("bash"), "bash is required")
|
||||
class RunMoleculeInCiImageTest(unittest.TestCase):
|
||||
class RunMoleculeInControllerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = pathlib.Path(tempfile.mkdtemp(prefix="kamino-runci-")).resolve()
|
||||
self.addCleanup(shutil.rmtree, self.tmp, True)
|
||||
@@ -616,7 +616,7 @@ class WorkflowJobsTest(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
step["env"]["SELECTED"], "${{ needs.select.outputs.scenarios }}"
|
||||
)
|
||||
self.assertIn('run_molecule_in_ci_image.sh <<< "$SELECTED"', step["run"])
|
||||
self.assertIn('run_molecule_in_controller.sh <<< "$SELECTED"', step["run"])
|
||||
|
||||
def test_the_result_runs_whatever_the_others_ended_as(self):
|
||||
job = self.JOBS["result"]
|
||||
|
||||
@@ -217,6 +217,16 @@ class SelectTest(unittest.TestCase):
|
||||
chosen, _reason = self.select(["requirements-dev.txt", "requirements-dev.lock"])
|
||||
self.assertEqual(chosen, [])
|
||||
|
||||
def test_the_apm_pin_selects_nothing(self):
|
||||
chosen, _reason = self.select(["pyproject.toml", "uv.lock"])
|
||||
self.assertEqual(chosen, [])
|
||||
|
||||
def test_the_bot_diff_check_selects_nothing(self):
|
||||
chosen, _reason = self.select(
|
||||
["scripts/check_bot_pr_diff.py", "scripts/check_uv_lock.py"]
|
||||
)
|
||||
self.assertEqual(chosen, [])
|
||||
|
||||
def test_molecule_requirements_select_everything(self):
|
||||
# An ansible-core or molecule bump there changes the tools every scenario runs with.
|
||||
for path in ("requirements-molecule.txt", "requirements-molecule.lock"):
|
||||
|
||||
Reference in new issue
Block a user