Compare commits

...
Author SHA1 Message Date
pingqiuandClaude Opus 5.5 28075339ad ci(block): a failed asset listing stops the release job; refused assets never reach gh
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-06 08:03:13 -08:00
pingqiuandClaude Opus 5.5 90f6d7cfea ci(block): release job refuses an asset whose binaries are not executable
The release job lists the tarball (tar -tvzf) before SHA256SUMS and any
upload, and stops unless blockmaster, blockvolume and sw-block are all
present with exec bits for owner, group and other.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-06 07:55:43 -08:00
2 changed files with 50 additions and 3 deletions

No files matched your search

+18
View File
@@ -138,6 +138,24 @@ jobs:
cp seaweed-block/deploy/systemd/sw-block.tmpfiles.conf "$out/bin/sw-block.tmpfiles.conf"
asset="sw-block-${version}-linux-amd64.tar.gz"
tar -C "$out/bin" -czf "$out/$asset" blockmaster blockvolume sw-block sw-block.tmpfiles.conf
# Before any upload: every binary in the asset is executable as shipped (tar tvf).
# The listing is taken first, so a failed listing stops the job here.
listing=$(tar -tvzf "$out/$asset")
executables=0
while read -r perms _ _ _ _ name; do
case "$name" in
blockmaster|blockvolume|sw-block)
if [[ ! "$perms" =~ ^-..x..x..x$ ]]; then
echo "refusing to publish: $name in $asset is $perms, not executable" >&2
exit 1
fi
executables=$((executables + 1)) ;;
esac
done <<<"$listing"
if [ "$executables" != 3 ]; then
echo "refusing to publish: $asset lists $executables of 3 binaries" >&2
exit 1
fi
(cd "$out" && sha256sum "$asset" >SHA256SUMS)
prerelease=false
if [[ "$version" == *-* ]]; then prerelease=true; fi
+32 -3
View File
@@ -1,6 +1,6 @@
"""Exercise release packaging without Docker, GitHub writes or product builds."""
from pathlib import Path
import json, os, subprocess, tarfile, tempfile, unittest
import json, os, shutil, subprocess, tarfile, tempfile, unittest
HERE = Path(__file__).resolve().parent
REV = "a" * 40
@@ -8,6 +8,18 @@ DIGEST = "example.invalid/block@sha256:" + "b" * 64
class ReleaseAssets(unittest.TestCase):
def test_active_root_release_contains_tmpfiles(self):
self.run_active_root()
def test_active_root_release_refuses_an_archive_without_exec_bits(self):
# An archive whose binaries lost their exec bits (as a tar made off the
# Linux job does) stops the job before SHA256SUMS or any upload.
self.run_active_root(fault='strip-exec')
def test_active_root_release_stops_when_the_listing_fails(self):
# Three valid rows and then a failed listing still stop the job.
self.run_active_root(fault='list-fails')
def run_active_root(self, fault=None):
repo = HERE.parents[2]
workflow = (repo / '.github/workflows/block-release.yml').read_text()
step = workflow.split(' - name: Publish matching binary tarball\n', 1)[1]
@@ -20,22 +32,39 @@ class ReleaseAssets(unittest.TestCase):
for name in ('blockmaster', 'blockvolume', 'sw-block'):
(image / name).write_bytes(('#!/bin/sh\necho '+name+' release\n').encode())
(image / name).chmod(0o755)
real = shutil.which('tar')
if fault == 'strip-exec':
(tools / 'tar').write_text('#!/bin/sh\ncase "$*" in *-czf*) exec ' + real + ' --mode=a-x "$@";; esac\nexec ' + real + ' "$@"\n')
elif fault == 'list-fails':
(tools / 'tar').write_text('#!/bin/sh\ncase "$*" in *-tvzf*) ' + real + ' "$@"; exit 2;; esac\nexec ' + real + ' "$@"\n')
(tools / 'docker').write_text('''#!/usr/bin/env python3
import os,pathlib,shutil,sys
a=sys.argv[1:]
if a[0]=='create': print('owned-container')
elif a[0]=='cp': shutil.copy2(pathlib.Path(os.environ['IMAGE'])/a[1].rsplit('/',1)[1],a[2])
''')
(tools / 'gh').write_text('#!/bin/sh\nexit 0\n')
(tools / 'gh').write_text('#!/bin/sh\necho "$@" >>"$GH_CALLS"\nexit 0\n')
for tool in tools.iterdir(): tool.chmod(0o755)
env = dict(os.environ, PATH=str(tools)+os.pathsep+os.environ['PATH'],
IMAGE=str(image), RUNNER_TEMP=str(root), BLOCK_IMAGE='example/block',
BLOCK_DIGEST='sha256:'+'b'*64, GITHUB_REF_NAME='seaweed-block/v1.1.2',
GITHUB_REPOSITORY='example/block', NOTES=str(root/'notes'))
GITHUB_REPOSITORY='example/block', NOTES=str(root/'notes'),
GH_CALLS=str(root/'gh-calls'))
result = subprocess.run(['bash', '-c', script], cwd=repo, env=env,
capture_output=True, text=True, timeout=15)
if fault:
self.assertNotEqual(result.returncode, 0, result.stderr)
if fault == 'strip-exec':
self.assertIn('refusing to publish: blockmaster', result.stderr)
self.assertFalse((root/'block-release/SHA256SUMS').exists())
self.assertFalse((root/'gh-calls').exists(), 'gh ran after a refused asset')
return
self.assertEqual(result.returncode, 0, result.stderr)
self.assertTrue((root/'gh-calls').exists(), 'the control never reached gh')
with tarfile.open(root/'block-release/sw-block-v1.1.2-linux-amd64.tar.gz') as tar:
for member in tar.getmembers():
if member.name != 'sw-block.tmpfiles.conf':
self.assertEqual(member.mode & 0o111, 0o111, member.name)
self.assertEqual(set(tar.getnames()), {'blockmaster', 'blockvolume', 'sw-block', 'sw-block.tmpfiles.conf'})
self.assertEqual(tar.extractfile('sw-block.tmpfiles.conf').read(),
(repo/'seaweed-block/deploy/systemd/sw-block.tmpfiles.conf').read_bytes())