hex/.github/workflows/site-deploy.yml
Dax Raad ea00b65602 fix(site): deploy the site from a secretless build through a locked script
Security finding #528: Site ran site/ code (bun install, build.ts, vite)
in the release environment with a Cloudflare token that can write every
Worker. Site deploy now builds without an environment or secret, uploads
the Build Output with its SHA256SUMS digest, and deploys it from a job
that checks out only .github/release/, verifies the digest, and runs
deploy-site.sh: it refuses any Worker, route, or binding other than the
mode's site Worker and deploys with the cf CLI locked in
.github/release/cf/. Legacy appcast checks out only .github/release/ and
the appcast, and r2-put.sh moves under the boundary.

The deploy token is now hex-site-deploy (Scripts + anoma.ly Routes, no
R2) and the appcast key hex-r2-production-files (one bucket).
2026-10-27 21:18:42 -04:00

111 lines
3.8 KiB
YAML

name: Site deploy
# Builds site/ for one environment and deploys its Worker (the site at /hex and
# the files bucket at /hex/files): dev -> https://dev.anoma.ly/hex,
# production -> https://anoma.ly/hex. Split like Release (docs/releasing.md):
#
# - build runs repository code (bun install, site/scripts/build.ts) with no
# environment and no secrets, and uploads the Worker's Build Output with a
# SHA256SUMS whose digest it reports.
# - deploy runs in the release environment, which holds the hex-site-deploy
# token. It checks out only .github/release/, verifies the artifact against
# that digest, and runs only .github/release/deploy-site.sh, which pins the
# Worker, routes, and bindings and deploys with the cf CLI locked in
# .github/release/cf/.
# - verify checks the live site and every download link without secrets.
on:
workflow_call:
inputs:
mode:
type: string
required: true
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-24.04
outputs:
digest: ${{ steps.upload.outputs.digest }}
defaults:
run:
working-directory: site
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
- run: bun install --frozen-lockfile
- name: Build
env:
MODE: ${{ inputs.mode }}
run: |
case "$MODE" in dev|production) ;; *) exit 1 ;; esac
bun scripts/build.ts --mode "$MODE"
- id: upload
uses: ./.github/release/upload
with:
name: site-${{ inputs.mode }}
path: site/.cloudflare/output
retention-days: 7
deploy:
needs: build
runs-on: ubuntu-24.04
environment: release
concurrency:
group: site-deploy-${{ inputs.mode }}
cancel-in-progress: false
steps:
- name: Check out the release scripts
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
sparse-checkout: /.github/release/
sparse-checkout-cone-mode: false
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
- name: Install the pinned cf CLI
working-directory: .github/release/cf
run: npm ci --ignore-scripts --no-audit --no-fund
- name: Download
uses: ./.github/release/download
with:
pattern: site-${{ inputs.mode }}
digests: site-${{ inputs.mode }}=${{ needs.build.outputs.digest }}
- name: Deploy
env:
MODE: ${{ inputs.mode }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
run: bash .github/release/deploy-site.sh "$MODE" "$RUNNER_TEMP/in/site-$MODE"
verify:
needs: deploy
runs-on: ubuntu-24.04
defaults:
run:
working-directory: site
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
- run: bun install --frozen-lockfile
- name: Check the live site and every download link
env:
MODE: ${{ inputs.mode }}
run: |
host=$([ "$MODE" = dev ] && echo dev.anoma.ly || echo anoma.ly)
for attempt in 1 2 3 4 5 6; do
status=$(curl --silent --output /dev/null --write-out '%{http_code}' "https://$host/hex/")
[ "$status" = 200 ] && break
sleep 10
done
test "$status" = 200
bun run check:downloads