Files
autocraft/deploy/post-receive
T
aiongg f5bdb64c5e Runner hardening: per-repository installation tokens, a github.com-only credential helper, an allow-listed jev environment, pinned git attribute source and explicit repositories, absolute deny rules, a wider output scrub, and a deploy of the pushed commit
- Installation tokens for a write are minted for the write's repository (a transfer's also for its target); reads across repos and pushes to a contributor's fork keep the installation-wide token. Reading the app's keys checks the secrets file's mode like every other reader.
- The app's git credential helper is set for https://github.com only, after every configured helper is dropped.
- jev children get only the search path, home, locale, temp, cache, TLS and proxy variables and Jev's own.
- Git on the cached clones names the repository with GIT_DIR, runs with safe.bareRepository=explicit and reads attributes from the empty tree.
- The sandbox denies /proc and the credential directory in the absolute (//path) form as well.
- The scrub hides hex keys that are not digests, URL user:password, three-part dotted tokens and credentials inside hex or base64.
- The dashboard unit sees the settings file, releases, the bare repo and .local read-only.
- post-receive resolves the pushed commit once and the hook deploys that commit; the image build runs pnpm installs without install scripts.
2026-11-14 23:23:21 +00:00

36 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# Bootstrap hook for the bare repo of a production install. Install it once as
# <bare repo>/hooks/post-receive (mode 0755). It never needs to change: the real
# deploy is deploy/hook.sh in the pushed commit, so a change to the deploy rides
# the same push as the code it deploys.
#
# Runs as the app user with cwd = the bare repo and GIT_DIR pointing at it.
# AUTOCRAFT_BRANCH (default main) is the branch that deploys.
set -euo pipefail
branch="${AUTOCRAFT_BRANCH:-main}"
sha=""
while read -r _old new ref; do
if [ "$ref" = "refs/heads/$branch" ]; then sha="$new"; fi
done
if [ -z "$sha" ]; then
echo "-- no $branch update; nothing to deploy --"
exit 0
fi
# The pushed commit, resolved once: the hook and the release both come from it, whatever the branch does meanwhile.
if ! printf '%s\n' "$sha" | grep -Eqx '[0-9a-f]{40}|[0-9a-f]{64}' || ! git cat-file -e "$sha^{commit}" 2>/dev/null; then
echo "!! $branch was deleted or does not name a commit; nothing was deployed" >&2
exit 1
fi
if ! git cat-file -e "$sha:deploy/hook.sh" 2>/dev/null; then
echo "!! the pushed commit has no deploy/hook.sh; nothing was deployed" >&2
exit 1
fi
# Run the hook from a copy: the checkout it updates may replace deploy/hook.sh mid-run.
hook="$(mktemp "$(cd "$GIT_DIR/.." && pwd)/.post-receive-hook.XXXXXX")"
trap 'rm -f "$hook"' EXIT
git cat-file blob "$sha:deploy/hook.sh" >"$hook"
AUTOCRAFT_BRANCH="$branch" AUTOCRAFT_DEPLOY_SHA="$sha" bash "$hook"