Skip to content

chore(cicd): commit branch rulesets + add drift and authorship guards - #289

Merged
PeterGeers merged 1 commit into
testfrom
chore/branch-protection-as-code
Dec 1, 2026
Merged

PeterGeers merged 1 commit into
testfrom
chore/branch-protection-as-code

Conversation

@PeterGeers

Copy link
Copy Markdown
Owner

What & why

GitHub's "Your main branch isn't protected" banner is a false positive on this repo: it is rendered from the classic protection object (GET /branches/main/protection -> 404, branches/main.protection.enabled: false), while main is protected by three active rulesets — GET /rules/branches/main returns deletion + non_fast_forward + pull_request (merge-commit only) + required_status_checks (CodeQL x3, GitGuardian, Main Source Guard), with zero bypass actors.

Rather than click-ops a second (classic) rule to silence a cosmetic card, the rulesets are now committed config, and the residue the banner pointed at is now enforced.

Branch protection as code

  • .github/rulesets/{protect-main-baseline,release-main,release-test}.json — exported from the live API (ids 24660088 / 28312126 / 28312125), each with a _note provenance header.
  • scripts/check_branch_rulesets.py — structural + order-insensitive drift check (committed vs live). Unreadable live config warns by default: reading rulesets needs the Administration permission, which a workflow GITHUB_TOKEN cannot hold, and this repo keeps no admin credentials in CI.
  • scripts/apply_branch_rulesets.sh — owner-run --dry-run / apply + verify (terraform-apply model, no click-ops).
  • backend/tests/unit/test_branch_ruleset_drift.py — the offline CI twin: pins what each ruleset enforces and that drift is reported (enforcement downgrade, added bypass actor, dropped required check, widened merge methods), while metadata / _note / list order are ignored.

config#* authorship guard (the scoped plumbing)

  • backend/scripts/check_projection_config_authorship.py (+ unit twin): Flask may import build_config_*_row but must never call it — the SAM plane is the sole author of config#scope/#fields/#mail (spec 02 1.15/3.7/5.8; Req 11.1/11.2). Wired into Backend CI and the required nightly Full Test Suite.
  • Corrects two stale contracts: sync_administration no longer emits config#* rows; _scope_config_version is the fallback, not future work (the version-bump-trap fix shipped in _config_row_version).

Docs

  • 43-cicd-deploys.md: ruleset table, the false-positive evidence, drift/apply commands, and the known gap (no per-PR lint/test gate while Backend/Frontend CI are disabled_manually).
  • 39-backend-data-access-sam-dynamodb.md: the new authorship guard in Enforcement.

Validation

  • python3 scripts/check_branch_rulesets.py -> OK: 3 committed ruleset(s) validated against GitHub
  • python3 scripts/check_branch_rulesets.py --offline and apply_branch_rulesets.sh --dry-run -> clean
  • python3 backend/scripts/check_projection_config_authorship.py -> [OK] ... SAM is the sole author
  • pytest: 46 new tests green; 205 passed across the four touched suites
  • ruff check / ruff format --check clean; fallback_lint.py --paths backend/src green; all workflows parse

Not in this PR (deliberate)

  • Adding MASKING fallback guard-rail + Frontend env single-source guard as required checks — that is a settings change: edit the JSON here, then scripts/apply_branch_rulesets.sh.
  • Choosing a per-PR test gate (re-enable Backend/Frontend CI vs a lean pr-gate.yml).

No deploy workflow is triggered (deploy-sam-* are sam/**-scoped; deploy-frontend is main-only).

`.github/rulesets/` is now the source of truth for the repository rulesets
(protect-main-baseline / release-main / release-test), exported from the live API.
GitHub's "Your main branch isn't protected" banner is a FALSE POSITIVE: it renders
from the CLASSIC protection object (`branches/main.protection.enabled: false`,
`/branches/main/protection` 404) while `main` is protected by these ACTIVE rulesets
(`/rules/branches/main` returns deletion + non_fast_forward + pull_request +
required_status_checks, zero bypass actors).

- scripts/check_branch_rulesets.py: structural + order-insensitive drift check
  (committed vs live). Unreadable live config WARNS by default, because a workflow
  GITHUB_TOKEN cannot hold the Administration permission and no admin credentials live
  in CI; CI gates the committed config structurally via the unit twin instead.
- scripts/apply_branch_rulesets.sh: owner-run apply with --dry-run, then verifies via
  the checker -- the terraform-apply model, never click-ops.
- backend/tests/unit/test_branch_ruleset_drift.py: offline CI twin pinning what
  release-main / release-test enforce (merge-only on main, Main Source Guard required,
  0 approvals by decision, unattributed-change approval on) and that drift is caught
  (enforcement downgrade, bypass actor, dropped required check, widened merge methods)
  while metadata / list order / `_note` are ignored.
- backend/scripts/check_projection_config_authorship.py (+ tests): Flask code may
  IMPORT the build_config_*_row builders but must never CALL them -- the SAM plane is
  the SOLE author of every config#* row (spec 02 1.15/3.7/5.8, Req 11.1/11.2). Wired
  into Backend CI and the required nightly full-test-suite.
- Correct two stale contracts in the scoped plumbing: sync_administration no longer
  emits config#* rows, and _scope_config_version is the per-param FALLBACK, not
  future work (the version-bump-trap fix shipped in _config_row_version).
- steering 43/39: single-source the protection table + commands + the known gap (no
  per-PR lint/test gate while Backend/Frontend CI are disabled_manually).
@PeterGeers
PeterGeers merged commit 142abfa into test Dec 1, 2026
5 checks passed
@PeterGeers
PeterGeers deleted the chore/branch-protection-as-code branch December 1, 2026 19:33
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