From e3acab9ca24fe5aca5c4cde728064d1a52a7b08b Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sun, 25 Oct 2026 18:23:42 +0000 Subject: [PATCH 1/4] fix(build): keep repository tooling and molecule scenarios out of the Collection archive Extend galaxy.yml build_ignore (extensions, role molecule scenarios, CLAUDE.md, tool directories, tests/scripts) and add scripts/check_tarball.py, an allow-list check run by the Build workflow after the Collection build and before galaxy-importer. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm --- .gitea/workflows/build.yml | 6 ++ .../fragments/collection-tarball-contents.yml | 5 ++ galaxy.yml | 14 +++++ scripts/check_tarball.py | 60 +++++++++++++++++++ tests/scripts/test_check_tarball.py | 28 +++++++++ 5 files changed, 113 insertions(+) create mode 100644 changelogs/fragments/collection-tarball-contents.yml create mode 100755 scripts/check_tarball.py create mode 100644 tests/scripts/test_check_tarball.py diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 762faff..7d06c68 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -91,6 +91,12 @@ jobs: ls -l /tmp/dist sha256sum /tmp/dist/*.tar.gz + # The archive is what consumers get: only the allow list of scripts/check_tarball.py. + - name: Check the archive contents + run: | + export PATH="/opt/venv/bin:$PATH" + python3 scripts/check_tarball.py /tmp/dist/mortis-kamino-*.tar.gz + # galaxy-importer without ansible-test and without Docker (ADR 0004, Collection # repo gates). The importer reads its configuration from this file. - name: Run galaxy-importer diff --git a/changelogs/fragments/collection-tarball-contents.yml b/changelogs/fragments/collection-tarball-contents.yml new file mode 100644 index 0000000..05d9ebe --- /dev/null +++ b/changelogs/fragments/collection-tarball-contents.yml @@ -0,0 +1,5 @@ +minor_changes: + - >- + The Collection archive no longer contains extensions/ (the image-smoke molecule scenario), + the roles' molecule scenarios, CLAUDE.md or other repository tooling; the Build workflow + now fails when the archive holds anything outside an allow list. diff --git a/galaxy.yml b/galaxy.yml index 7bb9fd3..1232eda 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -19,13 +19,27 @@ homepage: https://git.rkdr.net/mortis/kamino issues: https://git.rkdr.net/mortis/kamino/issues dependencies: {} build_ignore: + # Repository tooling that is not part of the Collection. scripts/check_tarball.py fails + # the build if anything outside its allowlist ends up in the archive, so a new top-level + # file is a decision: ignore it here or allow it there. + - .ansible + - .claude - .gitea - .gitignore - .pre-commit-config.yaml + - .reuse + - .venv - .yamllint - .ansible-lint + - CLAUDE.md - CONTRIBUTING.md + - HANDOFF.md + - extensions - images - scripts - requirements-dev.txt + - gitleaks-report.json + - importer_result.json + - tests/scripts + - 'roles/*/molecule' - '*.tar.gz' diff --git a/scripts/check_tarball.py b/scripts/check_tarball.py new file mode 100755 index 0000000..310e18b --- /dev/null +++ b/scripts/check_tarball.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# SPDX-FileCopyrightText: Defame1297 and contributors +# SPDX-License-Identifier: GPL-3.0-or-later +"""Assert that a built Collection tarball holds only files meant for consumers. + + scripts/check_tarball.py dist/mortis-kamino-X.Y.Z.tar.gz + +galaxy.yml `build_ignore` is a deny list: a new file at the repository root (a tool's +cache, an editor's directory, an agent's settings) ships silently. This check is the +allow list. A top-level entry that is not in ALLOWED_TOP, or a path under an entry that +matches FORBIDDEN, fails the build. When the Collection gains a plugin type or a +directory consumers should get, add it to ALLOWED_TOP in the same change. +""" +import fnmatch +import sys +import tarfile + +ALLOWED_TOP = { + "COPYING", "FILES.json", "LICENSES", "MANIFEST.json", "NOTICE", "README.md", + "REUSE.toml", "changelogs", "docs", "meta", "plugins", "roles", "tests", +} +# Checked on every member, whatever its top-level directory. +FORBIDDEN = [ + "*/molecule/*", "*/molecule", "tests/scripts*", "*.pyc", "*__pycache__*", "*.tar.gz", + "*.pem", "*.key", "*.vault*", "*vault-pass*", "*/.git/*", "*.env", "*importer_result.json", +] + + +def problems(names): + found = [] + for name in sorted(names): + path = name.rstrip("/") + if path.startswith("./"): + path = path[2:] + if not path: + continue + top = path.split("/", 1)[0] + if top not in ALLOWED_TOP: + found.append(f"{path}: top-level entry '{top}' is not allowed in the Collection archive") + elif any(fnmatch.fnmatch(path, pat) for pat in FORBIDDEN): + found.append(f"{path}: matches a forbidden pattern") + return found + + +def main(argv): + if len(argv) != 2: + sys.stderr.write(__doc__) + return 2 + with tarfile.open(argv[1]) as tar: + names = tar.getnames() + bad = problems(names) + if bad: + sys.stderr.write("Unexpected files in the Collection archive:\n " + "\n ".join(bad) + "\n") + return 1 + print(f"{argv[1]}: {len(names)} entries, all allowed") + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/tests/scripts/test_check_tarball.py b/tests/scripts/test_check_tarball.py new file mode 100644 index 0000000..d3eefdc --- /dev/null +++ b/tests/scripts/test_check_tarball.py @@ -0,0 +1,28 @@ +# 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 + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2] / "scripts")) +import check_tarball # noqa: E402 + + +class TarballTest(unittest.TestCase): + def test_clean(self): + self.assertEqual(check_tarball.problems( + ["README.md", "roles/", "roles/a/tasks/main.yml", "LICENSES/MIT.txt", "tests/sanity/x.txt"]), []) + + def test_stray_top_level(self): + for name in (".venv/lib/a.py", "CLAUDE.md", ".claude/settings.json", "importer_result.json", "extensions/m.yml"): + self.assertEqual(len(check_tarball.problems([name])), 1, name) + + def test_forbidden_inside_allowed(self): + self.assertEqual(len(check_tarball.problems(["roles/a/molecule/default/molecule.yml"])), 1) + self.assertEqual(len(check_tarball.problems(["roles/a/files/k.pem"])), 1) + self.assertEqual(len(check_tarball.problems(["tests/scripts/t.py"])), 1) + + +if __name__ == "__main__": + unittest.main() -- 2.43.0 From 580df0b892a5bd1f1b3122b0dd954446d489eb72 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sun, 25 Oct 2026 18:54:11 +0000 Subject: [PATCH 2/4] fix(build): reject links, special files and unsafe paths in the Collection archive check_tarball.py now iterates the tar members instead of their names. Only regular files and directories are allowed, so a symlink or hardlink cannot smuggle a file in under an allowed directory. Absolute paths and paths with an empty, '.', '..' or '.git' component are rejected, so roles/../.venv/x no longer passes the top-level allow list. Tests build crafted tarballs and run the script on them. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm --- .../fragments/collection-tarball-contents.yml | 4 +- scripts/check_tarball.py | 60 ++++++++++++---- tests/scripts/test_check_tarball.py | 69 +++++++++++++++++++ 3 files changed, 118 insertions(+), 15 deletions(-) diff --git a/changelogs/fragments/collection-tarball-contents.yml b/changelogs/fragments/collection-tarball-contents.yml index 05d9ebe..34681d7 100644 --- a/changelogs/fragments/collection-tarball-contents.yml +++ b/changelogs/fragments/collection-tarball-contents.yml @@ -2,4 +2,6 @@ minor_changes: - >- The Collection archive no longer contains extensions/ (the image-smoke molecule scenario), the roles' molecule scenarios, CLAUDE.md or other repository tooling; the Build workflow - now fails when the archive holds anything outside an allow list. + now fails when the archive holds anything outside an allow list, a member that is not a + regular file or directory (symlinks, hardlinks, devices), or a path that is absolute or + holds an empty, '..' or '.git' component. diff --git a/scripts/check_tarball.py b/scripts/check_tarball.py index 310e18b..5c87710 100755 --- a/scripts/check_tarball.py +++ b/scripts/check_tarball.py @@ -8,7 +8,8 @@ galaxy.yml `build_ignore` is a deny list: a new file at the repository root (a tool's cache, an editor's directory, an agent's settings) ships silently. This check is the allow list. A top-level entry that is not in ALLOWED_TOP, or a path under an entry that -matches FORBIDDEN, fails the build. When the Collection gains a plugin type or a +matches FORBIDDEN, fails the build, and so does a member that is not a regular file or +directory, or whose path is absolute or holds an empty, '.', '..' or '.git' component. When the Collection gains a plugin type or a directory consumers should get, add it to ALLOWED_TOP in the same change. """ import fnmatch @@ -26,19 +27,50 @@ FORBIDDEN = [ ] +def path_problems(name): + """Problems of one member path, as a list of messages (empty when the path is fine).""" + if name.startswith("/"): + return [f"{name}: absolute path"] + path = name.rstrip("/") + if path.startswith("./"): + path = path[2:] + if not path: + return [] + parts = path.split("/") + if "" in parts: + return [f"{path}: empty path component ('//')"] + if "." in parts or ".." in parts: + return [f"{path}: '.' or '..' path component"] + if ".git" in parts: + return [f"{path}: '.git' path component"] + if parts[0] not in ALLOWED_TOP: + return [f"{path}: top-level entry '{parts[0]}' is not allowed in the Collection archive"] + if any(fnmatch.fnmatch(path, pat) for pat in FORBIDDEN): + return [f"{path}: matches a forbidden pattern"] + return [] + + def problems(names): found = [] for name in sorted(names): - path = name.rstrip("/") - if path.startswith("./"): - path = path[2:] - if not path: - continue - top = path.split("/", 1)[0] - if top not in ALLOWED_TOP: - found.append(f"{path}: top-level entry '{top}' is not allowed in the Collection archive") - elif any(fnmatch.fnmatch(path, pat) for pat in FORBIDDEN): - found.append(f"{path}: matches a forbidden pattern") + found += path_problems(name) + return found + + +def member_problems(members): + """Check tarfile members: only regular files and directories, and only fine paths. + + Links, devices and fifos are rejected whatever their name: a symlink such as + roles/a/link -> /etc/passwd would ship the target's content on the consumer's side + (or make an extractor write outside its directory). + """ + found = [] + for member in sorted(members, key=lambda m: m.name): + if not (member.isreg() or member.isdir()): + kind = ("symlink" if member.issym() else "hardlink" if member.islnk() + else "device" if member.isdev() else "fifo" if member.isfifo() else "special file") + found.append(f"{member.name}: {kind} is not allowed in the Collection archive") + found += path_problems(member.name) return found @@ -47,12 +79,12 @@ def main(argv): sys.stderr.write(__doc__) return 2 with tarfile.open(argv[1]) as tar: - names = tar.getnames() - bad = problems(names) + members = tar.getmembers() + bad = member_problems(members) if bad: sys.stderr.write("Unexpected files in the Collection archive:\n " + "\n ".join(bad) + "\n") return 1 - print(f"{argv[1]}: {len(names)} entries, all allowed") + print(f"{argv[1]}: {len(members)} entries, all allowed") return 0 diff --git a/tests/scripts/test_check_tarball.py b/tests/scripts/test_check_tarball.py index d3eefdc..c9bdac7 100644 --- a/tests/scripts/test_check_tarball.py +++ b/tests/scripts/test_check_tarball.py @@ -1,8 +1,12 @@ # SPDX-FileCopyrightText: Defame1297 and contributors # SPDX-License-Identifier: GPL-3.0-or-later """Run with: python3 -m unittest discover -s tests/scripts""" +import io import pathlib +import subprocess import sys +import tarfile +import tempfile import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2] / "scripts")) @@ -24,5 +28,70 @@ class TarballTest(unittest.TestCase): self.assertEqual(len(check_tarball.problems(["tests/scripts/t.py"])), 1) +SCRIPT = pathlib.Path(__file__).resolve().parents[2] / "scripts" / "check_tarball.py" + + +class CraftedTarballTest(unittest.TestCase): + """Build tarballs by hand and run the script on them, as the Build workflow does.""" + + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + self.path = pathlib.Path(self.tmp.name) / "c.tar.gz" + + def build(self, *entries): + """entries: (name, type, linkname); type is a tarfile type constant.""" + with tarfile.open(self.path, "w:gz") as tar: + for name, typ, link in entries: + info = tarfile.TarInfo(name) + info.type = typ + info.linkname = link + data = b"x\n" if typ == tarfile.REGTYPE else None + info.size = len(data) if data else 0 + tar.addfile(info, io.BytesIO(data) if data else None) + + def check(self): + proc = subprocess.run([sys.executable, "-I", str(SCRIPT), str(self.path)], capture_output=True, text=True) + return proc.returncode, proc.stderr + + def test_legitimate_tarball_passes(self): + self.build(("roles", tarfile.DIRTYPE, ""), ("roles/a/tasks/main.yml", tarfile.REGTYPE, ""), + ("README.md", tarfile.REGTYPE, ""), ("LICENSES/MIT.txt", tarfile.REGTYPE, "")) + self.assertEqual(self.check()[0], 0) + + def assert_rejected(self, entry, text): + self.build(("README.md", tarfile.REGTYPE, ""), entry) + code, err = self.check() + self.assertEqual(code, 1, err) + self.assertIn(text, err) + + def test_symlink_is_rejected(self): + self.assert_rejected(("roles/a/link", tarfile.SYMTYPE, "/etc/passwd"), "symlink") + + def test_hardlink_is_rejected(self): + self.assert_rejected(("roles/a/hard", tarfile.LNKTYPE, "README.md"), "hardlink") + + def test_device_and_fifo_are_rejected(self): + self.assert_rejected(("roles/a/dev", tarfile.CHRTYPE, ""), "device") + self.assert_rejected(("roles/a/fifo", tarfile.FIFOTYPE, ""), "fifo") + + def test_parent_component_is_rejected(self): + self.assert_rejected(("roles/../.venv/x", tarfile.REGTYPE, ""), "'..'") + + def test_absolute_path_is_rejected(self): + self.assert_rejected(("/etc/cron.d/x", tarfile.REGTYPE, ""), "absolute") + + def test_empty_component_is_rejected(self): + self.assert_rejected(("roles//a/x", tarfile.REGTYPE, ""), "empty path component") + + def test_git_component_is_rejected(self): + self.assert_rejected(("roles/a/.git", tarfile.DIRTYPE, ""), "'.git'") + self.assert_rejected(("plugins/.git/config", tarfile.REGTYPE, ""), "'.git'") + + def test_existing_rules_still_apply(self): + self.assert_rejected((".venv/bin/x", tarfile.REGTYPE, ""), "top-level entry") + self.assert_rejected(("roles/a/molecule/default/m.yml", tarfile.REGTYPE, ""), "forbidden pattern") + + if __name__ == "__main__": unittest.main() -- 2.43.0 From b5751e14d62c85233fdb793f36353d7f432396a8 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sun, 25 Oct 2026 19:20:48 +0000 Subject: [PATCH 3/4] fix(build): harden the Collection archive check and refuse source symlinks check_tarball.py now compares path components case-insensitively (.GIT, Molecule), rejects backslashes and control or zero-width characters, duplicate members, an empty archive and a missing REQUIRED file, and reports an unreadable archive as one line. Drop the shebang and the executable bit and pass check= to subprocess.run so ansible-test sanity passes. ansible-galaxy dereferences symlinks, which the archive check cannot see, so the Build workflow fails when the source tree holds a symlink. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm --- .gitea/workflows/build.yml | 12 +++ .../fragments/collection-tarball-contents.yml | 6 +- scripts/check_tarball.py | 76 ++++++++++++++----- tests/scripts/test_check_tarball.py | 72 ++++++++++++++++-- 4 files changed, 143 insertions(+), 23 deletions(-) mode change 100755 => 100644 scripts/check_tarball.py diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 7d06c68..ec39e54 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -83,6 +83,18 @@ jobs: fi echo "Tag $TAG is annotated and matches galaxy.yml version $version" + # 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. + - name: Refuse symlinks in the source tree + run: | + links="$(find . -path ./.git -prune -o -path ./.venv -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" + exit 1 + fi + - name: Build the Collection run: | export PATH="/opt/venv/bin:$PATH" diff --git a/changelogs/fragments/collection-tarball-contents.yml b/changelogs/fragments/collection-tarball-contents.yml index 34681d7..1f102b4 100644 --- a/changelogs/fragments/collection-tarball-contents.yml +++ b/changelogs/fragments/collection-tarball-contents.yml @@ -4,4 +4,8 @@ minor_changes: the roles' molecule scenarios, CLAUDE.md or other repository tooling; the Build workflow now fails when the archive holds anything outside an allow list, a member that is not a regular file or directory (symlinks, hardlinks, devices), or a path that is absolute or - holds an empty, '..' or '.git' component. + holds an empty, '..' or '.git' component (compared case-insensitively), a backslash or a + control or zero-width character; it also fails on duplicate members, an empty archive or one + that lacks MANIFEST.json, FILES.json, COPYING, README.md, meta/runtime.yml or + changelogs/changelog.yaml, and on symlinks in the source tree (which ansible-galaxy would + dereference). diff --git a/scripts/check_tarball.py b/scripts/check_tarball.py old mode 100755 new mode 100644 index 5c87710..fe3b705 --- a/scripts/check_tarball.py +++ b/scripts/check_tarball.py @@ -1,25 +1,42 @@ -#!/usr/bin/env python3 # SPDX-FileCopyrightText: Defame1297 and contributors # SPDX-License-Identifier: GPL-3.0-or-later """Assert that a built Collection tarball holds only files meant for consumers. - scripts/check_tarball.py dist/mortis-kamino-X.Y.Z.tar.gz + python3 scripts/check_tarball.py dist/mortis-kamino-X.Y.Z.tar.gz galaxy.yml `build_ignore` is a deny list: a new file at the repository root (a tool's cache, an editor's directory, an agent's settings) ships silently. This check is the -allow list. A top-level entry that is not in ALLOWED_TOP, or a path under an entry that -matches FORBIDDEN, fails the build, and so does a member that is not a regular file or -directory, or whose path is absolute or holds an empty, '.', '..' or '.git' component. When the Collection gains a plugin type or a -directory consumers should get, add it to ALLOWED_TOP in the same change. +allow list. It fails the build for: + + * a top-level entry that is not in ALLOWED_TOP, or a path under an entry that matches + FORBIDDEN (both compared case-insensitively, so `.GIT` and `Molecule` do not slip by); + * a member that is not a regular file or directory; + * a path that is absolute or holds an empty, '.', '..' or '.git' component, a backslash, + or a control or zero-width character; + * two members with the same name; + * an empty archive, or one that lacks a file of REQUIRED; + * an archive that cannot be read (one line, exit 1). + +ansible-galaxy dereferences symlinks while building, so a symlink in the source tree +reaches the archive as a regular file and is invisible here; the Build workflow checks +the source tree for symlinks separately. + +When the Collection gains a plugin type or a directory consumers should get, add it to +ALLOWED_TOP in the same change. """ import fnmatch import sys import tarfile +import unicodedata ALLOWED_TOP = { "COPYING", "FILES.json", "LICENSES", "MANIFEST.json", "NOTICE", "README.md", "REUSE.toml", "changelogs", "docs", "meta", "plugins", "roles", "tests", } +# Every Collection archive built by ansible-galaxy holds these. +REQUIRED = { + "MANIFEST.json", "FILES.json", "COPYING", "README.md", "meta/runtime.yml", "changelogs/changelog.yaml", +} # Checked on every member, whatever its top-level directory. FORBIDDEN = [ "*/molecule/*", "*/molecule", "tests/scripts*", "*.pyc", "*__pycache__*", "*.tar.gz", @@ -27,25 +44,33 @@ FORBIDDEN = [ ] +def normalize(name): + """The member name without a leading './' and trailing '/'.""" + path = name.rstrip("/") + return path[2:] if path.startswith("./") else path + + def path_problems(name): """Problems of one member path, as a list of messages (empty when the path is fine).""" if name.startswith("/"): - return [f"{name}: absolute path"] - path = name.rstrip("/") - if path.startswith("./"): - path = path[2:] - if not path: - return [] + return [f"{name!r}: absolute path"] + if "\\" in name: + return [f"{name!r}: backslash in the path"] + odd = [c for c in name if unicodedata.category(c) in ("Cc", "Cf", "Zl", "Zp")] + if odd: + return [f"{name!r}: control or invisible character in the path"] + path = normalize(name) parts = path.split("/") if "" in parts: return [f"{path}: empty path component ('//')"] if "." in parts or ".." in parts: return [f"{path}: '.' or '..' path component"] - if ".git" in parts: + folded = [part.casefold() for part in parts] + if ".git" in folded: return [f"{path}: '.git' path component"] if parts[0] not in ALLOWED_TOP: return [f"{path}: top-level entry '{parts[0]}' is not allowed in the Collection archive"] - if any(fnmatch.fnmatch(path, pat) for pat in FORBIDDEN): + if any(fnmatch.fnmatchcase("/".join(folded), pat) for pat in FORBIDDEN): return [f"{path}: matches a forbidden pattern"] return [] @@ -74,13 +99,30 @@ def member_problems(members): return found +def archive_problems(members): + """All problems of an archive: members, duplicates, emptiness and the REQUIRED files.""" + if not members: + return ["the archive is empty"] + found = member_problems(members) + names = [normalize(m.name) for m in members] + for name in sorted({n for n in names if names.count(n) > 1}): + found.append(f"{name}: appears more than once in the archive") + present = {normalize(m.name) for m in members if m.isreg()} + found += [f"{name}: required file is missing" for name in sorted(REQUIRED - present)] + return found + + def main(argv): if len(argv) != 2: sys.stderr.write(__doc__) return 2 - with tarfile.open(argv[1]) as tar: - members = tar.getmembers() - bad = member_problems(members) + try: + with tarfile.open(argv[1]) as tar: + members = tar.getmembers() + except (tarfile.TarError, OSError, EOFError) as exc: + sys.stderr.write(f"cannot read {argv[1]}: {' '.join(str(exc).split())}\n") + return 1 + bad = archive_problems(members) if bad: sys.stderr.write("Unexpected files in the Collection archive:\n " + "\n ".join(bad) + "\n") return 1 diff --git a/tests/scripts/test_check_tarball.py b/tests/scripts/test_check_tarball.py index c9bdac7..0772e67 100644 --- a/tests/scripts/test_check_tarball.py +++ b/tests/scripts/test_check_tarball.py @@ -51,16 +51,25 @@ class CraftedTarballTest(unittest.TestCase): tar.addfile(info, io.BytesIO(data) if data else None) def check(self): - proc = subprocess.run([sys.executable, "-I", str(SCRIPT), str(self.path)], capture_output=True, text=True) + proc = subprocess.run([sys.executable, "-I", str(SCRIPT), str(self.path)], capture_output=True, text=True, + check=False) return proc.returncode, proc.stderr + def required(self, skip=()): + return [(name, tarfile.REGTYPE, "") for name in sorted(check_tarball.REQUIRED) if name not in skip] + def test_legitimate_tarball_passes(self): - self.build(("roles", tarfile.DIRTYPE, ""), ("roles/a/tasks/main.yml", tarfile.REGTYPE, ""), - ("README.md", tarfile.REGTYPE, ""), ("LICENSES/MIT.txt", tarfile.REGTYPE, "")) - self.assertEqual(self.check()[0], 0) + self.build(*self.required(), ("roles", tarfile.DIRTYPE, ""), ("roles/a/tasks/main.yml", tarfile.REGTYPE, ""), + ("LICENSES/MIT.txt", tarfile.REGTYPE, ""), ("meta", tarfile.DIRTYPE, "")) + code, err = self.check() + self.assertEqual(code, 0, err) + + def test_required_set_matches_a_real_build(self): + self.assertEqual(check_tarball.REQUIRED, { + "MANIFEST.json", "FILES.json", "COPYING", "README.md", "meta/runtime.yml", "changelogs/changelog.yaml"}) def assert_rejected(self, entry, text): - self.build(("README.md", tarfile.REGTYPE, ""), entry) + self.build(*self.required(), entry) code, err = self.check() self.assertEqual(code, 1, err) self.assertIn(text, err) @@ -88,6 +97,59 @@ class CraftedTarballTest(unittest.TestCase): self.assert_rejected(("roles/a/.git", tarfile.DIRTYPE, ""), "'.git'") self.assert_rejected(("plugins/.git/config", tarfile.REGTYPE, ""), "'.git'") + def test_case_variants_are_rejected(self): + self.assert_rejected(("roles/a/.GIT/config", tarfile.REGTYPE, ""), "'.git'") + self.assert_rejected(("roles/a/.Git", tarfile.DIRTYPE, ""), "'.git'") + self.assert_rejected(("roles/a/Molecule/default/m.yml", tarfile.REGTYPE, ""), "forbidden pattern") + self.assert_rejected(("roles/a/files/K.PEM", tarfile.REGTYPE, ""), "forbidden pattern") + self.assert_rejected(("tests/Scripts/t.py", tarfile.REGTYPE, ""), "forbidden pattern") + + def test_backslash_is_rejected(self): + self.assert_rejected(("roles\\a\\x.yml", tarfile.REGTYPE, ""), "backslash") + + def test_control_and_zero_width_characters_are_rejected(self): + for name in ("roles/a/x\u200b.yml", "roles/a/x\n.yml", "roles/a/\u202ex.yml", "roles/a/x\ty"): + self.assert_rejected((name, tarfile.REGTYPE, ""), "control or invisible") + + def test_duplicate_member_is_rejected(self): + self.assert_rejected(("README.md", tarfile.REGTYPE, ""), "appears more than once") + self.assert_rejected(("./README.md", tarfile.REGTYPE, ""), "appears more than once") + + def test_empty_archive_is_rejected(self): + self.build() + code, err = self.check() + self.assertEqual(code, 1, err) + self.assertIn("empty", err) + + def test_missing_required_file_is_rejected(self): + for name in sorted(check_tarball.REQUIRED): + self.build(*self.required(skip=(name,))) + code, err = self.check() + self.assertEqual(code, 1, name) + self.assertIn(f"{name}: required file is missing", err) + + def test_required_file_as_directory_does_not_count(self): + self.build(*self.required(skip=("COPYING",)), ("COPYING", tarfile.DIRTYPE, "")) + code, err = self.check() + self.assertEqual(code, 1, err) + self.assertIn("COPYING: required file is missing", err) + + def test_unreadable_archive_is_one_line(self): + self.path.write_bytes(b"not a tarball at all") + self.assert_one_line_failure(self.path, "cannot read") + self.assert_one_line_failure(pathlib.Path(self.tmp.name) / "missing.tar.gz", "cannot read") + self.build(*self.required()) + self.path.write_bytes(self.path.read_bytes()[:40]) # truncated + self.assert_one_line_failure(self.path, "cannot read") + + def assert_one_line_failure(self, path, text): + proc = subprocess.run([sys.executable, "-I", str(SCRIPT), str(path)], capture_output=True, text=True, + check=False) + self.assertEqual(proc.returncode, 1, proc.stderr) + self.assertNotIn("Traceback", proc.stderr) + self.assertIn(text, proc.stderr) + self.assertEqual(len(proc.stderr.strip().splitlines()), 1, proc.stderr) + def test_existing_rules_still_apply(self): self.assert_rejected((".venv/bin/x", tarfile.REGTYPE, ""), "top-level entry") self.assert_rejected(("roles/a/molecule/default/m.yml", tarfile.REGTYPE, ""), "forbidden pattern") -- 2.43.0 From cab2187c8982fd3c6d2d13425b12d10481da14b4 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sun, 25 Oct 2026 19:57:08 +0000 Subject: [PATCH 4/4] fix(ci): tighten the Collection archive check and make its guards testable The forbidden names widen to anything containing "vault", SSH keys, .envrc and .env* files. Names that Windows or macOS extraction would read differently are rejected (trailing space or dot, reserved device names, "::", 8.3 aliases of .git, non-ASCII spaces, surrogate/private-use/unassigned characters, components over 255 bytes), and the .git test compares after NFKC and case folding. Duplicates are compared case-insensitively, a name that is both a file and a directory is rejected, and only one slash is stripped. A unit test builds a real tarball with ansible-galaxy, another asserts the directories build.yml prunes are in galaxy.yml build_ignore, lint.yml runs tests/scripts, and the Build workflow fails unless exactly one tarball matches. The docstring states that file symlinks are invisible to the archive check. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm --- .gitea/workflows/build.yml | 20 ++- .gitea/workflows/lint.yml | 5 + .../fragments/collection-tarball-contents.yml | 5 + scripts/check_tarball.py | 78 +++++++++-- tests/scripts/test_check_tarball.py | 127 +++++++++++++++++- 5 files changed, 215 insertions(+), 20 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index ec39e54..b83474f 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -85,7 +85,11 @@ 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. + # 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, + # 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)" @@ -107,7 +111,12 @@ jobs: - name: Check the archive contents run: | export PATH="/opt/venv/bin:$PATH" - python3 scripts/check_tarball.py /tmp/dist/mortis-kamino-*.tar.gz + set -- /tmp/dist/mortis-kamino-*.tar.gz + if [ "$#" -ne 1 ] || [ ! -f "$1" ]; then + echo "::error::expected exactly one tarball in /tmp/dist, found $# match(es): $*" + exit 1 + fi + python3 scripts/check_tarball.py "$1" # galaxy-importer without ansible-test and without Docker (ADR 0004, Collection # repo gates). The importer reads its configuration from this file. @@ -120,8 +129,13 @@ jobs: RUN_ANSIBLE_LINT = False LOCAL_IMAGE_DOCKER = False CFG + set -- /tmp/dist/mortis-kamino-*.tar.gz + if [ "$#" -ne 1 ] || [ ! -f "$1" ]; then + echo "::error::expected exactly one tarball in /tmp/dist, found $# match(es): $*" + exit 1 + fi GALAXY_IMPORTER_CONFIG=/tmp/galaxy-importer.cfg \ - python3 -m galaxy_importer.main /tmp/dist/mortis-kamino-*.tar.gz + python3 -m galaxy_importer.main "$1" # Sanity tests need the collection at ansible_collections//. - name: Run ansible-test sanity diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index c2f3e27..cb4a286 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -67,6 +67,11 @@ jobs: export PATH="/opt/venv/bin:$PATH" pre-commit run --all-files --show-diff-on-failure + - name: Test the repository scripts + run: | + export PATH="/opt/venv/bin:$PATH" + python3 -m unittest discover -s tests/scripts + # The gitleaks hook scans --staged only, which is empty in a clean checkout, # so scan the PR's commits explicitly with the binary pre-commit built. - name: Scan PR commits for secrets diff --git a/changelogs/fragments/collection-tarball-contents.yml b/changelogs/fragments/collection-tarball-contents.yml index 1f102b4..dceb997 100644 --- a/changelogs/fragments/collection-tarball-contents.yml +++ b/changelogs/fragments/collection-tarball-contents.yml @@ -9,3 +9,8 @@ minor_changes: that lacks MANIFEST.json, FILES.json, COPYING, README.md, meta/runtime.yml or changelogs/changelog.yaml, and on symlinks in the source tree (which ansible-galaxy would dereference). + - >- + The archive check also rejects any file name containing "vault", SSH key and .envrc/.env* files, names that Windows or macOS extraction + would read differently (trailing space or dot, reserved device names such as CON or NUL, "::", 8.3 aliases of .git, non-ASCII spaces, + surrogate, private-use and unassigned characters, components over 255 bytes), case-insensitive duplicates and a name used as both a + file and a directory. The Build workflow fails with a clear message unless exactly one tarball was built. diff --git a/scripts/check_tarball.py b/scripts/check_tarball.py index fe3b705..347345f 100644 --- a/scripts/check_tarball.py +++ b/scripts/check_tarball.py @@ -11,20 +11,32 @@ allow list. It fails the build for: * a top-level entry that is not in ALLOWED_TOP, or a path under an entry that matches FORBIDDEN (both compared case-insensitively, so `.GIT` and `Molecule` do not slip by); * a member that is not a regular file or directory; - * a path that is absolute or holds an empty, '.', '..' or '.git' component, a backslash, - or a control or zero-width character; - * two members with the same name; + * a path that is absolute or holds an empty, '.', '..' or '.git' component (compared + after NFKC and case folding, so `.GIT`, a full-width `.git` and the 8.3 alias `GIT~1` + are caught), a backslash, or a control, zero-width, non-ASCII-space, surrogate, + private-use or unassigned character; + * a name that extraction on Windows or macOS reads differently: a component that ends in + a space or a dot, a reserved device name (CON, NUL, COM1, ... with or without an + extension), '::' (an NTFS stream), or a component longer than 255 bytes; + * two members with the same name, compared case-insensitively (a case-insensitive file + system would merge them), or a name that is both a file and a directory (COPYING and + COPYING/x); * an empty archive, or one that lacks a file of REQUIRED; * an archive that cannot be read (one line, exit 1). -ansible-galaxy dereferences symlinks while building, so a symlink in the source tree -reaches the archive as a regular file and is invisible here; the Build workflow checks -the source tree for symlinks separately. +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 +`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. When the Collection gains a plugin type or a directory consumers should get, add it to ALLOWED_TOP in the same change. """ import fnmatch +import re import sys import tarfile import unicodedata @@ -40,23 +52,48 @@ REQUIRED = { # Checked on every member, whatever its top-level directory. FORBIDDEN = [ "*/molecule/*", "*/molecule", "tests/scripts*", "*.pyc", "*__pycache__*", "*.tar.gz", - "*.pem", "*.key", "*.vault*", "*vault-pass*", "*/.git/*", "*.env", "*importer_result.json", + "*.pem", "*.key", "*vault*", "*/.git/*", "*.env", "*importer_result.json", + "*id_rsa*", "*id_ed25519*", "*.envrc", "*/.ssh", "*/.ssh/*", "*.env.*", "*/.env*", ".env*", ] +# Names Windows treats as devices, with or without an extension (and with trailing spaces). +WINDOWS_RESERVED = {"con", "prn", "aux", "nul", *(f"com{i}" for i in range(1, 10)), *(f"lpt{i}" for i in range(1, 10))} +MAX_COMPONENT_BYTES = 255 def normalize(name): - """The member name without a leading './' and trailing '/'.""" - path = name.rstrip("/") + """The member name without one leading './' and one trailing '/' (so 'a//' stays odd and is rejected).""" + path = name[:-1] if name.endswith("/") else name return path[2:] if path.startswith("./") else path +def fold(text): + """The comparison form of a name: NFKC and case folded.""" + return unicodedata.normalize("NFKC", text).casefold() + + +def component_problems(path, part): + """Names that mean something else once extracted on Windows or macOS.""" + if part.endswith((" ", ".")): + return [f"{path}: component {part!r} ends in a space or a dot (dropped on Windows)"] + if fold(part).split(".")[0].rstrip(" ") in WINDOWS_RESERVED: + return [f"{path}: component {part!r} is a reserved Windows device name"] + if "::" in part: + return [f"{path}: component {part!r} holds '::' (an NTFS stream)"] + if re.fullmatch(r"git~[0-9]+", fold(part)): + return [f"{path}: component {part!r} is an 8.3 alias of '.git'"] + if len(part.encode("utf-8", "surrogateescape")) > MAX_COMPONENT_BYTES: + return [f"{path}: a path component is longer than {MAX_COMPONENT_BYTES} bytes"] + return [] + + def path_problems(name): """Problems of one member path, as a list of messages (empty when the path is fine).""" if name.startswith("/"): return [f"{name!r}: absolute path"] if "\\" in name: return [f"{name!r}: backslash in the path"] - odd = [c for c in name if unicodedata.category(c) in ("Cc", "Cf", "Zl", "Zp")] + odd = [c for c in name if unicodedata.category(c) in ("Cc", "Cf", "Cs", "Co", "Cn", "Zl", "Zp") + or (unicodedata.category(c) == "Zs" and c != " ")] if odd: return [f"{name!r}: control or invisible character in the path"] path = normalize(name) @@ -65,9 +102,13 @@ def path_problems(name): return [f"{path}: empty path component ('//')"] if "." in parts or ".." in parts: return [f"{path}: '.' or '..' path component"] - folded = [part.casefold() for part in parts] + folded = [fold(part) for part in parts] if ".git" in folded: return [f"{path}: '.git' path component"] + for part in parts: + found = component_problems(path, part) + if found: + return found if parts[0] not in ALLOWED_TOP: return [f"{path}: top-level entry '{parts[0]}' is not allowed in the Collection archive"] if any(fnmatch.fnmatchcase("/".join(folded), pat) for pat in FORBIDDEN): @@ -105,8 +146,19 @@ def archive_problems(members): return ["the archive is empty"] found = member_problems(members) names = [normalize(m.name) for m in members] - for name in sorted({n for n in names if names.count(n) > 1}): - found.append(f"{name}: appears more than once in the archive") + keys = [fold(n) for n in names] + for key in sorted({k for k in keys if keys.count(k) > 1}): + same = sorted({n for n, k in zip(names, keys) if k == key}) + found.append(f"{' / '.join(same)}: appears more than once in the archive (names are compared " + "ignoring case)") + file_names = {fold(n): n for n, m in zip(names, members) if not m.isdir()} + for name in sorted(set(names)): + parts = name.split("/") + for i in range(1, len(parts)): + prefix = "/".join(parts[:i]) + message = f"{prefix}: is both a file and a directory in the archive" + if fold(prefix) in file_names and message not in found: + found.append(message) present = {normalize(m.name) for m in members if m.isreg()} found += [f"{name}: required file is missing" for name in sorted(REQUIRED - present)] return found diff --git a/tests/scripts/test_check_tarball.py b/tests/scripts/test_check_tarball.py index 0772e67..5bf45f2 100644 --- a/tests/scripts/test_check_tarball.py +++ b/tests/scripts/test_check_tarball.py @@ -3,13 +3,18 @@ """Run with: python3 -m unittest discover -s tests/scripts""" import io import pathlib +import re +import shutil import subprocess import sys import tarfile import tempfile import unittest -sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2] / "scripts")) +import yaml + +REPO = pathlib.Path(__file__).resolve().parents[2] +sys.path.insert(0, str(REPO / "scripts")) import check_tarball # noqa: E402 @@ -27,6 +32,56 @@ class TarballTest(unittest.TestCase): self.assertEqual(len(check_tarball.problems(["roles/a/files/k.pem"])), 1) self.assertEqual(len(check_tarball.problems(["tests/scripts/t.py"])), 1) + def test_widened_forbidden_names(self): + for name in ("roles/a/files/my_vault.yml", "roles/a/Vault-Pass.txt", "roles/a/vaultfile", "roles/a/id_rsa", + "roles/a/files/id_rsa.pub", "roles/a/id_ed25519", "roles/a/.envrc", "roles/a/.env", + "roles/a/.env.local", "roles/a/prod.env.bak", "roles/a/.ssh/config", "roles/a/files/.ssh"): + found = check_tarball.problems([name]) + self.assertEqual(len(found), 1, name) + self.assertIn("forbidden pattern", found[0], name) + + def test_ambiguous_names_are_rejected(self): + cases = { + "roles/a/x ": "ends in a space or a dot", + "roles/a/x.": "ends in a space or a dot", + "roles/a/dir /x": "ends in a space or a dot", + "roles/a/CON": "reserved Windows device name", + "roles/a/nul.txt": "reserved Windows device name", + "roles/a/Com1.yml": "reserved Windows device name", + "roles/a/LPT9": "reserved Windows device name", + "roles/a/aux.tar.gz": "reserved Windows device name", + "roles/a/f::$DATA": "NTFS stream", + "roles/a/GIT~1/config": "8.3 alias", + "roles/a/git~12": "8.3 alias", + "roles/a/\uff0egit/config": "'.git' path component", + "roles/a/x\u00a0y": "control or invisible", + "roles/a/x\u3000y": "control or invisible", + "roles/a/x\ud800y": "control or invisible", + "roles/a/x\ue000y": "control or invisible", + "roles/a/x\u0378y": "control or invisible", + "roles/a/" + "n" * 256: "longer than 255 bytes", + "roles/a/" + "\u00e9" * 128: "longer than 255 bytes", + } + for name, text in cases.items(): + found = check_tarball.problems([name]) + self.assertEqual(len(found), 1, name) + self.assertIn(text, found[0], name) + + def test_ordinary_names_still_pass(self): + ok = ["roles/a/my file.yml", "roles/a/console.yml", "roles/a/n" * 1 + "x", "roles/a/" + "n" * 255, + "roles/a/tasks/auxiliary.yml", "roles/a/.hidden", "roles/a/caf\u00e9.yml", "roles/a/git.yml"] + for name in ok: + self.assertEqual(check_tarball.problems([name]), [], name) + + def test_normalize_strips_one_slash_each_side_only(self): + self.assertEqual(check_tarball.normalize("./a/b"), "a/b") + self.assertEqual(check_tarball.normalize("a/b/"), "a/b") + self.assertEqual(check_tarball.normalize("a//"), "a/") + self.assertEqual(check_tarball.problems(["a//b"])[0].count("empty path component"), 1) + self.assertEqual(len(check_tarball.problems(["roles//a"])), 1) + self.assertEqual(len(check_tarball.problems(["roles/a//"])), 1) + self.assertEqual(check_tarball.problems(["./roles/a/x.yml", "roles/b/"]), []) + SCRIPT = pathlib.Path(__file__).resolve().parents[2] / "scripts" / "check_tarball.py" @@ -64,9 +119,59 @@ class CraftedTarballTest(unittest.TestCase): code, err = self.check() self.assertEqual(code, 0, err) - def test_required_set_matches_a_real_build(self): - self.assertEqual(check_tarball.REQUIRED, { - "MANIFEST.json", "FILES.json", "COPYING", "README.md", "meta/runtime.yml", "changelogs/changelog.yaml"}) + def test_required_file_present_only_as_dot_slash_name(self): + self.build(*self.required(skip=("COPYING",)), ("./COPYING", tarfile.REGTYPE, "")) + code, err = self.check() + self.assertEqual(code, 0, err) + + def test_double_slash_and_dot_slash_paths(self): + self.assert_rejected(("a//b", tarfile.REGTYPE, ""), "empty path component") + self.assert_rejected(("roles//a/x", tarfile.REGTYPE, ""), "empty path component") + self.build(*self.required(), ("./roles/a/x.yml", tarfile.REGTYPE, ""), ("./roles/", tarfile.DIRTYPE, "")) + code, err = self.check() + self.assertEqual(code, 0, err) + + def test_case_insensitive_duplicates_are_rejected(self): + self.assert_rejected(("readme.md", tarfile.REGTYPE, ""), "appears more than once") + self.build(*self.required(), ("roles/a/X.yml", tarfile.REGTYPE, ""), ("roles/a/x.YML", tarfile.REGTYPE, "")) + code, err = self.check() + self.assertEqual(code, 1, err) + self.assertIn("ignoring case", err) + self.build(*self.required(), ("roles/a/X.yml", tarfile.REGTYPE, ""), ("roles/a/y.yml", tarfile.REGTYPE, "")) + self.assertEqual(self.check()[0], 0) + + def test_file_and_directory_with_the_same_path_are_rejected(self): + self.assert_rejected(("COPYING/x", tarfile.REGTYPE, ""), "COPYING: is both a file and a directory") + self.assert_rejected(("copying/x", tarfile.REGTYPE, ""), "is both a file and a directory") + self.build(*self.required(), ("roles/a", tarfile.REGTYPE, ""), ("roles/a/x", tarfile.REGTYPE, "")) + code, err = self.check() + self.assertEqual(code, 1, err) + self.assertIn("roles/a: is both a file and a directory", err) + + def test_widened_and_ambiguous_names_through_the_script(self): + self.assert_rejected(("roles/a/secrets.vault.yml", tarfile.REGTYPE, ""), "forbidden pattern") + self.assert_rejected(("roles/a/CON.txt", tarfile.REGTYPE, ""), "reserved Windows device name") + self.assert_rejected(("roles/a/x.", tarfile.REGTYPE, ""), "ends in a space or a dot") + + def test_real_build_passes(self): + """Build the Collection with ansible-galaxy from a copy of this checkout and check it.""" + galaxy = shutil.which("ansible-galaxy") + if not galaxy: + self.skipTest("ansible-galaxy is not on PATH; the Build workflow covers the real archive") + src = pathlib.Path(self.tmp.name) / "src" + shutil.copytree(REPO, src, ignore=shutil.ignore_patterns(".git", ".venv", "__pycache__", "output", "*.tar.gz")) + out = pathlib.Path(self.tmp.name) / "dist" + build = subprocess.run([galaxy, "collection", "build", "--force", "--output-path", str(out), str(src)], + capture_output=True, text=True, check=False) + self.assertEqual(build.returncode, 0, build.stderr) + tarballs = list(out.glob("mortis-kamino-*.tar.gz")) + self.assertEqual(len(tarballs), 1, tarballs) + with tarfile.open(tarballs[0]) as tar: + names = {check_tarball.normalize(m.name) for m in tar.getmembers() if m.isreg()} + self.assertTrue(check_tarball.REQUIRED <= names, check_tarball.REQUIRED - names) + proc = subprocess.run([sys.executable, "-I", str(SCRIPT), str(tarballs[0])], capture_output=True, text=True, + check=False) + self.assertEqual(proc.returncode, 0, proc.stderr) def assert_rejected(self, entry, text): self.build(*self.required(), entry) @@ -155,5 +260,19 @@ class CraftedTarballTest(unittest.TestCase): self.assert_rejected(("roles/a/molecule/default/m.yml", tarfile.REGTYPE, ""), "forbidden pattern") +class BuildWorkflowTest(unittest.TestCase): + """The symlink guard of build.yml prunes directories that the build itself skips.""" + + # ansible-galaxy excludes these without being told (ansible.galaxy.collection, the default ignore list). + DEFAULT_EXCLUDED = {".git"} + + def test_pruned_directories_are_not_built(self): + workflow = (REPO / ".gitea" / "workflows" / "build.yml").read_text() + pruned = set(re.findall(r"-path \./(\S+) -prune", workflow)) + self.assertTrue(pruned, "no -prune target found in build.yml; update this test with the step") + ignored = set(yaml.safe_load((REPO / "galaxy.yml").read_text())["build_ignore"]) | self.DEFAULT_EXCLUDED + self.assertEqual(sorted(pruned - ignored), [], "build.yml prunes a directory that the build does not skip") + + if __name__ == "__main__": unittest.main() -- 2.43.0