mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 22:37:29 +00:00
feat(packages): install a checksum-pinned vendor artefact where no repo exists
A vendor that ships a package file but runs no repository left the registry nothing to resolve, so cursor declared an empty list on Debian and RedHat and the role deployed while installing nothing. The new 'download' source names the artefact directly and pins it by digest: the URL alone would install whatever the vendor serves today. get_url verifies before and after the transfer, the artefact is cached root-owned so no other account can swap it in the window before the install, and a closing package call fails loudly when the artefact registered under a name other than the one declared. Cursor's rpm carries no signature, which is why dnf runs with disable_gpg_check; the digest is the integrity control. All 92 of its requirements resolve against Fedora 44 and CentOS Stream 10 repodata. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c15476a270
commit
66533e6b50
7 files changed
+359
-7
No files matched your search
@@ -7,16 +7,27 @@ from utils.packages.schema import (
|
||||
SOURCE_AUR,
|
||||
SOURCE_BUILD,
|
||||
SOURCE_COPR,
|
||||
SOURCE_DOWNLOAD,
|
||||
SOURCE_FLATPAK,
|
||||
PackageSpec,
|
||||
)
|
||||
from utils.packages.sources import (
|
||||
AUR_BUILDER_USER,
|
||||
DOWNLOAD_CACHE_DIR,
|
||||
FLATPAK_COMMAND_DIR,
|
||||
FLATPAK_EXPORT_DIR,
|
||||
PACMAN_CONF,
|
||||
)
|
||||
|
||||
_DEB = {
|
||||
"url": "https://vendor.example/pool/editor_1.2.3_amd64.deb",
|
||||
"checksum": "sha256:" + "a" * 64,
|
||||
}
|
||||
_RPM = {
|
||||
"url": "https://vendor.example/pool/editor-1.2.3.el8.x86_64.rpm",
|
||||
"checksum": "sha256:" + "b" * 64,
|
||||
}
|
||||
|
||||
|
||||
class TestExternalFetchRetries(unittest.TestCase):
|
||||
"""Every call that fetches over the network carries a retry policy, the
|
||||
@@ -200,6 +211,97 @@ class TestBuildPlan(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class TestDownloadSource(unittest.TestCase):
|
||||
"""A vendor artefact is fetched against its pin and installed from disk,
|
||||
so what the package manager receives is the file the registry describes."""
|
||||
|
||||
def test_the_deb_is_fetched_with_its_checksum_then_installed(self):
|
||||
plan = build_plan(
|
||||
PackageSpec(("editor",), source=SOURCE_DOWNLOAD, download=_DEB),
|
||||
STATE_PRESENT,
|
||||
)
|
||||
self.assertEqual(
|
||||
_modules(plan),
|
||||
[
|
||||
"ansible.builtin.file",
|
||||
"ansible.builtin.get_url",
|
||||
"ansible.builtin.apt",
|
||||
"ansible.builtin.package",
|
||||
],
|
||||
)
|
||||
cache, fetch, install, confirm = plan
|
||||
self.assertEqual(cache.args["path"], DOWNLOAD_CACHE_DIR)
|
||||
self.assertEqual(cache.args["owner"], "root")
|
||||
self.assertEqual(confirm.args["name"], ["editor"])
|
||||
self.assertEqual(fetch.args["url"], _DEB["url"])
|
||||
self.assertEqual(fetch.args["checksum"], _DEB["checksum"])
|
||||
self.assertEqual(
|
||||
fetch.args["dest"], f"{DOWNLOAD_CACHE_DIR}/editor_1.2.3_amd64.deb"
|
||||
)
|
||||
self.assertEqual(install.args["deb"], fetch.args["dest"])
|
||||
|
||||
def test_the_rpm_is_installed_from_the_fetched_path(self):
|
||||
plan = build_plan(
|
||||
PackageSpec(("editor",), source=SOURCE_DOWNLOAD, download=_RPM),
|
||||
STATE_PRESENT,
|
||||
)
|
||||
self.assertEqual(
|
||||
_modules(plan),
|
||||
[
|
||||
"ansible.builtin.file",
|
||||
"ansible.builtin.get_url",
|
||||
"ansible.builtin.dnf",
|
||||
"ansible.builtin.package",
|
||||
],
|
||||
)
|
||||
_cache, fetch, install, confirm = plan
|
||||
self.assertEqual(install.args["name"], [fetch.args["dest"]])
|
||||
self.assertEqual(install.args["state"], STATE_PRESENT)
|
||||
self.assertEqual(confirm.args["name"], ["editor"])
|
||||
|
||||
def test_an_unsupported_artefact_is_refused(self):
|
||||
spec = PackageSpec(
|
||||
("editor",),
|
||||
source=SOURCE_DOWNLOAD,
|
||||
download={"url": "https://vendor.example/editor.AppImage", "checksum": "x"},
|
||||
)
|
||||
with self.assertRaises(ValueError) as caught:
|
||||
build_plan(spec, STATE_PRESENT)
|
||||
self.assertIn(".AppImage", str(caught.exception))
|
||||
|
||||
def test_a_query_string_does_not_hide_the_artefact_type(self):
|
||||
spec = PackageSpec(
|
||||
("editor",),
|
||||
source=SOURCE_DOWNLOAD,
|
||||
download={**_DEB, "url": _DEB["url"] + "?token=abc"},
|
||||
)
|
||||
plan = build_plan(spec, STATE_PRESENT)
|
||||
self.assertEqual(plan[2].module, "ansible.builtin.apt")
|
||||
self.assertEqual(
|
||||
plan[1].args["dest"], f"{DOWNLOAD_CACHE_DIR}/editor_1.2.3_amd64.deb"
|
||||
)
|
||||
|
||||
def test_the_source_without_its_block_is_refused(self):
|
||||
spec = PackageSpec(("editor",), source=SOURCE_DOWNLOAD)
|
||||
with self.assertRaises(ValueError):
|
||||
build_plan(spec, STATE_PRESENT)
|
||||
|
||||
def test_the_fetch_is_retried(self):
|
||||
plan = build_plan(
|
||||
PackageSpec(("editor",), source=SOURCE_DOWNLOAD, download=_DEB),
|
||||
STATE_PRESENT,
|
||||
)
|
||||
self.assertIsNotNone(plan[1].retry)
|
||||
|
||||
def test_removal_goes_through_the_host_manager(self):
|
||||
plan = build_plan(
|
||||
PackageSpec(("editor",), source=SOURCE_DOWNLOAD, download=_DEB),
|
||||
STATE_ABSENT,
|
||||
)
|
||||
self.assertEqual(_modules(plan), ["ansible.builtin.package"])
|
||||
self.assertEqual(plan[0].args["name"], ["editor"])
|
||||
|
||||
|
||||
class TestFlatpakSource(unittest.TestCase):
|
||||
"""A Flatpak id is installed from a remote and exposed under the name the
|
||||
role actually invokes."""
|
||||
|
||||
@@ -165,6 +165,95 @@ class TestRegistry(unittest.TestCase):
|
||||
with self.assertRaises(PackagesShapeError):
|
||||
resolve(self._declaration("git"), "debian")
|
||||
|
||||
def test_download_without_a_checksum_raises(self):
|
||||
_write_role(
|
||||
self.root,
|
||||
"role-a",
|
||||
{
|
||||
"editor": {
|
||||
"Debian": {
|
||||
"names": ["editor"],
|
||||
"source": "download",
|
||||
"download": {"url": "https://vendor.example/editor.deb"},
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
with self.assertRaises(PackagesShapeError) as ctx:
|
||||
resolve(self._declaration("editor"), "debian")
|
||||
self.assertIn("checksum", str(ctx.exception))
|
||||
|
||||
def test_download_rejects_a_weak_digest(self):
|
||||
_write_role(
|
||||
self.root,
|
||||
"role-a",
|
||||
{
|
||||
"editor": {
|
||||
"Debian": {
|
||||
"names": ["editor"],
|
||||
"source": "download",
|
||||
"download": {
|
||||
"url": "https://vendor.example/editor.deb",
|
||||
"checksum": "md5:" + "a" * 32,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
with self.assertRaises(PackagesShapeError):
|
||||
resolve(self._declaration("editor"), "debian")
|
||||
|
||||
def test_download_rejects_a_plaintext_url(self):
|
||||
_write_role(
|
||||
self.root,
|
||||
"role-a",
|
||||
{
|
||||
"editor": {
|
||||
"Debian": {
|
||||
"names": ["editor"],
|
||||
"source": "download",
|
||||
"download": {
|
||||
"url": "http://vendor.example/editor.deb",
|
||||
"checksum": "sha256:" + "a" * 64,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
with self.assertRaises(PackagesShapeError) as ctx:
|
||||
resolve(self._declaration("editor"), "debian")
|
||||
self.assertIn("https", str(ctx.exception))
|
||||
|
||||
def test_download_source_without_its_block_raises(self):
|
||||
_write_role(
|
||||
self.root,
|
||||
"role-a",
|
||||
{"editor": {"Debian": {"names": ["editor"], "source": "download"}}},
|
||||
)
|
||||
with self.assertRaises(PackagesShapeError):
|
||||
resolve(self._declaration("editor"), "debian")
|
||||
|
||||
def test_a_pinned_download_resolves(self):
|
||||
_write_role(
|
||||
self.root,
|
||||
"role-a",
|
||||
{
|
||||
"editor": {
|
||||
"Debian": {
|
||||
"names": ["editor"],
|
||||
"source": "download",
|
||||
"download": {
|
||||
"url": "https://vendor.example/editor.deb",
|
||||
"checksum": "sha256:" + "a" * 64,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
spec = resolve(self._declaration("editor"), "debian")
|
||||
self.assertEqual(spec.source, "download")
|
||||
self.assertEqual(spec.download["url"], "https://vendor.example/editor.deb")
|
||||
|
||||
def test_unknown_distro_raises_without_family(self):
|
||||
_write_role(self.root, "role-a", {"git": {"Debian": ["git"]}})
|
||||
with self.assertRaises(PackagesShapeError):
|
||||
|
||||
Reference in new issue
Block a user