maos: publish OTA to Cloudflare R2 instead of GitHub Releases
- Commit
f87045ee0710bb46836014be9d81b691658d8ea0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-08-09 14:48 UTC (3 months ago)
- Parents
d353997
Diff
README.md
diff --git a/README.md b/README.mdindex 4e7fdfa..259ff18 100644--- a/README.md+++ b/README.md@@ -88,8 +88,10 @@ local_manifest.xml # adds this repo to the GrapheneOS tree ## OTA MAOS uses the standard A/B OTA flow (`update_engine`) with updates served from-**`https://ota.ma.vayunmathur.com`**, hosted by `location_share_server` (which proxies the-signed OTA zips + channel metadata from a public GitHub Release — the same pattern as the-F-Droid repo). Build/publish scripts are in [`ota/`](ota/README.md); pointing the Updater-at the server is covered in [`updater/`](updater/README.md). Full design rationale is in-`GRAPHENEOS_FORK_PLAN.md` (Modern-Apps repo).+**`https://ota.ma.vayunmathur.com`**, a **Cloudflare R2 bucket** exposed via a custom+domain. The build host uploads signed OTA zips + channel metadata straight to R2+(`ota/publish-ota.sh`), and devices download directly from R2 — no GitHub Release and no+server proxy, since the payloads are multi-GB. Build/publish scripts are in+[`ota/`](ota/README.md); pointing the Updater at the server is covered in+[`updater/`](updater/README.md). Full design rationale is in `GRAPHENEOS_FORK_PLAN.md`+(Modern-Apps repo).
docs/BUILD_RUNBOOK.md
diff --git a/docs/BUILD_RUNBOOK.md b/docs/BUILD_RUNBOOK.mdindex e008a63..b00add3 100644--- a/docs/BUILD_RUNBOOK.md+++ b/docs/BUILD_RUNBOOK.md@@ -109,17 +109,28 @@ vendor/modern-apps/ota/build-ota.sh \ -t signed-$DEVICE-$BUILD.zip \ [-p signed-$DEVICE-$OLD_BUILD.zip -o "$OLD_BUILD"] -# Publish to the PUBLIC OTA repo (server proxies its latest release):-vendor/modern-apps/ota/publish-ota.sh -r vayun-mathur/MAOS-releases -t "$BUILD"+# Upload the zips + channel metadata to Cloudflare R2 (served at ota.ma.vayunmathur.com):+export R2_ACCESS_KEY_ID=... R2_SECRET_ACCESS_KEY=... R2_ACCOUNT_ID=...+vendor/modern-apps/ota/publish-ota.sh -b maos-ota ``` -Make sure the server's `MAOS_OTA_GH` matches the repo you publish to.+`publish-ota.sh` uploads the immutable zips first and the `$DEVICE-$CHANNEL` metadata+pointer last. Requires the `aws` CLI and the R2 env vars (see `ota/README.md`). -## 10. Wire the OTA server+## 10. OTA hosting (Cloudflare R2) -On the box running `location_share_server`, point DNS `ota.ma.vayunmathur.com` at it and-ensure its TLS cert covers that host. The server already routes that host to the OTA-proxy (`handlers/ota.rs`). No code change needed beyond deploying the updated binary.+`ota.ma.vayunmathur.com` is an **R2 bucket served via a Cloudflare custom domain** —+devices download directly from R2. There is no server component for OTA (R2 handles the+multi-GB payloads that GitHub Releases / the server's disk cannot). One-time setup:++1. Create the R2 bucket (e.g. `maos-ota`) and an API token with Object Read & Write.+2. Attach the custom domain `ota.ma.vayunmathur.com` (R2 → Settings → Custom Domains);+ Cloudflare provisions TLS.+3. Ensure any Cache Rule does **not** cache the `*-<channel>` metadata objects (the+ uploader already sets `Cache-Control: no-store` on them).++> The `handlers/ota.rs` proxy in `location_share_server` is now unused for this design+> (DNS points at R2, not the server) and can be removed; it is harmless dead code if left. ## 11. Test before trusting it
ota/README.md
diff --git a/ota/README.md b/ota/README.mdindex 9e97d2b..82cb11b 100644--- a/ota/README.md+++ b/ota/README.md@@ -8,11 +8,11 @@ How over-the-air updates flow, and the scripts that produce them. signed target-files ──build-ota.sh──▶ full + incremental OTA zips + channel metadata │ │ │ ▼- │ publish-ota.sh ──▶ PUBLIC GitHub Release (latest)+ │ publish-ota.sh ──▶ Cloudflare R2 bucket │ │ ▼ ▼- (kept for next ota.ma.vayunmathur.com proxies- incremental) /latest/download/<file> (location_share_server)+ (kept for next ota.ma.vayunmathur.com (R2 custom domain,+ incremental) serves objects directly) │ ▼ Updater on device@@ -21,13 +21,41 @@ signed target-files ──build-ota.sh──▶ full + incremental OTA zips + ch - **`build-ota.sh`** turns a *signed* target-files zip into `DEVICE-ota_update-BUILD.zip` (full), optionally `DEVICE-incremental-OLD-NEW.zip`, and a `DEVICE-CHANNEL` metadata file. Signed with your `releasekey`.-- **`publish-ota.sh`** uploads those to a **public** GitHub Release marked *latest*.-- **`location_share_server`** (`handlers/ota.rs`) serves `https://ota.ma.vayunmathur.com/<file>`- by streaming from `releases/latest/download/<file>` of that repo. Set `MAOS_OTA_GH` on- the server to the repo you publish to (defaults to `vayun-mathur/MAOS`).+- **`publish-ota.sh`** uploads those to a **Cloudflare R2** bucket (S3-compatible, via the+ `aws` CLI). Zips go up first; the channel-metadata pointer goes up last.+- **`ota.ma.vayunmathur.com`** is that R2 bucket exposed via a Cloudflare custom domain, so+ an object keyed `<file>` is served at `https://ota.ma.vayunmathur.com/<file>`. Devices+ download straight from R2 — **no GitHub Release and no `location_share_server` proxy are+ involved** (R2 handles the multi-GB payloads that GitHub Releases / the server's disk+ can't). - The **Updater** app polls `https://ota.ma.vayunmathur.com/<device>-<channel>` then downloads the referenced zip (see `../updater/README.md`). +## Credentials (never commit)++`publish-ota.sh` reads R2 credentials from the environment:++| Var | Meaning |+| --- | --- |+| `R2_ACCESS_KEY_ID` | R2 API token access key id |+| `R2_SECRET_ACCESS_KEY` | R2 API token secret |+| `R2_ACCOUNT_ID` | Cloudflare account id (builds the endpoint), **or** |+| `R2_ENDPOINT` | full endpoint URL (overrides `R2_ACCOUNT_ID`) |+| `R2_BUCKET` | bucket name (default `maos-ota`; or pass `-b`) |++The endpoint defaults to `https://<R2_ACCOUNT_ID>.r2.cloudflarestorage.com`. Create the+API token in the Cloudflare dashboard (R2 → Manage API Tokens) with **Object Read & Write**+on the target bucket.++## Cloudflare setup (one-time)++1. Create the R2 bucket (e.g. `maos-ota`).+2. Attach the custom domain `ota.ma.vayunmathur.com` to it (R2 → Settings → Custom Domains).+ Cloudflare provisions TLS automatically.+3. The object `Cache-Control` headers set by `publish-ota.sh` (immutable zips, `no-store`+ metadata) are honored by Cloudflare's cache. If you add a Cache Rule, make sure it does+ **not** cache the `*-<channel>` metadata objects, or devices will see stale builds.+ ## Keep every release's signed target-files Incrementals diff the previous signed target-files against the new one. Archive each@@ -37,13 +65,7 @@ ship a full OTA, just not a delta. ## Metadata format `build-ota.sh` writes `BUILD TIMESTAMP CHANNEL` (one line). This must match whatever your-Updater version parses — confirm against the pinned source and adjust both sides-together if needed.--## Payloads are proxied, not stored--Nothing is stored on the OTA host; it streams from GitHub Releases (mirrors how the-F-Droid repo proxies APKs). The release repo must be **public** so the server can fetch-without auth (or run the server with a token and keep it private).+Updater version parses — confirm against the pinned source and adjust both sides together+if needed. See `../docs/BUILD_RUNBOOK.md` for the full build → sign → OTA → publish sequence.
ota/publish-ota.sh
diff --git a/ota/publish-ota.sh b/ota/publish-ota.shindex cb8471c..21d24a0 100755--- a/ota/publish-ota.sh+++ b/ota/publish-ota.sh@@ -1,57 +1,100 @@ #!/usr/bin/env bash #-# publish-ota.sh — upload OTA artifacts to a PUBLIC GitHub Release so the OTA server-# (ota.ma.vayunmathur.com) can proxy them from `.../releases/latest/download/<file>`.+# publish-ota.sh — upload OTA artifacts to Cloudflare R2. #-# The server serves whatever is on the LATEST release, so this marks the release latest.-# Devices download from our origin (the server proxies the bytes), never from GitHub-# directly, so a redirect-averse Updater still works.+# `ota.ma.vayunmathur.com` is an R2 bucket served directly via a Cloudflare custom+# domain, so devices download straight from R2 — there is no GitHub Release and no+# server proxy in the loop. An object stored at key `<file>` is served at+# `https://ota.ma.vayunmathur.com/<file>`, which is exactly what the Updater polls. #-# Requires the GitHub CLI (`gh`) authenticated with write access to the OTA repo.+# Upload order matters: the signed zips go up FIRST and the channel-metadata pointer+# goes up LAST, so a device polling mid-publish never sees metadata referencing a zip+# that isn't there yet. #-# Usage:-# ota/publish-ota.sh -r vayun-mathur/MAOS-releases -t 2026080900 -O out/maos-ota+# R2 is S3-compatible, so this uses the standard `aws` CLI pointed at the R2 endpoint.+# Credentials come from the environment (never commit them):+#+# R2_ACCESS_KEY_ID R2 API token access key id+# R2_SECRET_ACCESS_KEY R2 API token secret+# R2_ACCOUNT_ID Cloudflare account id (used to build the endpoint), OR+# R2_ENDPOINT full endpoint URL (overrides R2_ACCOUNT_ID)+# R2_BUCKET bucket name (default: maos-ota, or pass -b)+#+# Requires: awscli v2. # set -euo pipefail -REPO="" ; TAG="" ; OUTDIR="out/maos-ota"+BUCKET="${R2_BUCKET:-maos-ota}"+OUTDIR="out/maos-ota" usage() { cat >&2 <<EOF-usage: publish-ota.sh -r OWNER/REPO -t TAG [-O OUTDIR]- -r OWNER/REPO PUBLIC GitHub repo to hold OTA releases (must match the server's- MAOS_OTA_GH; defaults there to vayun-mathur/MAOS)- -t TAG release tag (e.g. the build number 2026080900)- -O OUTDIR dir containing the artifacts from build-ota.sh (default: out/maos-ota)+usage: publish-ota.sh [-b BUCKET] [-O OUTDIR]+ -b BUCKET R2 bucket name (default: \$R2_BUCKET or maos-ota)+ -O OUTDIR dir containing the artifacts from build-ota.sh (default: out/maos-ota)++Required env: R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, and either R2_ACCOUNT_ID or+R2_ENDPOINT. See the header of this file. EOF exit 2 } -while getopts "r:t:O:h" opt; do+while getopts "b:O:h" opt; do case "$opt" in- r) REPO="$OPTARG" ;;- t) TAG="$OPTARG" ;;+ b) BUCKET="$OPTARG" ;; O) OUTDIR="$OPTARG" ;; *) usage ;; esac done -[[ -n "$REPO" && -n "$TAG" ]] || usage-command -v gh >/dev/null || { echo "gh (GitHub CLI) not found" >&2; exit 1; }-shopt -s nullglob-FILES=("$OUTDIR"/*.zip "$OUTDIR"/*-stable "$OUTDIR"/*-beta)-[[ ${#FILES[@]} -gt 0 ]] || { echo "no artifacts in $OUTDIR" >&2; exit 1; }--echo ">> publishing ${#FILES[@]} file(s) to $REPO @ $TAG (latest)"-if gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then- gh release upload "$TAG" "${FILES[@]}" --repo "$REPO" --clobber- gh release edit "$TAG" --repo "$REPO" --latest-else- gh release create "$TAG" "${FILES[@]}" \- --repo "$REPO" \- --title "MAOS OTA $TAG" \- --notes "Automated MAOS OTA release." \- --latest+command -v aws >/dev/null || { echo "aws CLI (v2) not found" >&2; exit 1; }+: "${R2_ACCESS_KEY_ID:?set R2_ACCESS_KEY_ID}"+: "${R2_SECRET_ACCESS_KEY:?set R2_SECRET_ACCESS_KEY}"++ENDPOINT="${R2_ENDPOINT:-}"+if [[ -z "$ENDPOINT" ]]; then+ : "${R2_ACCOUNT_ID:?set R2_ACCOUNT_ID or R2_ENDPOINT}"+ ENDPOINT="https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com" fi -echo ">> done. Server will serve these from https://ota.ma.vayunmathur.com/<file>"+# Map R2 creds to the AWS SDK's variables for this process only.+export AWS_ACCESS_KEY_ID="$R2_ACCESS_KEY_ID"+export AWS_SECRET_ACCESS_KEY="$R2_SECRET_ACCESS_KEY"+# R2 ignores region but the SDK requires one; "auto" is the documented value.+export AWS_DEFAULT_REGION="auto"+# aws-cli v2 adds trailing/streaming integrity checksums that break R2 multipart+# uploads (which is every multi-GB OTA). Only send checksums when the API requires+# them, matching Cloudflare's own R2 guidance.+export AWS_REQUEST_CHECKSUM_CALCULATION="when_required"+export AWS_RESPONSE_CHECKSUM_VALIDATION="when_required"++s3() { aws s3 --endpoint-url "$ENDPOINT" "$@"; }++put() {+ # put <local> <key> <content-type> <cache-control>+ local src="$1" key="$2" ctype="$3" cache="$4"+ echo ">> $key ($(du -h "$src" | cut -f1), $ctype)"+ s3 cp "$src" "s3://$BUCKET/$key" \+ --content-type "$ctype" \+ --cache-control "$cache" \+ --only-show-errors+}++shopt -s nullglob+ZIPS=("$OUTDIR"/*.zip)+METAS=("$OUTDIR"/*-stable "$OUTDIR"/*-beta "$OUTDIR"/*-alpha)+[[ ${#ZIPS[@]} -gt 0 || ${#METAS[@]} -gt 0 ]] || { echo "no artifacts in $OUTDIR" >&2; exit 1; }++echo ">> R2 endpoint: $ENDPOINT bucket: $BUCKET"++# 1) Immutable payloads first. Named per-build, so they can be cached forever.+for z in "${ZIPS[@]}"; do+ put "$z" "$(basename "$z")" "application/zip" "public, max-age=31536000, immutable"+done++# 2) Mutable channel pointer(s) last, uncacheable so a new build is seen promptly.+for m in "${METAS[@]}"; do+ put "$m" "$(basename "$m")" "text/plain; charset=utf-8" "no-store, must-revalidate"+done++echo ">> done. Served at https://ota.ma.vayunmathur.com/<file>"
updater/README.md
diff --git a/updater/README.md b/updater/README.mdindex 61000d4..0e06f5c 100644--- a/updater/README.md+++ b/updater/README.md@@ -1,9 +1,9 @@ # Updater configuration (MAOS) MAOS reuses the GrapheneOS Updater app but points it at our own OTA server,-`https://ota.ma.vayunmathur.com` (served by `location_share_server`, which proxies the-metadata + signed OTA zips from the latest GitHub Release — see that repo's-`handlers/ota.rs`).+`https://ota.ma.vayunmathur.com` — a **Cloudflare R2 bucket** exposed via a custom domain,+which serves the signed OTA zips + channel metadata directly (uploaded by+`ota/publish-ota.sh`; see `../ota/README.md`). ## What the Updater fetches @@ -33,8 +33,9 @@ your Updater version parses (GrapheneOS uses a short space-separated line — fork plan's "fallback: when a real fork is unavoidable"). 2. **Certificate pinning.** GrapheneOS pins its server's certificate. `ota.ma.vayunmathur.com`- uses a normal (Let's Encrypt) certificate, so either remove the pin or repin to your- cert. Check the Updater's `network_security_config` / any `CertificatePinner`:+ uses a Cloudflare-managed certificate (and Cloudflare may rotate it), so either remove the+ pin or pin to the Cloudflare/issuer cert. Check the Updater's `network_security_config` /+ any `CertificatePinner`: ```bash grep -rn "pin-set\|CertificatePinner\|network_security_config" packages/apps/Updater/