Hmm, the user is asking for a repository ruleset design—specifically protections, required checks, and exceptions. This is a technical but practical request, likely from someone managing code quality or DevOps in a team. They probably want a comprehensive yet adaptable template, not just a list of features.
I should structure this as a policy document that balances security and developer experience. Need to cover core areas: branch protection, CI/CD checks, access controls, and exceptions. The user might be thinking about their own repo’s pain points—like merge chaos or security gaps—so I’ll emphasize rationale behind each rule.
Ah, and exceptions are key—real-world workflows require flexibility. I’ll call out common edge cases (hotfixes, documentation-only changes) with concrete examples. The tone should be authoritative but not rigid, stressing that rules evolve with team maturity. Maybe add a maturity model later to help them gauge progress.
Wait, should I assume a specific platform? Better keep it generic (GitHub/GitLab/Bitbucket) but call out platform-specific terms where needed (e.g., "CODEOWNERS" vs. "approvers"). Avoid jargon but stay precise.
User might also need implementation tips—like "use tags for exception bypasses" or "audit logs." I’ll weave those in. Oh, and remind them to iterate; no ruleset survives first contact with reality unscathed.
Comprehensive Repository Ruleset Design
1. Core Principles
- Principle of Least Privilege: Minimal permissions by default
- Defense in Depth: Multiple overlapping safeguards
- Auditability: All actions logged and reviewable
- Developer Experience Balance: Security without excessive friction
2. Branch Protection Rules
Protected Branches
main/master (production)
staging (pre-production)
release/* (release candidates)
Required Pull Request Reviews
- Minimum approvals: 1-2 (based on team size/risk)
- Code owners required: Yes (via
CODEOWNERS file)
- Dismiss stale approvals: Yes (when new commits pushed)
- Restrict pushes: Only allow specific roles (maintainers, automation)
- Require conversation resolution: All PR comments must be resolved
Status Checks
- Required before merge: All CI pipelines must pass
- Required after last update: Yes (prevents merging stale PRs)
- Timeout: 1 hour (configurable per pipeline)
Linear History Requirement
- Squash merging: Disallowed (preserve commit history)
- Rebase merging: Allowed (with caution)
- Merge commits: Required for integration
3. Required Checks & Validations
CI/CD Pipeline Gates
-
Security Scans
- SAST (Static Application Security Testing)
- SCA (Software Composition Analysis)
- Secret scanning (no hardcoded credentials)
- Dependency vulnerability scanning
-
Code Quality
- Linting (language-specific)
- Formatting consistency
- Test coverage ≥ threshold (e.g., 80%)
- All tests passing (unit/integration)
-
Build Verification
- Successful build on all target platforms
- Artifact generation/publishing
- Container image scanning (if applicable)
-
Documentation
- Updated
CHANGELOG.md for user-facing changes
- README updates for new features
- API documentation generation (if applicable)
4. Access Control Matrix
| Role | Branch Access | Merge Rights | Force Push | Bypass Rules |
|---|
| Maintainer | Read/Write | ✅ | ❌ | Emergency only |
| Developer | Read/Write (feature branches) | ❌ | ❌ | Never |
| Automation | Read (tokens with scopes) | ✅ (via bots) | ❌ | Specific checks |
| Guest/External | Read-only (selected repos) | ❌ | ❌ | N/A |
5. Exception Framework
A. Bypass Mechanisms (Strictly Controlled)
-
Hotfix/Production Breakglass
- Requires: 2 senior maintainer approvals + Security team notification
- Must create post-incident review within 24h
- Automatic audit log alert
-
Documentation-Only Changes
- Path-based exception:
docs/, *.md files
- Skip CI if: Only markdown/text files changed
- Still require 1 approval
-
Infrastructure as Code Exceptions
- IaC changes require:terraform-plan review + security scan
- Can auto-merge after X days if no conflicts (for non-breaking changes)
B. Conditional Waivers
- Test flakiness: Allow 1 retry before blocking (configurable)
- Security scan false positives: Pre-approved patterns via allowlist (audited quarterly)
- Lock file updates: Automated dependency updates via Dependabot/Renovate can bypass human review
6. Special Workflow Protections
Secret Management
- Never allow secrets in PRs (automated blocking)
- Use vault/integrated secrets management only
- Rotate any accidentally committed secrets immediately
Large File Handling
- Block files > 10MB (use LFS/artifact storage)
- Prevent binary files in code directories
Signed Commits
- Require GPG-signed commits for
main branch
- Optional for feature branches (enforced via CI)
7. Monitoring & Compliance
Automated Auditing
- Weekly report: bypass rule usage
- Monthly: permission drift detection
- Real-time alerts for: force pushes, direct main pushes, rule changes
Compliance Reports
- Generate SOX/GDPR/HIPAA reports as needed
- Export merge history with approver signatures
- Retention: All audit logs for 7 years
8. Implementation Roadmap
Phase 1: Foundation (Week 1-2)
- Enable branch protection on
main
- Require 1 approval + CI passing
- Set up basic security scanning
Phase 2: Hardening (Week 3-4)
- Add CODEOWNERS requirement
- Implement signed commits
- Set up audit logging
Phase 3: Optimization (Week 5-6)
- Configure exceptions based on team feedback
- Tune CI timeouts/flakiness handling
- Implement documentation-only bypass
Phase 4: Maturity (Ongoing)
- Quarterly rule review
- Permission recertification
- Compliance reporting automation
9. Platform-Specific Notes
GitHub
- Use: Branch protection rules, required status checks, CODEOWNERS
- Bypass: Use
restrictions with dismiss_stale_reviews
- Tokens: Fine-grained PATs for automation
GitLab
- Use: Merge request approvals, push rules, code owners
- Bypass:
skip_pipeline in commit messages (monitored)
- Protected environments for production deployment
Bitbucket
- Use: Branch permissions, merge checks, pull request validators
- Bypass: Admin overrides (logged)
10. Exception Request Process
-
Submit ticket to security/ops team with:
- Business justification
- Risk assessment
- Duration (temporary/permanent)
- mitigation plan
-
Review within 4 business hours (emergency: 1 hour)
-
Implementation:
- Time-boxed exceptions auto-expire
- All exceptions logged with approver
- Quarterly review of active exceptions
11. Do's and Don'ts
✅ DO:
- Start strict, relax based on data
- Communicate changes 2 weeks in advance
- Monitor false positive rates
- Train developers on "why" behind rules
- Review rules quarterly with team
❌ DON'T:
- Make exceptions without documentation
- Disable security scanning for "speed"
- Give permanent bypass rights
- Ignore audit logs
- Let rules accumulate without pruning
Final Recommendation: Start with the Phase 1 foundation for all repos. Customize exceptions after 30 days of real usage data. The most effective rulesets evolve with team maturity—treat this as living documentation, not a one-time setup.