ci: declare branch protection as rulesets and audit effective drift (#298) - #344
Open
parthrohit22 wants to merge 2 commits into
Open
parthrohit22 wants to merge 2 commits into
parthrohit22 wants to merge 2 commits into
Conversation
…WASP#298) Declare dev and main protection as versioned GitHub rulesets and add a scheduled audit that compares the rules GitHub actually enforces with them, fails on drift, and retains a JSON evidence artifact. - dev: 1 approval, main: 2; code owner review, last-push approval, stale review dismissal, conversation resolution, strict required checks (CI Summary, DCO sign-off, dependency-review, CodeQL), no bypass actors - tests fail if a declared ruleset is weakened or names a check no job runs - run CI and CodeQL on pushes to dev and main for post-merge assurance - stop pushing statistics straight to protected dev; open a PR instead - document admin apply steps, evidence, and the emergency procedure Signed-off-by: parthrohit22 <parthrohit60@gmail.com>
parthrohit22
requested review from
Vishnu2707 and
ritiksah141
as code owners
September 16, 2026 12:12
Semgrep flagged the dynamic urllib call. Requests now go to a fixed api.github.com host over a verified default TLS context, and API error statuses or connection failures are reported as drift. Signed-off-by: parthrohit22 <parthrohit60@gmail.com>
Comment on lines
+184
to
+186
| connection = http.client.HTTPSConnection( # nosemgrep: python.lang.security.audit.httpsconnection-detected.httpsconnection-detected # noqa: E501 | ||
| API_HOST, timeout=30, context=ssl.create_default_context() | ||
| ) |
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 does this PR do?
Declares
devandmainbranch protection as versioned GitHub rulesets and adds an automated audit that fails when the protection GitHub actually enforces is weaker than declared, so #298's controls are demonstrated rather than only documented.Type of change
Changes
Declared state:
.github/branch-protection/{dev,main}.json, in GitHub's ruleset import formatCI Summary,DCO sign-off,dependency-review,Analyze (python),Analyze (javascript); no standing bypass actors.devrequires 1 approval andmainrequires 2. The existingEnforce dev to main sourcejob already runs insideCI Summary.Effective state:
scripts/check_branch_protection.pyplus.github/workflows/branch-protection-audit.ymlGET /repos/{repo}/rules/branches/{branch}and each applied ruleset, then reports missing rules, fewer approvals than declared, missing flags, missing or non-strict checks, and standing bypass actors.branch-protection-evidenceJSON artifact (kept 90 days).Post-merge assurance
ci.ymlandcodeql.ymlnow also run onpushtodevandmain. Post-merge runs are never cancelled (concurrency is keyed by SHA for pushes). This is compatible with the Mergify queue proposed in infra: add Mergify serial merge queue for dev branch #335.Stats bot no longer pushes to protected
devupdate-learn-page.ymlhas been failing withGH006: Protected branch update failed. It now force-updatesdocs/refresh-learn-page-statsand opens or refreshes a PR through the normal protected flow. It uses theSTATS_BOT_TOKENsecret if one is set, because PRs opened withGITHUB_TOKENdon't start workflows.Docs:
docs/ci-pipeline.mdnow separates declared state from effective state, and covers admin apply commands, how to verify each acceptance criterion, and an emergency procedure with no standing bypass.Current effective state (evidence)
Running the audit against
OWASP/openshieldtoday:This matches the #298 finding: no required check is enforced on either branch.
Admin actions needed after merge (I can't do these: my role is write, not admin)
gh api -X POST repos/OWASP/openshield/rulesets --input .github/branch-protection/dev.json(repeat withmain.json), then retire the classic protection.BRANCH_PROTECTION_AUDIT_TOKENsecret (ruleset read-admin) so the audit can verify bypass actors.STATS_BOT_TOKENsecret and allow GitHub Actions to create PRs.Testing
tests/test_check_branch_protection.py: 15 tests. They cover:mainrequires 2 approvalstest_devops_client.pyare local-only (azure-devopsisn't installed on my machine) and also fail on unmodifieddev.ruff check .andruff format --check .are clean, and all workflow YAML parses.OWASP/openshield(output above).Related issue
Partially addresses #298. The in-repo work is complete, but the issue should stay open until an administrator applies the rulesets and the audit and acceptance drills pass.
Checklist
Signed-off-bytrailerinfra/description