[GHAS CodeQL Series] - Part 2: Implementing Alert-Mode Repository Rulesets #191259
vishaljsoni
started this conversation in
Discover: GitHub Best Practices
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
GitHub Advanced Security CodeQL Series - Part 2: Implementing Alert-Mode Repository Rulesets
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 Ruleset
This 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 Rules
Repository 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 Scanning
Repository 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 Guide
Step 1: Navigate to Repository or Organization Rulesets
Rulesets can be managed at either the repository level or the organization level:
To create an organization ruleset:
Step 2: Create a New Branch Ruleset
Now create a branch ruleset specifically for non-blocking code scanning governance:
"CodeQL Alert Mode - Governed Repositories""Requires CodeQL scanning to run while keeping new security findings non-blocking during rollout."Step 3: Configure Ruleset Targets
This 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 Repositories
Choose your scope based on your organization's needs:
Step 4: Set Branch Targeting
Define which branches the branch ruleset should protect:
Recommended Configuration
mainor whichever branch is your defaultrelease/*for release branches, or a specific branch name likemainto target it directlyAdvanced Targeting
For 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 Means
Setting 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 Rules
While 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 Protections
If 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 Ruleset
Final steps to implement your alert-mode ruleset:
What This Implementation Achieves
Your implementation now gives you two complementary outcomes.
1. Developer Education from CodeQL Pull Request Scanning
2. Governance and Compliance from Rulesets
Monitoring and Measuring Success
Key Metrics to Track
Coverage Metrics
Pull Request Alert Metrics
Developer Engagement
Monitoring Tools and Approaches
GitHub Security Overview
Access organization-level visibility:
Repository-Level Monitoring
For individual repository insights:
API-Based Reporting
For alert inventory reporting, the GitHub CLI can give you better pagination support and more context than a single REST call:
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 Success
Communication Strategy
Developer Support
Continuous Improvement
Preparing for Part 3: Blocking Mode
After 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 Issues
Ruleset Not Applying
Symptoms: Target repositories are not showing ruleset enforcement
Solutions:
Missing Code Scanning Results
Symptoms: No code scanning feedback is appearing on pull requests
Solutions:
Developers Expect the Ruleset to Create Alerts
Symptoms: 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 Resources
Essential 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:
Beta Was this translation helpful? Give feedback.
All reactions