Skip to content

Add branch-protection tooling + security/CI/AI-SDLC hardening#2

Merged
DenWin merged 3 commits into
mainfrom
setup/branch-protection-tooling
Jul 16, 2026
Merged

Add branch-protection tooling + security/CI/AI-SDLC hardening#2
DenWin merged 3 commits into
mainfrom
setup/branch-protection-tooling

Conversation

@DenWin

@DenWin DenWin commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Goal

Two related deliverables on one branch: (1) the one-time branch-protection tooling (setup/Protect-MainBranch.ps1), and (2) the concepts worth keeping from the ai-lab review — governance (CODEOWNERS, PR/issue templates), supply-chain hardening (SHA pins, zizmor, full-history secret scan), policy checks (semgrep, PSSA custom rule), and setup tooling for repo security and AI-maintainer identity.

Scope

  • setup/Protect-MainBranch.ps1 (ruleset: PR + lint check + merge queue + thread resolution; auto-merge/branch-cleanup; opt-in admin-exempt -WithStrictLayer), Enable-RepoSecurity.ps1 (secret scanning, Dependabot, PVR, read-only token, Actions allowlist + SHA-pinning requirement), AI-maintainer identity KB (AsciiDoc), tests for all of it
  • .github/ — CODEOWNERS (control surfaces only), PR template with mandatory Evidence, issue forms, gitleaks full-history CI step, scheduled semgrep workflow, SHA-pinned actions, Dependabot cooldown + pip ecosystem
  • .pre-commit-config.yaml — zizmor and semgrep hooks
  • .config/ — semgrep policy rules, PSScriptAnalyzer custom rule (Measure-RequireStrictMode), Set-StrictMode retrofit across all scripts, asciidoctor in bootstrap

Deliberately not included: repo-level squash-only (would bind admin bypass too), code-owner review enforcement (deferred until AI-maintainer identities exist), required_linear_history (contradicts admin merge-method freedom).

Risk & rollback

Low-to-moderate. The semgrep hook and zizmor add new commit-time gates — a false-positive rule blocks commits; mitigation: delete/adjust the rule in .config/semgrep/rules/. The Set-StrictMode retrofit changes runtime semantics of all scripts — covered by the test suite (34 tests green) and it already surfaced+fixed one latent bug. Applied-live repo settings (auto-merge, Actions allowlist + SHA pinning) are outside this diff and reversible via one gh api call each. Rollback of the diff: revert the branch's two commits; no migrations.

Evidence

  • Fast test lane: 34 passed, 0 failed (Pester, incl. new ruleset/setting/rule tests)
  • PSScriptAnalyzer (incl. the new custom rule): clean over all 19 PowerShell files
  • All pre-commit hooks pass locally; semgrep verified to block a probe violation with exit 1; asciidoctor-validate skipped locally (no Ruby) and validated by this PR's CI instead
  • zizmor: repo clean after fixing its 3 findings (persist-credentials, Dependabot cooldown)
  • Actions allowlist + SHA-pinning requirement verified live via gh api GET

🤖 Generated with Claude Code

DenWin and others added 2 commits July 16, 2026 07:11
- setup/Protect-MainBranch.ps1 creates a main-protection ruleset (require PR +
  lint check, merge queue, block force-push/deletion), with a payload-builder
  unit test and a README (run once on a new repo, then delete the folder).
- Remove .config/scripts/Enable-MergeQueue.* (superseded by the fuller ruleset).
- Point .github/README.md and AGENTS.md at the new setup/ tooling.
- Bump CI actions off deprecated Node 20 (checkout@v7, setup-python@v6, cache@v6).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Governance & PR flow:
- CODEOWNERS for control surfaces only (no catch-all)
- PR template with mandatory Evidence section; issue forms (bug/feature)
- Ruleset: require review-thread resolution; enable auto-merge +
  delete-branch-on-merge; opt-in admin-exempt strict layer (-WithStrictLayer)
- setup/Enable-RepoSecurity.ps1: secret scanning + push protection,
  Dependabot alerts/fixes, private vuln reporting, read-only workflow
  token, Actions allowlist + required SHA pinning
- setup/AI-Maintainer-Identity.adoc: least-privilege agent identity KB

Supply chain & workflow security:
- SHA-pin all actions; zizmor hook; persist-credentials:false
- Full-history gitleaks scan in CI (staged-only local hook is a no-op there)
- Dependabot: 7-day cooldown; pip ecosystem for the semgrep pin

Policy checks:
- semgrep as a per-commit local hook (PyPI wheel; managed clone breaks on
  Windows) + monthly registry scan workflow
- PSScriptAnalyzer custom rule Measure-RequireStrictMode; Set-StrictMode
  retrofitted across all scripts (caught one real bug in Enable-RepoSecurity)
- Bootstrap: install asciidoctor when Ruby is present

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@DenWin DenWin changed the title Add one-time branch-protection tooling (setup/) Add branch-protection tooling + security/CI/AI-SDLC hardening Jul 16, 2026
Semgrep was briefly wired in as an active pre-commit hook + scheduled CI
scan; reverting that back to an inert overlay. Reasons: the managed
pre-commit hook doesn't clone on Windows (case-colliding paths), and
PowerShell rule execution is Pro-gated (free tier silently reports 0
findings) with Pro capped at 10 repos account-wide - unsuitable for a
template cloned into many repos. Tracking issue for a replacement:
#3

- .pre-commit-config.yaml: remove the semgrep hook
- .github/: remove semgrep-scheduled.yml, requirements-semgrep.txt,
  the Dependabot pip entry
- .config/overlays/semgrep/: activation-only (README + hook fragment)
- .config/semgrep/rules/: the two verified rules stay as real, tracked
  config, renamed to match their rule id (python-/bash- prefix)
- .config/overlays/semgrep-pro/: documents the Pro-tier gate

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@DenWin
DenWin merged commit e8090c4 into main Jul 16, 2026
3 checks passed
@DenWin
DenWin deleted the setup/branch-protection-tooling branch July 16, 2026 14:14
@DenWin
DenWin restored the setup/branch-protection-tooling branch July 17, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant