[GHAS CodeQL Series] - Part 2: Implementing Alert-Mode Repository Rulesets #191259
|
Welcome back to our GitHub Advanced Security CodeQL series! In Part 1, we enabled CodeQL scanning across repositories by using security configurations. Once CodeQL is enabled, developers already get pull request scanning, net new alerts, annotations, and Copilot Autofix suggestions for supported alerts during pull requests. This post is about the next step: using repository rulesets to operationalize that alert-first experience at scale. In other words, rulesets do not create CodeQL alerts in pull requests, but they do help you standardize coverage, require the code scanning check to run, and support compliance goals without blocking merges on new findings yet. Series Overview
Why Start with Alert Mode?Before jumping straight to blocking vulnerable code merges, there is significant value in starting with an alert-first approach. Developer Benefits
Organizational Benefits
What Developers Already Get Before a RulesetThis is the most important framing for Part 2: if CodeQL is already enabled and scanning pull requests, developers can already see code scanning results in their pull requests even when no ruleset exists.
Repository rulesets become valuable when you want to make that experience consistent and governable across repositories or across an organization.
Understanding Repository Rulesets vs. Branch Protection RulesRepository rulesets represent GitHub's modern approach to repository governance, offering significant advantages over traditional branch protection rules. Key Advantages of Rulesets
Why Choose Rulesets for Code ScanningRepository rulesets provide native support for code scanning merge protection, making them the best choice when you want to require the code scanning check itself and standardize thresholds across repositories. That is especially useful for compliance programs and larger engineering organizations that need consistent governance. Step-by-Step Implementation GuideStep 1: Navigate to Repository or Organization RulesetsRulesets can be managed at either the repository level or the organization level:
To create an organization ruleset:
Step 2: Create a New Branch RulesetNow create a branch ruleset specifically for non-blocking code scanning governance:
Step 3: Configure Ruleset TargetsThis step determines which repositories the ruleset applies to. Enforcement Status
Note Evaluate mode is helpful for understanding how a ruleset would behave, but it does not control whether developers see pull request alerts. Pull request alerts come from CodeQL scanning itself. Target RepositoriesChoose your scope based on your organization's needs:
Step 4: Set Branch TargetingDefine which branches the branch ruleset should protect: Recommended Configuration
Advanced TargetingFor organizations with complex branching strategies:
Step 5: Configure Code Scanning Settings (Non-Blocking Findings)This is the step that keeps new findings non-blocking while still requiring the code scanning check:
Understanding What "None" Actually MeansSetting both thresholds to "None" means:
This can feel a little strict at first, because you are not blocking on new findings, but you are still making the scan mandatory. That tradeoff is often acceptable when your goal is compliance, coverage verification, or change management across a large set of repositories. If your goal is only to give developers visibility into CodeQL findings in pull requests, you may not need a ruleset yet. CodeQL already provides that experience when pull request scanning is enabled. Step 6: Optional Complementary Protection RulesWhile keeping security findings non-blocking, you can still layer in other protections that make sense for your software delivery process. Pull Request Requirements
Status Check Requirements
Code Quality
Sensitive File ProtectionsIf you want to restrict changes to specific file paths, treat that as a separate control. File path restrictions are typically handled with a push ruleset, not this branch ruleset. Step 7: Create and Activate the RulesetFinal steps to implement your alert-mode ruleset:
What This Implementation AchievesYour implementation now gives you two complementary outcomes. 1. Developer Education from CodeQL Pull Request Scanning
2. Governance and Compliance from Rulesets
Monitoring and Measuring SuccessKey Metrics to TrackCoverage Metrics
Pull Request Alert Metrics
Developer Engagement
Monitoring Tools and ApproachesGitHub Security OverviewAccess organization-level visibility:
Repository-Level MonitoringFor individual repository insights:
API-Based ReportingFor alert inventory reporting, the GitHub CLI can give you better pagination support and more context than a single REST call: # List open code scanning alerts across an organization with pagination and useful context
gh api --paginate \
-H "Accept: application/vnd.github+json" \
"/orgs/$ORG/code-scanning/alerts?state=open&per_page=100" \
--jq '.[] | {repo: .repository.full_name, number: .number, rule: .rule.id, severity: (.rule.security_severity_level // .rule.severity), state: .state, ref: .most_recent_instance.ref}'Use API output for inventory and operational reporting, and use Security overview for the richer pull request alert and Autofix metrics. Best Practices for Alert Mode SuccessCommunication Strategy
Developer Support
Continuous Improvement
Preparing for Part 3: Blocking ModeAfter a period of successful alert-first operation, you'll be ready to transition to blocking controls. Monitor these indicators: Readiness Signals
Pre-Blocking Checklist
Troubleshooting Common IssuesRuleset Not ApplyingSymptoms: Target repositories are not showing ruleset enforcement Solutions:
Missing Code Scanning ResultsSymptoms: No code scanning feedback is appearing on pull requests Solutions:
Developers Expect the Ruleset to Create AlertsSymptoms: Teams think the ruleset is what turns pull request alerts on Solutions:
What's Next?Excellent work! You now have a clearer operating model: CodeQL gives developers alert-first pull request security feedback by default, and repository rulesets help you standardize and govern that experience across repositories. In Part 3 of this series, we'll cover the final step: moving from non-blocking findings to blocking merges on the thresholds that match your team's readiness and risk tolerance. Coming up in Part 3:
Key Takeaways
Additional ResourcesEssential Documentation:
Changelog and Guidance:
Community Resources: This is Part 2 of our GitHub Advanced Security CodeQL series. Continue to Part 3 when you're ready to turn proven, non-blocking visibility into targeted enforcement. Series Navigation:
|
Replies: 2 comments 1 reply
|
✅ Verified by GitHub
Click to openWelcome back to our GitHub Advanced Security CodeQL series! In [Part 1](https://github.com/orgs/community/discussions/177178), we enabled CodeQL scanning across repositories by using security configurations. Once CodeQL is enabled, developers already get pull request scanning, net new alerts, annotations, and Copilot Autofix suggestions for supported alerts during pull requests.This post is about the next step: using repository rulesets to operationalize that alert-first experience at scale. In other words, rulesets do not create CodeQL alerts in pull requests, but they do help you standardize coverage, require the code scanning check to run, and support compliance goals without blocking merges on new findings yet. Series Overview
Why Start with Alert Mode?Before jumping straight to blocking vulnerable code merges, there is significant value in starting with an alert-first approach. Developer Benefits
Organizational Benefits
What Developers Already Get Before a RulesetThis is the most important framing for Part 2: if CodeQL is already enabled and scanning pull requests, developers can already see code scanning results in their pull requests even when no ruleset exists.
Repository rulesets become valuable when you want to make that experience consistent and governable across repositories or across an organization.
Understanding Repository Rulesets vs. Branch Protection RulesRepository rulesets represent GitHub's modern approach to repository governance, offering significant advantages over traditional branch protection rules. Key Advantages of Rulesets
Why Choose Rulesets for Code ScanningRepository rulesets provide native support for code scanning merge protection, making them the best choice when you want to require the code scanning check itself and standardize thresholds across repositories. That is especially useful for compliance programs and larger engineering organizations that need consistent governance. Step-by-Step Implementation GuideStep 1: Navigate to Repository or Organization RulesetsRulesets can be managed at either the repository level or the organization level:
To create an organization ruleset:
Step 2: Create a New Branch RulesetNow create a branch ruleset specifically for non-blocking code scanning governance:
Step 3: Configure Ruleset TargetsThis step determines which repositories the ruleset applies to. Enforcement Status
Target RepositoriesChoose your scope based on your organization's needs:
Step 4: Set Branch TargetingDefine which branches the branch ruleset should protect: Recommended Configuration
Advanced TargetingFor organizations with complex branching strategies:
Step 5: Configure Code Scanning Settings (Non-Blocking Findings)This is the step that keeps new findings non-blocking while still requiring the code scanning check:
Understanding What "None" Actually MeansSetting both thresholds to "None" means:
This can feel a little strict at first, because you are not blocking on new findings, but you are still making the scan mandatory. That tradeoff is often acceptable when your goal is compliance, coverage verification, or change management across a large set of repositories. If your goal is only to give developers visibility into CodeQL findings in pull requests, you may not need a ruleset yet. CodeQL already provides that experience when pull request scanning is enabled. Step 6: Optional Complementary Protection RulesWhile keeping security findings non-blocking, you can still layer in other protections that make sense for your software delivery process. Pull Request Requirements
Status Check Requirements
Code Quality
Sensitive File ProtectionsIf you want to restrict changes to specific file paths, treat that as a separate control. File path restrictions are typically handled with a push ruleset, not this branch ruleset. Step 7: Create and Activate the RulesetFinal steps to implement your alert-mode ruleset:
What This Implementation AchievesYour implementation now gives you two complementary outcomes. 1. Developer Education from CodeQL Pull Request Scanning
2. Governance and Compliance from Rulesets
Monitoring and Measuring SuccessKey Metrics to TrackCoverage Metrics
Pull Request Alert Metrics
Developer Engagement
Monitoring Tools and ApproachesGitHub Security OverviewAccess organization-level visibility:
Repository-Level MonitoringFor individual repository insights:
API-Based ReportingFor alert inventory reporting, the GitHub CLI can give you better pagination support and more context than a single REST call: # List open code scanning alerts across an organization with pagination and useful context
gh api --paginate \
-H "Accept: application/vnd.github+json" \
"/orgs/$ORG/code-scanning/alerts?state=open&per_page=100" \
--jq '.[] | {repo: .repository.full_name, number: .number, rule: .rule.id, severity: (.rule.security_severity_level // .rule.severity), state: .state, ref: .most_recent_instance.ref}'Use API output for inventory and operational reporting, and use Security overview for the richer pull request alert and Autofix metrics. Best Practices for Alert Mode SuccessCommunication Strategy
Developer Support
Continuous Improvement
Preparing for Part 3: Blocking ModeAfter a period of successful alert-first operation, you'll be ready to transition to blocking controls. Monitor these indicators: Readiness Signals
Pre-Blocking Checklist
Troubleshooting Common IssuesRuleset Not ApplyingSymptoms: Target repositories are not showing ruleset enforcement Solutions:
Missing Code Scanning ResultsSymptoms: No code scanning feedback is appearing on pull requests Solutions:
Developers Expect the Ruleset to Create AlertsSymptoms: Teams think the ruleset is what turns pull request alerts on Solutions:
What's Next?Excellent work! You now have a clearer operating model: CodeQL gives developers alert-first pull request security feedback by default, and repository rulesets help you standardize and govern that experience across repositories. In Part 3 of this series, we'll cover the final step: moving from non-blocking findings to blocking merges on the thresholds that match your team's readiness and risk tolerance. Coming up in Part 3:
Key Takeaways
Additional ResourcesEssential Documentation:
Changelog and Guidance:
Community Resources: This is Part 2 of our GitHub Advanced Security CodeQL series. Continue to Part 3 when you're ready to turn proven, non-blocking visibility into targeted enforcement. Series Navigation:
|








✅ Verified by GitHub
Click to open
Welcome back to our GitHub Advanced Security CodeQL series! In [Part 1](https://github.com/orgs/community/discussions/177178), we enabled CodeQL scanning across repositories by using security configurations. Once CodeQL is enabled, developers already get pull request scanning, net new alerts, annotations, and Copilot Autofix suggestions fo…