Skip to content

A full-featured download manager.

fix(snap): isolate publication architecture from snap runtime (#2485)

Dr_rOot664f0d56602f
diff --git a/.github/workflows/snap-publish.yml b/.github/workflows/snap-publish.yml
index 8e0ef62e..66c02740 100644
--- a/.github/workflows/snap-publish.yml
+++ b/.github/workflows/snap-publish.yml
@@ -62,7 +62,7 @@ jobs:
matrix:
arch: [amd64, arm64]
env:
- SNAP_ARCH: ${{ matrix.arch }}
+ MOTRIX_SNAP_ARCH: ${{ matrix.arch }}
EXPECTED_VERSION: ${{ inputs.expected_version }}
SNAP_SOURCE: ${{ needs.preflight.outputs.source }}
steps:
@@ -105,7 +105,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install --yes squashfs-tools
- node scripts/verify-snap-artifact.mjs --snap "release/snap-verified/motrix_verified_${SNAP_ARCH}.snap" --arch "$SNAP_ARCH" --version "$EXPECTED_VERSION"
+ node scripts/verify-snap-artifact.mjs --snap "release/snap-verified/motrix_verified_${MOTRIX_SNAP_ARCH}.snap" --arch "$MOTRIX_SNAP_ARCH" --version "$EXPECTED_VERSION"
- name: Install Snapcraft 9
timeout-minutes: 10
diff --git a/.github/workflows/snap.yml b/.github/workflows/snap.yml
index efcb7aa4..ae09007c 100644
--- a/.github/workflows/snap.yml
+++ b/.github/workflows/snap.yml
@@ -205,6 +205,9 @@ jobs:
snapcraft-channel: 9.x/stable
- name: Verify publication client compatibility without Store credentials
+ # Exercise an ARM64 publication target even on the amd64 tooling host.
+ env:
+ MOTRIX_SNAP_ARCH: arm64
run: |
# shellcheck disable=SC2016
snap run --shell snapcraft -c 'exec "$SNAP/bin/python" scripts/upload_snap_revision.py check-client'
diff --git a/scripts/snap_publication.py b/scripts/snap_publication.py
index 567731df..ecf24b4a 100644
--- a/scripts/snap_publication.py
+++ b/scripts/snap_publication.py
@@ -221,7 +221,7 @@ def main():
source = json.loads(os.environ["SNAP_SOURCE"])
require(source["repository"] == repo, "Repository mismatch")
if mode == "download":
- arch = os.environ["SNAP_ARCH"]
+ arch = os.environ["MOTRIX_SNAP_ARCH"]
require(arch in ARCHES, "Unknown architecture")
download_snap(source, arch)
elif mode == "aggregate":
diff --git a/scripts/upload_snap_revision.py b/scripts/upload_snap_revision.py
index 439298d2..b511c6d9 100644
--- a/scripts/upload_snap_revision.py
+++ b/scripts/upload_snap_revision.py
@@ -125,6 +125,14 @@ def verify_before_release(get):
positive(found["revision"]) == revisions[arch], "Store receipt no longer releaseable")
+def publication_architecture():
+ # SNAP_ARCH belongs to snapd and describes the tooling snap's host, not
+ # the package being published by a cross-architecture upload runner.
+ arch = os.environ["MOTRIX_SNAP_ARCH"]
+ require(arch in ("amd64", "arm64"), "Invalid architecture")
+ return arch
+
+
def main():
if sys.argv[1:] == ["check-client"]:
# Exercise the real factory without credentials, network, or a host
@@ -133,14 +141,14 @@ def main():
from craft_store.auth import MemoryKeyring
keyring.set_keyring(MemoryKeyring())
store_getter()
+ require(publication_architecture() == "arm64", "Publication architecture was overwritten")
print("Snapcraft authenticated Store adapter initialization passed")
return
get = store_getter()
if len(sys.argv) == 2 and sys.argv[1] == "verify":
verify_before_release(get)
return
- arch = os.environ["SNAP_ARCH"]
- require(arch in ("amd64", "arm64"), "Invalid architecture")
+ arch = publication_architecture()
source = json.loads(os.environ["SNAP_SOURCE"])
version = os.environ["EXPECTED_VERSION"]
require(source["version"] == version, "Source version mismatch")
diff --git a/tests/scripts/test_snap_publication.py b/tests/scripts/test_snap_publication.py
index 5a8d5663..19b2822c 100644
--- a/tests/scripts/test_snap_publication.py
+++ b/tests/scripts/test_snap_publication.py
@@ -38,6 +38,14 @@ class UploadRecoveryTests(unittest.TestCase):
with self.subTest(permissions=permissions), self.assertRaises(ValueError):
verify_scope(whoami(permissions), "latest/edge", True)
+ def test_target_architecture_survives_snap_runtime_host_environment(self):
+ for target in ["amd64", "arm64"]:
+ for host in ["amd64", "arm64"]:
+ with self.subTest(target=target, host=host), patch.dict(upload.os.environ, {"MOTRIX_SNAP_ARCH": target, "SNAP_ARCH": host}):
+ self.assertEqual(upload.publication_architecture(), target)
+ with patch.dict(upload.os.environ, {"SNAP_ARCH": "amd64"}, clear=True), self.assertRaises(KeyError):
+ upload.publication_architecture()
+
def test_existing_hash_never_uploads_again(self):
result, mutation, _ = self.run_reconcile([revision()])
self.assertEqual(result["revision"], 119)
@@ -129,6 +137,7 @@ class StoreClientAdapterTests(unittest.TestCase):
"craft_store": SimpleNamespace(),
"craft_store.auth": SimpleNamespace(MemoryKeyring=lambda: "memory-only")}
with patch.dict(sys.modules, modules), \
+ patch.dict(upload.os.environ, {"MOTRIX_SNAP_ARCH": "arm64", "SNAP_ARCH": "amd64"}), \
patch.object(sys, "argv", ["upload_snap_revision.py", "check-client"]):
upload.main()
keyring.set_keyring.assert_called_once_with("memory-only")