Repository navigation
chore(cicd): commit branch rulesets + add drift and authorship guards - #289
Merged
Merged
Conversation
`.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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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), whilemainis protected by three active rulesets —GET /rules/branches/mainreturnsdeletion+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_noteprovenance header.scripts/check_branch_rulesets.py— structural + order-insensitive drift check (committed vs live). Unreadable live config warns by default: reading rulesets needs theAdministrationpermission, which a workflowGITHUB_TOKENcannot 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 importbuild_config_*_rowbut must never call it — the SAM plane is the sole author ofconfig#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.sync_administrationno longer emitsconfig#*rows;_scope_config_versionis 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 aredisabled_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 GitHubpython3 scripts/check_branch_rulesets.py --offlineandapply_branch_rulesets.sh --dry-run-> cleanpython3 backend/scripts/check_projection_config_authorship.py->[OK] ... SAM is the sole authorpytest: 46 new tests green; 205 passed across the four touched suitesruff check/ruff format --checkclean;fallback_lint.py --paths backend/srcgreen; all workflows parseNot in this PR (deliberate)
MASKING fallback guard-rail+Frontend env single-source guardas required checks — that is a settings change: edit the JSON here, thenscripts/apply_branch_rulesets.sh.pr-gate.yml).No deploy workflow is triggered (
deploy-sam-*aresam/**-scoped;deploy-frontendismain-only).