Files
loki/scripts/setup-branch-protection.sh
Mao NakamotoandClaude Opus 4.8 cc4c58fcbf chore(devops): prepare blast-radius containment (#1) + CI-gated deploy (#2)
Both prepared, NOT applied. Inert until you act — see
docs/development/devops-prep-apply-guide.md.

#1 — box-runner blast radius:
- scripts/hetzner/harden-box-runner.sh installs a systemd drop-in that makes the
  co-tenant /opt/<app> dirs, /opt/backups, and /home/ubuntu/.ssh kernel-
  inaccessible to the runner AND every agent PTY it spawns. Keeps User=ubuntu
  (the claude CLI lives in /home/ubuntu, so no user migration needed). Safe: the
  runner only touches its own dir + fresh clones under /home/ubuntu/dev, never a
  co-tenant /opt (verified in box-workspace.ts). --dry-run / --revert supported.
- install-box-runner.sh bakes the same InaccessiblePaths into the unit for fresh
  installs.

#2 — CI-gated deploy:
- .github/workflows/deploy.yml runs ONLY after CI succeeds on main, builds
  (schema-only Postgres service), and ships via deploy-hetzner.sh --no-build so
  the flock/rollback/verify logic carries over. A red CI → no deploy. Needs a
  HETZNER_SSH_KEY secret; the local push-deploy hook must be disabled to avoid
  double deploys (documented).
- scripts/setup-branch-protection.sh (opt-in, separate) requires the CI check
  before merge — rejects direct pushes to main, so only for a PR-based flow.

bash -n + deploy.yml structural checks clean; drop-in dry-run verified.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-07 20:49:36 +02:00

44 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# OPTIONAL, SEPARATE from the deploy gate (DevOps remediation #2, extra layer).
#
# The deploy.yml workflow_run already guarantees "red CI can't ship" WITHOUT
# this. This goes further: it stops a red commit from even landing on `main` by
# requiring the CI `check` job to pass before merge.
#
# ⚠️ BEHAVIOR CHANGE: with required status checks, GitHub REJECTS direct pushes
# to main (the checks can't have passed at push time). You must then land
# changes via PR. If you rely on `git push origin main`, do NOT run this —
# the deploy.yml gate alone is enough. Run this only if you want PR-based main.
#
# Requires: gh authenticated with admin on the repo.
# Usage: bash scripts/setup-branch-protection.sh # enable
# bash scripts/setup-branch-protection.sh --remove # disable
set -euo pipefail
REPO="$(gh repo view --json nameWithOwner -q .nameWithOwner)"
echo "repo: $REPO"
if [ "${1:-}" = "--remove" ]; then
gh api -X DELETE "repos/$REPO/branches/main/protection"
echo "✓ branch protection removed from main"
exit 0
fi
# Require the CI job named "check" (see ci.yml). strict=true → branch must be up
# to date with main before merge. No required reviews (solo repo); flip
# required_pull_request_reviews if you want them.
gh api -X PUT "repos/$REPO/branches/main/protection" \
--input - <<'JSON'
{
"required_status_checks": { "strict": true, "contexts": ["check"] },
"enforce_admins": false,
"required_pull_request_reviews": null,
"restrictions": null
}
JSON
echo "✓ main now requires the CI 'check' job to pass before merge."
echo " Direct pushes to main will be rejected — use PRs from here on."
echo " Undo: $0 --remove"