From 6a6eb5da0cbdfb4073f10d975874bae3c1b73368 Mon Sep 17 00:00:00 2001 From: Hive76 ops box Date: Thu, 22 Oct 2026 02:57:12 +0000 Subject: [PATCH 1/4] chore: Hive76 secret-scanning template (pre-commit gitleaks + Action) --- .github/workflows/gitleaks.yml | 19 +++++++++++++++++++ .gitignore | 16 ++++++++++++++++ git-hooks/pre-commit | 19 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 .github/workflows/gitleaks.yml create mode 100755 git-hooks/pre-commit diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml new file mode 100644 index 0000000..bc91713 --- /dev/null +++ b/.github/workflows/gitleaks.yml @@ -0,0 +1,19 @@ +name: gitleaks + +on: + push: + pull_request: + +jobs: + scan: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install gitleaks + run: | + curl -sSfL https://github.com/gitleaks/gitleaks/releases/download/v8.28.0/gitleaks_8.28.0_linux_x64.tar.gz | tar -xz gitleaks + sudo mv gitleaks /usr/local/bin/ + - name: Scan full history + run: gitleaks detect --source . --config .gitleaks.toml --no-banner --redact --log-opts=--all diff --git a/.gitignore b/.gitignore index ad07a51..3eae587 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,19 @@ venv/ # Local knowledge base copy knowledge_base.txt sync_manifest.json + +# Hive76 template (ops/repo-template/.gitignore) +*.env +.env* +!*.env.example +secrets/ +*.key +*.pem +id_* +!id_*.pub +*.sql +*.sql.gz +*.dump +*.csv +.superpowers/ +.pytest_cache/ diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit new file mode 100755 index 0000000..d6c9a7d --- /dev/null +++ b/git-hooks/pre-commit @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Block commits that contain secrets. Installed with: git config core.hooksPath git-hooks +set -euo pipefail +# Hooks and runuser get a minimal PATH; the pinned gitleaks lives in /usr/local/bin. +export PATH="$PATH:/usr/local/bin:/opt/homebrew/bin" + +if ! command -v gitleaks >/dev/null 2>&1; then + echo "pre-commit: gitleaks is not installed; refusing to commit unscanned changes." >&2 + exit 1 +fi + +root=$(git rev-parse --show-toplevel) +cfg=() +[ -f "$root/.gitleaks.toml" ] && cfg=(--config "$root/.gitleaks.toml") + +if ! gitleaks protect --staged "${cfg[@]}" --no-banner --redact; then + echo "pre-commit: possible secret in staged changes. Secrets belong in /etc/hive76/secrets/, never in git." >&2 + exit 1 +fi From b69952fc164bd297139bef6e7ef1960ccf6d60a8 Mon Sep 17 00:00:00 2001 From: Hive76 ops box Date: Thu, 22 Oct 2026 04:13:54 +0000 Subject: [PATCH 2/4] ci: gitleaks workflow token read-only (CodeQL) Co-Authored-By: Claude Opus 5.5 --- .github/workflows/gitleaks.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml index bc91713..dec6e1f 100644 --- a/.github/workflows/gitleaks.yml +++ b/.github/workflows/gitleaks.yml @@ -4,6 +4,9 @@ on: push: pull_request: +permissions: + contents: read + jobs: scan: runs-on: ubuntu-latest From 4840273c618414ea03d394604fd812538d67db14 Mon Sep 17 00:00:00 2001 From: Hive76 ops box Date: Thu, 22 Oct 2026 04:21:40 +0000 Subject: [PATCH 3/4] chore: pre-push hook blocks force-push/delete of main Synced from hive76-space ops/repo-template (see hive76/hive76-space#1). Co-Authored-By: Claude Opus 5.5 --- git-hooks/pre-push | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 git-hooks/pre-push diff --git a/git-hooks/pre-push b/git-hooks/pre-push new file mode 100755 index 0000000..849df03 --- /dev/null +++ b/git-hooks/pre-push @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Refuse to force-push or delete main. GitHub's free org plan can't protect branches in +# private repos, so this hook is the guard. Installed with: git config core.hooksPath git-hooks +set -euo pipefail + +zero=0000000000000000000000000000000000000000 +status=0 +while read -r _local_ref local_sha remote_ref remote_sha; do + [ "$remote_ref" = refs/heads/main ] || continue + if [ "${local_sha//0/}" = "" ]; then + echo "pre-push: refusing to delete main." >&2 + status=1 + elif [ "$remote_sha" != "$zero" ] && ! git merge-base --is-ancestor "$remote_sha" "$local_sha" 2>/dev/null; then + echo "pre-push: refusing to force-push main (it would drop commits already on GitHub)." >&2 + echo "pre-push: run 'git pull' and push again; to undo a pushed commit, use 'git revert'." >&2 + status=1 + fi +done +exit $status From 9d8682152fc3a408a6b979881a665c47b88d4c26 Mon Sep 17 00:00:00 2001 From: Hive76 ops box Date: Thu, 22 Oct 2026 04:24:36 +0000 Subject: [PATCH 4/4] ci: report checks under the names branch protection requires main's protection requires the checks `test` and `scan-secrets`, but the jobs reported as "Tests" and "Secret Scan", so the required checks never arrived and every PR stayed blocked. Dropping the display names makes the check names equal the job IDs, so a cosmetic rename can't silently block merges again. Also, per GitHub's hardening guidance: the workflow token is limited to contents: read, and aquasecurity/trivy-action is pinned to the v0.36.0 commit instead of @master. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5b8a78..6df9b94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,9 +6,11 @@ on: pull_request: branches: [main] +permissions: + contents: read + jobs: test: - name: Tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -21,14 +23,13 @@ jobs: run: python -m pytest tests/ -v scan-secrets: - name: Secret Scan runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 # full history so gitleaks can scan all commits - name: Trivy secret scan - uses: aquasecurity/trivy-action@master + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: scan-type: fs scanners: secret @@ -41,7 +42,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Trivy CVE scan (warn only) - uses: aquasecurity/trivy-action@master + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: scan-type: fs scanners: vuln