mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Fix PhotoCraft Nightly signer inputs and macOS notice layout (#17231)
* Fix PhotoCraft Nightly signer inputs and macOS notice layout * Test the nightly environment guard with a spaced YAML key * Check nightly environment bindings structurally
This commit is contained in:
1 parent
345716309b
commit
610c86b969
6 files changed
+225
-16
No files matched your search
@@ -4,10 +4,10 @@
|
||||
"repository_id": 1398080271,
|
||||
"producer_workflow_id": 428462603,
|
||||
"producer_workflow_path": ".github/workflows/nightly.yml",
|
||||
"producer_tooling_revision": "8389cad8b849ea6bdb5e15fbce16772c3457565a",
|
||||
"producer_workflow_ref": "storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@8389cad8b849ea6bdb5e15fbce16772c3457565a",
|
||||
"producer_tooling_revision": "bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3",
|
||||
"producer_workflow_ref": "storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3",
|
||||
"signer_workflow_path": ".github/workflows/nightly-sign.yml",
|
||||
"signer_tooling_revision": "8389cad8b849ea6bdb5e15fbce16772c3457565a",
|
||||
"signer_tooling_revision": "bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3",
|
||||
"release_branch": "nightly-signer",
|
||||
"manual_actors": [
|
||||
"bflatastic",
|
||||
|
||||
@@ -35,12 +35,25 @@ jobs:
|
||||
checks: read
|
||||
attestations: write
|
||||
id-token: write
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-release.yml@8389cad8b849ea6bdb5e15fbce16772c3457565a
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-release.yml@bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3
|
||||
with:
|
||||
tooling-revision: 8389cad8b849ea6bdb5e15fbce16772c3457565a
|
||||
tooling-revision: bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3
|
||||
app-name: photocraft
|
||||
producer_run_id: ${{ inputs.producer_run_id }}
|
||||
producer_run_attempt: ${{ inputs.producer_run_attempt }}
|
||||
# No secrets: inherit or raw platform values in this caller. Only the isolated native
|
||||
# callee job may bind the existing release environment (which trusts release and
|
||||
# nightly-signer) and export keys in its signing step.
|
||||
# Declare only same-name inputs required by the reusable signer. Only native callee
|
||||
# signing jobs bind the release environment; do not copy credentials to caller scope.
|
||||
secrets:
|
||||
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
|
||||
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
|
||||
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
|
||||
APPLE_ID: ${{ secrets.APPLE_ID }}
|
||||
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
|
||||
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
|
||||
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
|
||||
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
|
||||
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
|
||||
AZURE_SIGNING_ENDPOINT: ${{ secrets.AZURE_SIGNING_ENDPOINT }}
|
||||
AZURE_SIGNING_ACCOUNT: ${{ secrets.AZURE_SIGNING_ACCOUNT }}
|
||||
AZURE_CERT_PROFILE: ${{ secrets.AZURE_CERT_PROFILE }}
|
||||
LINUX_SIGNING_KEY: ${{ secrets.LINUX_SIGNING_KEY }}
|
||||
@@ -22,9 +22,9 @@ jobs:
|
||||
actions: read
|
||||
attestations: write
|
||||
id-token: write
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@8389cad8b849ea6bdb5e15fbce16772c3457565a
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3
|
||||
with:
|
||||
tooling-revision: 8389cad8b849ea6bdb5e15fbce16772c3457565a
|
||||
tooling-revision: bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3
|
||||
app-name: photocraft
|
||||
manual-actors: '["bflatastic","dylanmtaylor","echelon","FredApps","skylartaylor"]'
|
||||
craft-fonts-ref: cc9269cd8d8258785dac603fba3122e5d2556795
|
||||
|
||||
@@ -33,11 +33,12 @@ OUTPUT="$DIST/photocraft-$VERSION-macos-aarch64-nightly.zip"
|
||||
nightly_compile_gui
|
||||
|
||||
APP="$NIGHTLY_WORK/stage/$MAC_NIGHTLY_APP"
|
||||
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"
|
||||
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources/docs"
|
||||
cp "$NIGHTLY_GUI" "$APP/Contents/MacOS/PhotoCraft"
|
||||
chmod 755 "$APP/Contents/MacOS/PhotoCraft"
|
||||
cp "$ROOT/assets/app-icon/photocraft-nightly.icns" "$APP/Contents/Resources/photocraft-nightly.icns"
|
||||
nightly_copy_notices "$APP/Contents/Resources"
|
||||
# Launcher admits notices under Resources/docs, not beside the icon.
|
||||
nightly_copy_notices "$APP/Contents/Resources/docs"
|
||||
# The private mktemp cwd is the helper authority root: stage the template inside it.
|
||||
cp "$HERE/Info.plist.in" "$NIGHTLY_WORK/Info.plist.in"
|
||||
(cd "$NIGHTLY_WORK" && python3 "$HERE/nightly_plist.py" --template Info.plist.in \
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
"""The macOS Nightly signing and verification scripts, run on any POSIX host against generated
|
||||
fixtures and stand-in Apple tools (codesign, notarytool, stapler, spctl, security, ditto, plutil,
|
||||
lipo) that log their arguments. This proves the scripts' order, refusals and cleanup; it is not a
|
||||
real signature, notarization or Mac run."""
|
||||
lipo) that log their arguments. The unsigned producer also runs with a stub GUI build. These
|
||||
check the scripts and bundle layout, not native signing, notarization or Mac execution."""
|
||||
import base64
|
||||
import importlib.util
|
||||
import json
|
||||
@@ -27,6 +27,8 @@ COMMIT = "b" * 40
|
||||
VERSION = "0.23.1-nightly.20261123.4567.1.g" + COMMIT[:12]
|
||||
ASSET = f"photocraft-{VERSION}-macos-aarch64-nightly.zip"
|
||||
APP = "PhotoCraft Nightly.app"
|
||||
APP_NOTICES = ("README.md", "LICENSE-MIT", "LICENSE-APACHE", "NOTICE", "ATTRIBUTION.md")
|
||||
OPTIONAL_NOTICES = ("LICENSE", "COPYRIGHT")
|
||||
TEAM = "ABCDE12345"
|
||||
IDENTITY = "0123456789ABCDEF0123456789ABCDEF01234567"
|
||||
SECRETS = {
|
||||
@@ -183,6 +185,50 @@ class Fixture:
|
||||
z.writestr(info, b"" if path.is_dir() else path.read_bytes())
|
||||
return self.input
|
||||
|
||||
def package(self, font_licences):
|
||||
"""Drive the real producer from a clean fixture checkout, without Cargo or Apple tools."""
|
||||
source = HERE.parents[1]
|
||||
checkout = self.root / "source"
|
||||
checkout.mkdir()
|
||||
notices = APP_NOTICES + tuple(name for name in OPTIONAL_NOTICES if (source / name).is_file())
|
||||
for relative in (*notices, "packaging/env.sh", "packaging/nightly-common.sh", "packaging/nightly_paths.py",
|
||||
"packaging/macos/nightly.sh", "packaging/macos/nightly-lib.sh",
|
||||
"packaging/macos/Info.plist.in", "packaging/macos/nightly_plist.py",
|
||||
"assets/app-icon/photocraft-nightly.icns"):
|
||||
target = checkout / relative
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(source / relative, target)
|
||||
env = self.env(**dict.fromkeys(SECRETS))
|
||||
|
||||
def git(*args):
|
||||
return subprocess.run(["git", "-c", "core.hooksPath=/dev/null", "-c", "commit.gpgsign=false", *args],
|
||||
cwd=checkout, env=env, check=True, capture_output=True, text=True, timeout=30).stdout
|
||||
|
||||
git("init", "-q")
|
||||
git("add", "--", ".")
|
||||
git("-c", "user.name=Fixture", "-c", "[email protected]", "commit", "-qm", "Packaging fixture")
|
||||
commit = git("rev-parse", "HEAD").strip()
|
||||
version = VERSION[:-12] + commit[:12]
|
||||
# Generated licence text exercises the copier without depending on a font checkout.
|
||||
fonts = self.root / "craft-fonts"
|
||||
for family, data in font_licences.items():
|
||||
licence = fonts / "fonts" / family / "OFL.txt"
|
||||
licence.parent.mkdir(parents=True)
|
||||
licence.write_bytes(data)
|
||||
# The existing cargo stub fails for every invocation. Only this producer fixture emits a GUI.
|
||||
(self.bin / "cargo").write_text(
|
||||
'#!/bin/sh\nset -eu\n'
|
||||
'gui="$CARGO_TARGET_DIR/aarch64-apple-darwin/release/photocraft"\n'
|
||||
'mkdir -p "$(dirname "$gui")"\n'
|
||||
"printf \"#!/bin/sh\\necho 'PhotoCraft %s (nightly-v1)'\\n\" \"$PHOTOCRAFT_VERSION\" >\"$gui\"\n",
|
||||
)
|
||||
result = self.run(checkout / "packaging/macos/nightly.sh", "--arch", "aarch64", **dict.fromkeys(SECRETS),
|
||||
DIST=str(self.dist), CARGO_TARGET_DIR=str(self.root / "target"), CRAFT_FONTS_DIR=str(fonts),
|
||||
PHOTOCRAFT_BUILD_CHANNEL="nightly-v1", PHOTOCRAFT_VERSION=version,
|
||||
PHOTOCRAFT_BUILD_SHA=commit, PHOTOCRAFT_BUILD_DATE="2026-11-23")
|
||||
assert result.returncode == 0, result.stdout
|
||||
return self.dist / ASSET.replace(VERSION, version)
|
||||
|
||||
def env(self, **changes):
|
||||
env = {"PATH": f"{self.bin}:{os.environ['PATH']}", "HOME": str(self.root), "SHIM_LOG": str(self.log),
|
||||
"SHIM_TEAM": TEAM, "SHIM_IDENTITY": IDENTITY, "RUNNER_TEMP": str(self.temp), **SECRETS}
|
||||
@@ -410,6 +456,40 @@ class Verify(unittest.TestCase):
|
||||
|
||||
|
||||
class Build(unittest.TestCase):
|
||||
def test_unsigned_archive_has_launcher_layout_and_keeps_all_notices(self):
|
||||
f = Fixture(self)
|
||||
fonts = {"fixture-one": b"generated font notice one", "fixture-two": b"generated font notice two"}
|
||||
archive = f.package(fonts)
|
||||
source = HERE.parents[1]
|
||||
resources = f"{APP}/Contents/Resources"
|
||||
icon = "photocraft-nightly.icns"
|
||||
notice_files = {name: (source / name).read_bytes() for name in APP_NOTICES}
|
||||
notice_files.update({name: (source / name).read_bytes() for name in OPTIONAL_NOTICES if (source / name).is_file()})
|
||||
notice_files.update({f"OFL-{family}.txt": data for family, data in fonts.items()})
|
||||
# Shipped Launcher v0.20.3 accepts these leaves only in Resources/docs, except for the root icon.
|
||||
expected_files = {f"{resources}/docs/{name}": data for name, data in notice_files.items()}
|
||||
expected_files[f"{resources}/{icon}"] = (source / "assets/app-icon" / icon).read_bytes()
|
||||
contents = f"{APP}/Contents"
|
||||
gui = f"{contents}/MacOS/PhotoCraft"
|
||||
with zipfile.ZipFile(archive) as zipped:
|
||||
entries = zipped.infolist()
|
||||
names = {entry.filename for entry in entries}
|
||||
self.assertEqual(len(entries), len({name.casefold() for name in names}), "unique paths, ignoring case")
|
||||
self.assertEqual({entry.filename for entry in entries if not entry.is_dir()},
|
||||
set(expected_files) | {gui, f"{contents}/Info.plist", f"{contents}/PkgInfo"})
|
||||
self.assertTrue({entry.filename for entry in entries if entry.is_dir()} <= {
|
||||
f"{APP}/", f"{contents}/", f"{contents}/MacOS/", f"{resources}/", f"{resources}/docs/"})
|
||||
for path, data in expected_files.items():
|
||||
with self.subTest(path=path):
|
||||
self.assertEqual(zipped.read(path), data)
|
||||
mode = zipped.getinfo(path).external_attr >> 16
|
||||
self.assertTrue(stat.S_ISREG(mode))
|
||||
self.assertFalse(mode & 0o111)
|
||||
mode = zipped.getinfo(gui).external_attr >> 16
|
||||
self.assertTrue(stat.S_ISREG(mode) and mode & stat.S_IXUSR)
|
||||
result = f.run("nightly-verify.sh", "--input", archive, "--expect", "unsigned", **dict.fromkeys(SECRETS))
|
||||
self.assertEqual(result.returncode, 0, result.stdout)
|
||||
|
||||
def test_compilation_refuses_signing_material_before_building(self):
|
||||
f = Fixture(self)
|
||||
for name in ("APPLE_CERTIFICATE", "APPLE_PASSWORD", "MACOS_SIGN_IDENTITY", "WINDOWS_CERTIFICATE", "AZURE_CLIENT_SECRET", "LINUX_SIGNING_KEY"):
|
||||
|
||||
@@ -182,6 +182,95 @@ def producer_platforms(source):
|
||||
return platforms
|
||||
|
||||
|
||||
# The pinned nightly-apps.json PhotoCraft row has Windows, Linux and macOS targets.
|
||||
# These are the corresponding names from the pinned nightly_signer_settings.py.
|
||||
NIGHTLY_SIGNER_SECRETS = {
|
||||
"APPLE_CERTIFICATE", "APPLE_CERTIFICATE_PASSWORD", "APPLE_ID", "APPLE_PASSWORD",
|
||||
"APPLE_TEAM_ID", "KEYCHAIN_PASSWORD", "LINUX_SIGNING_KEY", "AZURE_CERT_PROFILE",
|
||||
"AZURE_CLIENT_ID", "AZURE_CLIENT_SECRET", "AZURE_SIGNING_ACCOUNT",
|
||||
"AZURE_SIGNING_ENDPOINT", "AZURE_TENANT_ID",
|
||||
}
|
||||
|
||||
|
||||
def assert_nightly_caller_secrets(source, signer):
|
||||
"""Check the callers' plain block layout without adding a YAML dependency to CI.
|
||||
|
||||
This is a narrow source guard, not a YAML parser. Noncanonical job/key syntax
|
||||
fails closed; the shared signer preflight separately parses YAML.
|
||||
"""
|
||||
lines = [line for line in source.splitlines() if line.strip() and not line.lstrip().startswith("#")]
|
||||
roots = [line for line in lines if line == line.lstrip()]
|
||||
if (not roots or roots[-1] != "jobs:" or
|
||||
any(not re.fullmatch(r"(?:name|on|permissions|concurrency):(?: .*)?", line)
|
||||
for line in roots[:-1])):
|
||||
raise ValueError("expected one plain root jobs block")
|
||||
job = "release" if signer else "unsigned"
|
||||
start = lines.index("jobs:")
|
||||
if any(re.search(r"\bsecrets\b", line, re.IGNORECASE) for line in lines[:start]):
|
||||
raise ValueError("no secret references outside the signer mapping")
|
||||
if lines[start + 1:start + 2] != [f" {job}:"]:
|
||||
raise ValueError(f"expected one plain {job} job")
|
||||
keys, mapping = set(), {}
|
||||
field = None
|
||||
for line in lines[start + 2:]:
|
||||
if not line.startswith(" "):
|
||||
match = re.fullmatch(r" (if|permissions|uses|with|secrets):(?: .+)?", line)
|
||||
if match is None or match[1] in keys:
|
||||
raise ValueError("expected unique plain caller job keys and no environment binding")
|
||||
field = match[1]
|
||||
keys.add(field)
|
||||
if field == "secrets" and (not signer or line != " secrets:"):
|
||||
raise ValueError("only the signer may declare a plain secrets mapping")
|
||||
elif field == "secrets":
|
||||
match = re.fullmatch(r" ([A-Z][A-Z0-9_]*): \$\{\{ secrets\.([A-Z][A-Z0-9_]*) \}\}", line)
|
||||
if match is None or match[1] in mapping:
|
||||
raise ValueError("expected unique literal secret references")
|
||||
mapping[match[1]] = match[2]
|
||||
continue
|
||||
if field != "secrets" and re.search(r"\bsecrets\b", line, re.IGNORECASE):
|
||||
raise ValueError("no secret references outside the signer mapping")
|
||||
if signer and mapping != {name: name for name in NIGHTLY_SIGNER_SECRETS}:
|
||||
raise ValueError("the signer must forward exactly the target-specific same-name references")
|
||||
|
||||
|
||||
class NightlyCallerSecrets(unittest.TestCase):
|
||||
SIGNER = ROOT / ".github/workflows/nightly-sign.yml"
|
||||
UNSIGNED = ROOT / ".github/workflows/nightly.yml"
|
||||
|
||||
def test_signer_forwards_exactly_the_target_specific_secret_names(self):
|
||||
assert_nightly_caller_secrets(self.SIGNER.read_text(), signer=True)
|
||||
|
||||
def test_unsigned_caller_has_no_secret_inputs(self):
|
||||
assert_nightly_caller_secrets(self.UNSIGNED.read_text(), signer=False)
|
||||
|
||||
def test_signer_refuses_noncanonical_or_mismatched_forwarding(self):
|
||||
source = self.SIGNER.read_text()
|
||||
start = " secrets:\n"
|
||||
key = " LINUX_SIGNING_KEY: ${{ secrets.LINUX_SIGNING_KEY }}\n"
|
||||
self.assertIn(start, source)
|
||||
self.assertIn(key, source)
|
||||
for case, bad in {
|
||||
"missing": source.replace(key, ""),
|
||||
"extra": source.replace(key, key + " UNUSED: ${{ secrets.UNUSED }}\n"),
|
||||
"different name": source.replace(key, key.replace("secrets.LINUX_SIGNING_KEY", "secrets.APPLE_ID")),
|
||||
"duplicate name": source.replace(key, key + key),
|
||||
"duplicate map": source.replace(start, start + start),
|
||||
"inherit": source.replace(start, " secrets: inherit\n"),
|
||||
"YAML anchor": source.replace(start, " secrets: &forwarded\n"),
|
||||
"YAML alias": source.replace(key, key.replace("${{ secrets.LINUX_SIGNING_KEY }}", "*forwarded")),
|
||||
"environment binding": source.replace(start, " environment: release\n" + start),
|
||||
}.items():
|
||||
with self.subTest(case=case), self.assertRaises(ValueError):
|
||||
assert_nightly_caller_secrets(bad, signer=True)
|
||||
|
||||
def test_unsigned_refuses_a_secret_map_or_reference(self):
|
||||
source = self.UNSIGNED.read_text()
|
||||
for extra in (" secrets: inherit\n", " secrets: {}\n", " 'secrets': {}\n",
|
||||
" unintended: ${{ secrets['UNUSED'] }}\n"):
|
||||
with self.subTest(extra=extra), self.assertRaises(ValueError):
|
||||
assert_nightly_caller_secrets(source + extra, signer=False)
|
||||
|
||||
|
||||
class Response:
|
||||
status = 204
|
||||
|
||||
@@ -467,8 +556,29 @@ class TrustedSourcePreparation(unittest.TestCase):
|
||||
with self.subTest(workflow=name):
|
||||
self.assertNotRegex(executable, r"(?im)^\s*(?:-\s*)?uses:\s*[^\n]*cache")
|
||||
self.assertNotRegex(executable, r"(?im)^\s*[^\s:#]*cache[^\s:#]*:")
|
||||
self.assertNotRegex(executable, r"(?im)^\s*(?:environment|secrets):")
|
||||
self.assertNotIn("secrets.", executable)
|
||||
self.assertEqual(workflow_environment_problems(source), [], "app callers must not bind an environment")
|
||||
if name != "nightly-sign.yml":
|
||||
self.assertNotRegex(executable, r"(?im)^\s*secrets:")
|
||||
self.assertNotIn("secrets.", executable)
|
||||
|
||||
def test_generic_closure_recognizes_environment_keys_in_each_caller(self):
|
||||
for name in ("nightly.yml", "nightly-sign.yml", "nightly-dispatch.yml"):
|
||||
source = (ROOT / ".github/workflows" / name).read_text()
|
||||
job_field = " if: >-\n"
|
||||
self.assertEqual(workflow_environment_problems(source), [], name)
|
||||
for key in ("environment:", "environment :"):
|
||||
with self.subTest(workflow=name, key=key):
|
||||
with_binding = source.replace(job_field, f" {key} release\n" + job_field, 1)
|
||||
self.assertNotEqual(source, with_binding)
|
||||
self.assertRegex("\n".join(workflow_environment_problems(with_binding)),
|
||||
r"(?m)^line \d+: direct environment key$")
|
||||
|
||||
def test_generic_closure_ignores_environment_text_in_dispatch_script(self):
|
||||
source = DISPATCHER.read_text()
|
||||
with_annotation = source.replace(" import json\n",
|
||||
' environment : str = "release"\n import json\n', 1)
|
||||
self.assertNotEqual(source, with_annotation)
|
||||
self.assertEqual(workflow_environment_problems(with_annotation), [])
|
||||
|
||||
|
||||
class NightlyTrustAnchors(unittest.TestCase):
|
||||
@@ -846,6 +956,11 @@ def workflow_keys(source):
|
||||
return [(number, key) for number, key, _, _ in entries], refused
|
||||
|
||||
|
||||
def workflow_environment_problems(source):
|
||||
keys, refused = workflow_keys(source)
|
||||
return refused + [f"line {line}: direct environment key" for line, key in keys if key.casefold() == "environment"]
|
||||
|
||||
|
||||
SHARED_CALLEE = re.compile(r"storytold/craft-common-actions/\.github/workflows/([\w.-]+\.ya?ml)@(\S+)", re.IGNORECASE)
|
||||
INSPECTED_KEYS = {"environment", "uses"}
|
||||
|
||||
|
||||
Reference in new issue
Block a user