Skip to content

Commit f15e07f

Browse files
authored
Release: create verified owner-only 44-file VPS source ZIP
* release: package 27 app discovery and 17 policy files into verified offline VPS ZIP * test: verify exact 44-file offline bundle hashes, source truth and unsafe-path rejection * release: reject ZIP output anywhere under public source tree * test: reject parent directory traversal in archive inputs * test: distinguish safe packaging executable from owner-only SSH instructions * ci: produce owner-downloadable verified VPS source bundle without posting or deploying
1 parent 9202e43 commit f15e07f

3 files changed

Lines changed: 364 additions & 0 deletions

File tree

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Produces a portable verified release ZIP for the site owner when the
2+
# labeled self-hosted appsite-deploy runner is unavailable.
3+
# It NEVER writes to a VPS, changes DNS, or starts publication.
4+
name: Prepare app site owner-only VPS release ZIP
5+
6+
on:
7+
pull_request:
8+
branches: [main]
9+
paths:
10+
- 'index.html'
11+
- 'apps.html'
12+
- 'robots.txt'
13+
- 'sitemap.xml'
14+
- 'press/**'
15+
- 'guides/**'
16+
- 'support/**'
17+
- 'privacy-policy/**'
18+
- 'scripts/preflight_app_discovery.py'
19+
- 'scripts/publish_app_discovery.sh'
20+
- 'scripts/publish_stale_policy_pages.sh'
21+
- 'scripts/test_preflight_app_discovery.py'
22+
- 'scripts/test_press_kit.py'
23+
- 'scripts/test_publish_app_discovery_staging.py'
24+
- 'scripts/build_site_release_bundle.py'
25+
- 'scripts/test_site_release_bundle.py'
26+
- '.github/workflows/build-appsite-release-bundle.yml'
27+
push:
28+
branches: [main]
29+
paths:
30+
- 'index.html'
31+
- 'apps.html'
32+
- 'robots.txt'
33+
- 'sitemap.xml'
34+
- 'press/**'
35+
- 'guides/**'
36+
- 'support/**'
37+
- 'privacy-policy/**'
38+
- 'scripts/preflight_app_discovery.py'
39+
- 'scripts/publish_app_discovery.sh'
40+
- 'scripts/publish_stale_policy_pages.sh'
41+
- 'scripts/test_preflight_app_discovery.py'
42+
- 'scripts/test_press_kit.py'
43+
- 'scripts/test_publish_app_discovery_staging.py'
44+
- 'scripts/build_site_release_bundle.py'
45+
- 'scripts/test_site_release_bundle.py'
46+
- '.github/workflows/build-appsite-release-bundle.yml'
47+
workflow_dispatch:
48+
49+
permissions:
50+
contents: read
51+
52+
jobs:
53+
bundle:
54+
runs-on: ubuntu-latest
55+
timeout-minutes: 12
56+
steps:
57+
- name: Check out exact release source
58+
uses: actions/checkout@v4
59+
with:
60+
persist-credentials: false
61+
- name: Set up Python
62+
uses: actions/setup-python@v5
63+
with:
64+
python-version: '3.12'
65+
- name: Verify publisher source and five localized press pages
66+
run: |
67+
python3 scripts/preflight_app_discovery.py
68+
python3 -m unittest \
69+
scripts.test_preflight_app_discovery \
70+
scripts.test_press_kit \
71+
scripts.test_publish_app_discovery_staging \
72+
scripts.test_site_release_bundle -v
73+
- name: Create source-only ZIP (no network or VPS access)
74+
shell: bash
75+
run: |
76+
set -euo pipefail
77+
mkdir -p "$RUNNER_TEMP/appsite"
78+
python3 scripts/build_site_release_bundle.py \
79+
--output "$RUNNER_TEMP/appsite/appsite-vps-source-${GITHUB_SHA:0:12}.zip"
80+
python3 - <<'PY'
81+
from pathlib import Path
82+
from zipfile import ZipFile
83+
import os
84+
folder = Path(os.environ['RUNNER_TEMP']) / 'appsite'
85+
archives = list(folder.glob('appsite-vps-source-*.zip'))
86+
assert len(archives) == 1, 'one ZIP per verified source checkout'
87+
with ZipFile(archives[0]) as z:
88+
names = z.namelist()
89+
assert len(names) == 46, f'44 site documents + hash manifest + instructions; got {len(names)}'
90+
assert z.testzip() is None
91+
assert all(n.startswith('site/') or n in ('SHA256SUMS.txt', 'DEPLOY_README.txt') for n in names)
92+
PY
93+
- name: Save reviewed release ZIP for the owner (main only)
94+
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: appsite-vps-source-${{ github.sha }}
98+
path: ${{ runner.temp }}/appsite/*.zip
99+
if-no-files-found: error
100+
retention-days: 14
101+
- name: Clarify publication status
102+
if: always()
103+
shell: bash
104+
run: |
105+
{
106+
echo '## Source bundle — this is NOT a production deployment'
107+
echo ''
108+
echo '- Existing VPS release requires explicit owner approval on the separate **publish to VPS** workflow.'
109+
echo '- Bundle contains only existing allowlisted public app pages and approved policy HTML.'
110+
echo '- Public URLs remain unverified until the owner applies and reruns the live smoke test.'
111+
echo '- No SSH, domain transfer, indexing submission, social post, or traffic event is performed.'
112+
} >> "$GITHUB_STEP_SUMMARY"
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!/usr/bin/env python3
2+
"""Build a portable, read-only appdevelopsk.com VPS release bundle.
3+
4+
This script packages ONLY the exact files allowed by the existing owner-only
5+
app discovery and privacy-policy publishing scripts. It never touches a VPS,
6+
changes a GitHub branch, sends events, or requires SSH/network access.
7+
8+
Usage:
9+
python3 scripts/build_site_release_bundle.py --output /tmp/appsite-release.zip
10+
"""
11+
import argparse
12+
import hashlib
13+
import json
14+
import re
15+
import shlex
16+
import sys
17+
import zipfile
18+
from pathlib import Path, PurePosixPath
19+
20+
ROOT = Path(__file__).resolve().parents[1]
21+
APP_PUBLISHER = "scripts/publish_app_discovery.sh"
22+
POLICY_PUBLISHER = "scripts/publish_stale_policy_pages.sh"
23+
PRESS = {
24+
"press/index.html",
25+
"press/es/index.html",
26+
"press/pt-br/index.html",
27+
"press/ja/index.html",
28+
"press/id/index.html",
29+
}
30+
MAX_FILE_BYTES = 5_000_000
31+
MAX_TOTAL_BYTES = 25_000_000
32+
README = """APP SITE — OWNER-CONTROLLED RELEASE BUNDLE
33+
34+
This ZIP is source-only. Creating or downloading it does NOT publish a site.
35+
The root-level site/ directory preserves paths relative to the VPS web root.
36+
SHA256SUMS.txt verifies the exact bytes included; it is not a deployed SHA.
37+
38+
PREFERRED RELEASE:
39+
GitHub Actions -> publish to VPS -> main -> mode=dry-run; review.
40+
The owner may then authorize a separate mode=apply on the self-hosted VPS
41+
runner. Do NOT use this bundle to bypass a failed source preflight.
42+
43+
ALTERNATIVE WHEN THE SELF-HOSTED RUNNER IS UNAVAILABLE:
44+
1. Extract this ZIP into a private temporary directory on a trusted computer.
45+
2. From that extracted directory, run:
46+
sha256sum -c SHA256SUMS.txt
47+
3. Owner verifies the SSH host/user, web-root path and exact file list.
48+
4. Owner uploads only its site/ contents with their relative directories:
49+
rsync -rlcv --itemize-changes -- site/ USER@VPS:/var/www/html/
50+
Do not add --delete. Do not blindly copy files to an unverified host.
51+
5. Run source post-release read-only probes:
52+
bash scripts/check_app_discovery_live.sh
53+
bash scripts/publish_stale_policy_pages.sh --check-live
54+
6. Confirm all five /press/ locale routes return HTTP 200 on
55+
https://appdevelopsk.com and the expected canonical/hreflang, then
56+
check the public app catalog and support landing metadata.
57+
58+
This includes 27 app-discovery documents and 17 approved policy documents
59+
from current source. It is NOT a complete VPS backup, nginx configuration,
60+
database migration, browser test, app-store release, or SEO indexing proof.
61+
"""
62+
63+
64+
def shell_array(text, name):
65+
if name == "files":
66+
pattern = r"(?m)^files=\(([^)\n]*)\)\s*$"
67+
elif name == "slugs":
68+
pattern = r"(?ms)^slugs=\(\s*(.*?)^\)\s*$"
69+
else:
70+
raise ValueError("unsupported manifest variable")
71+
found = re.findall(pattern, text)
72+
if len(found) != 1:
73+
raise ValueError("expected exactly one explicit " + name + "=(...) manifest")
74+
parts = shlex.split(found[0], comments=True)
75+
if not parts or len(parts) != len(set(parts)):
76+
raise ValueError(name + " manifest is empty or has duplicate entries")
77+
return parts
78+
79+
80+
def release_manifest(root=ROOT):
81+
scripts = root / "scripts"
82+
apps = shell_array((scripts / "publish_app_discovery.sh").read_text(encoding="utf-8"), "files")
83+
policies = shell_array((scripts / "publish_stale_policy_pages.sh").read_text(encoding="utf-8"), "slugs")
84+
if len(apps) != 27 or len(policies) != 17:
85+
raise ValueError("publisher manifest count changed; review before bundling")
86+
if not PRESS.issubset(set(apps)):
87+
raise ValueError("one or more of the five press routes are not in publisher manifest")
88+
if not {"index.html", "apps.html", "sitemap.xml", "robots.txt",
89+
"support/brain-burst/index.html", "support/debate-me/index.html"}.issubset(apps):
90+
raise ValueError("critical app discovery/SEO pages missing from publisher manifest")
91+
if any(not re.fullmatch(r"[a-z0-9-]+", slug) for slug in policies):
92+
raise ValueError("unsafe privacy-policy slug")
93+
files = apps + ["privacy-policy/" + slug + "/index.html" for slug in policies]
94+
if len(files) != len(set(files)):
95+
raise ValueError("publisher allowlists overlap")
96+
total = 0
97+
for filename in files:
98+
path = PurePosixPath(filename)
99+
if (path.is_absolute() or ".." in path.parts or "." in path.parts
100+
or path.as_posix() != filename or "\\" in filename):
101+
raise ValueError("unsafe release path: " + filename)
102+
actual = root / filename
103+
if (not actual.is_file() or actual.is_symlink()
104+
or not actual.resolve().is_relative_to(root.resolve())):
105+
raise ValueError("missing or unsafe source file: " + filename)
106+
size = actual.stat().st_size
107+
if size <= 0 or size > MAX_FILE_BYTES:
108+
raise ValueError("missing, empty or oversized source file: " + filename)
109+
total += size
110+
if total > MAX_TOTAL_BYTES:
111+
raise ValueError("release is too large for the reviewed source-only bundle")
112+
return files
113+
114+
115+
def zip_bytes(root, files, out):
116+
out.parent.mkdir(parents=True, exist_ok=True)
117+
checksum_rows = []
118+
with zipfile.ZipFile(out, "w", compression=zipfile.ZIP_DEFLATED,
119+
compresslevel=6) as archive:
120+
for filename in sorted(files):
121+
content = (root / filename).read_bytes()
122+
source = "site/" + filename
123+
archive.writestr(source, content)
124+
checksum_rows.append(hashlib.sha256(content).hexdigest() + " " + source)
125+
archive.writestr("SHA256SUMS.txt", "\n".join(checksum_rows) + "\n")
126+
archive.writestr("DEPLOY_README.txt", README)
127+
return hashlib.sha256(out.read_bytes()).hexdigest()
128+
129+
130+
def main():
131+
parser = argparse.ArgumentParser(description=__doc__)
132+
parser.add_argument("--output", required=True, type=Path,
133+
help="Local output .zip path; never a production web root")
134+
args = parser.parse_args()
135+
if args.output.suffix.lower() != ".zip":
136+
parser.error("--output must be a .zip filename")
137+
output = args.output.resolve()
138+
if output.is_relative_to(ROOT):
139+
parser.error("do not create ZIP anywhere inside the public website source tree")
140+
try:
141+
files = release_manifest(ROOT)
142+
digest = zip_bytes(ROOT, files, output)
143+
except (OSError, ValueError, zipfile.BadZipFile) as exc:
144+
print(type(exc).__name__ + ": " + str(exc), file=sys.stderr)
145+
return 1
146+
print(json.dumps({
147+
"status": "source_bundle_created_not_deployed",
148+
"output": str(output),
149+
"sha256": digest,
150+
"appDiscoveryFiles": 27,
151+
"policyFiles": 17,
152+
"totalFiles": len(files),
153+
"pressRoutes": sorted(PRESS),
154+
"publishesToVps": False,
155+
"urlIndexingRequested": False,
156+
}, indent=2))
157+
return 0
158+
159+
160+
if __name__ == "__main__":
161+
sys.exit(main())
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""Offline tests for owner-controlled, no-credentials VPS release ZIP."""
2+
import hashlib
3+
import re
4+
import shutil
5+
import tempfile
6+
import unittest
7+
import zipfile
8+
from pathlib import Path
9+
10+
from scripts import build_site_release_bundle as bundle
11+
12+
13+
class AppsiteReleaseBundleTests(unittest.TestCase):
14+
def test_exact_publish_manifest_has_five_press_and_seventeen_policies(self):
15+
files = bundle.release_manifest()
16+
self.assertEqual(len(files), 44)
17+
self.assertEqual(len(files), len(set(files)))
18+
self.assertTrue(bundle.PRESS.issubset(files))
19+
self.assertEqual(sum(x.startswith("privacy-policy/") for x in files), 17)
20+
self.assertNotIn(".env", "\n".join(files))
21+
self.assertFalse(any(".." in Path(x).parts or "." in Path(x).parts for x in files))
22+
23+
def test_zip_contains_exact_site_payload_with_matching_checksum_file(self):
24+
files = bundle.release_manifest()
25+
with tempfile.TemporaryDirectory() as tmp:
26+
output = Path(tmp) / "appsite.zip"
27+
digest = bundle.zip_bytes(bundle.ROOT, files, output)
28+
self.assertEqual(digest, hashlib.sha256(output.read_bytes()).hexdigest())
29+
with zipfile.ZipFile(output) as z:
30+
expected = {"site/" + f for f in files} | {"SHA256SUMS.txt", "DEPLOY_README.txt"}
31+
self.assertEqual(set(z.namelist()), expected)
32+
self.assertEqual(z.testzip(), None)
33+
hashes = {}
34+
for line in z.read("SHA256SUMS.txt").decode().splitlines():
35+
checksum, name = line.split(" ", 1)
36+
self.assertNotIn(name, hashes)
37+
hashes[name] = checksum
38+
self.assertEqual(set(hashes), {"site/" + f for f in files})
39+
for name, checksum in hashes.items():
40+
with self.subTest(name=name):
41+
self.assertEqual(hashlib.sha256(z.read(name)).hexdigest(), checksum)
42+
self.assertEqual(z.read(name), (bundle.ROOT / name.removeprefix("site/")).read_bytes())
43+
readme = z.read("DEPLOY_README.txt").decode()
44+
self.assertIn("source-only", readme)
45+
self.assertIn("mode=dry-run", readme)
46+
self.assertIn("mode=apply", readme)
47+
self.assertIn("Do not add --delete", readme)
48+
49+
def test_publisher_slug_path_traversal_fails_closed(self):
50+
with tempfile.TemporaryDirectory() as tmp:
51+
root = Path(tmp)
52+
(root / "scripts").mkdir()
53+
for filename in (bundle.APP_PUBLISHER, bundle.POLICY_PUBLISHER):
54+
shutil.copy2(bundle.ROOT / filename, root / filename)
55+
old = (root / bundle.POLICY_PUBLISHER).read_text()
56+
self.assertIn("battery-charging-map", old)
57+
(root / bundle.POLICY_PUBLISHER).write_text(
58+
old.replace("battery-charging-map", "../outside", 1))
59+
with self.assertRaises(ValueError):
60+
bundle.release_manifest(root)
61+
62+
def test_any_missing_press_route_fails_before_archive(self):
63+
with tempfile.TemporaryDirectory() as tmp:
64+
root = Path(tmp)
65+
(root / "scripts").mkdir()
66+
for filename in (bundle.APP_PUBLISHER, bundle.POLICY_PUBLISHER):
67+
shutil.copy2(bundle.ROOT / filename, root / filename)
68+
script = root / bundle.APP_PUBLISHER
69+
text = script.read_text()
70+
self.assertIn("press/id/index.html", text)
71+
script.write_text(text.replace("press/id/index.html",
72+
"press/nonexistent/index.html", 1))
73+
with self.assertRaises(ValueError):
74+
bundle.release_manifest(root)
75+
76+
def test_archive_builder_never_needs_vps_or_credentials(self):
77+
source = (bundle.ROOT / "scripts/build_site_release_bundle.py").read_text()
78+
# Deployment instructions (README) legitimately mention SSH and rsync;
79+
# only the executable packaging code must be free of network commands.
80+
executable = source.split("def shell_array", 1)[1]
81+
self.assertNotIn("subprocess", executable)
82+
self.assertNotIn("urllib.request", executable)
83+
self.assertNotIn("ssh ", executable)
84+
self.assertNotIn("rsync -", executable)
85+
self.assertNotIn("os.system", executable)
86+
self.assertNotIn("eval(", executable)
87+
self.assertIn("publishesToVps", executable)
88+
89+
90+
if __name__ == "__main__":
91+
unittest.main()

0 commit comments

Comments
 (0)