|
| 1 | +# 🛡️ GitHub Rulesets for Bilten |
| 2 | + |
| 3 | +This directory contains GitHub Rulesets that enforce security, quality, and deployment policies for the Bilten event management platform. |
| 4 | + |
| 5 | +## 📋 Overview |
| 6 | + |
| 7 | +GitHub Rulesets provide a centralized way to manage repository rules and policies. They help ensure code quality, security, and compliance across the project. |
| 8 | + |
| 9 | +## 🎯 Rulesets |
| 10 | + |
| 11 | +### 1. Security Ruleset (`security-ruleset.json`) |
| 12 | +**Target**: Main branches (main, master, develop, release/*) |
| 13 | +**Purpose**: Enforce security policies and prevent vulnerabilities |
| 14 | + |
| 15 | +**Key Features**: |
| 16 | +- 🔍 Secret scanning and push protection |
| 17 | +- 📦 Dependency review |
| 18 | +- 🔒 Code scanning with CodeQL |
| 19 | +- ✅ Required security workflows |
| 20 | +- 👥 Mandatory code reviews (2 approvals) |
| 21 | +- 🔐 Required commit signatures |
| 22 | +- 📝 Linear history requirement |
| 23 | + |
| 24 | +### 2. Quality Ruleset (`quality-ruleset.json`) |
| 25 | +**Target**: All branches except hotfix and docs |
| 26 | +**Purpose**: Ensure code quality and maintainability |
| 27 | + |
| 28 | +**Key Features**: |
| 29 | +- 🧪 Required CI/CD workflows |
| 30 | +- ✅ Status checks (Build, Tests, Lint, Type Check, Coverage) |
| 31 | +- 👥 Code reviews (1 approval) |
| 32 | +- 💬 Conversation resolution |
| 33 | +- 🚀 Staging deployment requirement |
| 34 | + |
| 35 | +### 3. Production Ruleset (`production-ruleset.json`) |
| 36 | +**Target**: Main branches only (main, master) |
| 37 | +**Purpose**: Strict production deployment controls |
| 38 | + |
| 39 | +**Key Features**: |
| 40 | +- 🚀 Production deployment workflows |
| 41 | +- 🔒 Security audit requirements |
| 42 | +- ⚡ Performance and E2E tests |
| 43 | +- 👥 Strict code reviews (3 approvals) |
| 44 | +- 🔐 Required signatures |
| 45 | +- 📝 Linear history |
| 46 | +- 💬 Conversation resolution |
| 47 | +- 🛡️ Backup verification |
| 48 | + |
| 49 | +### 4. Development Ruleset (`development-ruleset.json`) |
| 50 | +**Target**: Development branches (develop, feature/*, hotfix/*) |
| 51 | +**Purpose**: Streamlined development workflow |
| 52 | + |
| 53 | +**Key Features**: |
| 54 | +- 🧪 Basic CI/CD workflows |
| 55 | +- ✅ Essential status checks |
| 56 | +- 👥 Light code reviews (1 approval) |
| 57 | +- 🚀 Development deployment |
| 58 | + |
| 59 | +## 🔧 Configuration |
| 60 | + |
| 61 | +### Enforcement Levels |
| 62 | +- **Active**: Rules are enforced and block non-compliant changes |
| 63 | +- **Evaluate**: Rules are evaluated but don't block changes (for testing) |
| 64 | + |
| 65 | +### Bypass Actors |
| 66 | +Rulesets can be bypassed by: |
| 67 | +- **Integration**: Automated systems (CI/CD) |
| 68 | +- **User**: Specific users with bypass permissions |
| 69 | +- **Never**: No bypass allowed (production rules) |
| 70 | + |
| 71 | +### Conditions |
| 72 | +Rulesets apply based on: |
| 73 | +- **Branch patterns**: Which branches the rules apply to |
| 74 | +- **Repository names**: Which repositories are affected |
| 75 | +- **File paths**: Specific files or directories |
| 76 | + |
| 77 | +## 🚀 Implementation |
| 78 | + |
| 79 | +### 1. Enable Rulesets |
| 80 | +```bash |
| 81 | +# Using GitHub CLI |
| 82 | +gh api repos/:owner/:repo/rulesets \ |
| 83 | + --method POST \ |
| 84 | + --field name="Bilten Security Ruleset" \ |
| 85 | + --field enforcement=active \ |
| 86 | + --field target=branch \ |
| 87 | + --field rules='[{"type":"secret_scanning","state":"enabled"}]' |
| 88 | +``` |
| 89 | + |
| 90 | +### 2. Apply to Branches |
| 91 | +```bash |
| 92 | +# Apply security ruleset to main branch |
| 93 | +gh api repos/:owner/:repo/branches/main/protection \ |
| 94 | + --method PUT \ |
| 95 | + --field required_status_checks='{"strict":true,"contexts":["Security Scan"]}' \ |
| 96 | + --field enforce_admins=true |
| 97 | +``` |
| 98 | + |
| 99 | +### 3. Configure Workflows |
| 100 | +Ensure the required workflows exist: |
| 101 | +- `.github/workflows/security-scan.yml` |
| 102 | +- `.github/workflows/ci.yml` |
| 103 | +- `.github/workflows/test.yml` |
| 104 | +- `.github/workflows/lint.yml` |
| 105 | +- `.github/workflows/deploy-production.yml` |
| 106 | + |
| 107 | +## 📊 Monitoring |
| 108 | + |
| 109 | +### Ruleset Status |
| 110 | +Monitor ruleset compliance through: |
| 111 | +- GitHub repository insights |
| 112 | +- Pull request status checks |
| 113 | +- Security tab alerts |
| 114 | +- Dependabot notifications |
| 115 | + |
| 116 | +### Metrics |
| 117 | +Track key metrics: |
| 118 | +- Ruleset bypass frequency |
| 119 | +- Failed status checks |
| 120 | +- Security scan results |
| 121 | +- Code review turnaround time |
| 122 | + |
| 123 | +## 🔄 Maintenance |
| 124 | + |
| 125 | +### Regular Updates |
| 126 | +- Review and update ruleset configurations monthly |
| 127 | +- Adjust enforcement levels based on team feedback |
| 128 | +- Update bypass permissions as needed |
| 129 | +- Monitor and optimize workflow performance |
| 130 | + |
| 131 | +### Troubleshooting |
| 132 | +Common issues and solutions: |
| 133 | + |
| 134 | +#### Ruleset Not Applied |
| 135 | +```bash |
| 136 | +# Check ruleset status |
| 137 | +gh api repos/:owner/:repo/rulesets |
| 138 | + |
| 139 | +# Verify branch protection |
| 140 | +gh api repos/:owner/:repo/branches/main/protection |
| 141 | +``` |
| 142 | + |
| 143 | +#### Workflow Failures |
| 144 | +```bash |
| 145 | +# Check workflow runs |
| 146 | +gh run list --workflow=security-scan.yml |
| 147 | + |
| 148 | +# View workflow logs |
| 149 | +gh run view <run-id> --log |
| 150 | +``` |
| 151 | + |
| 152 | +#### Bypass Issues |
| 153 | +```bash |
| 154 | +# Check bypass permissions |
| 155 | +gh api repos/:owner/:repo/rulesets/:ruleset-id/bypass_actors |
| 156 | +``` |
| 157 | + |
| 158 | +## 📚 Resources |
| 159 | + |
| 160 | +- [GitHub Rulesets Documentation](https://docs.github.com/en/rest/repos/rules) |
| 161 | +- [Branch Protection API](https://docs.github.com/en/rest/branches/branch-protection) |
| 162 | +- [Security Best Practices](https://docs.github.com/en/code-security) |
| 163 | +- [Workflow Syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions) |
| 164 | + |
| 165 | +## 🤝 Contributing |
| 166 | + |
| 167 | +When updating rulesets: |
| 168 | +1. Test changes in a development environment |
| 169 | +2. Update this documentation |
| 170 | +3. Notify the team of changes |
| 171 | +4. Monitor for any issues after deployment |
| 172 | + |
| 173 | +## 📞 Support |
| 174 | + |
| 175 | +For questions or issues with rulesets: |
| 176 | +1. Check the [Common Issues](Common-Issues) wiki page |
| 177 | +2. Review GitHub documentation |
| 178 | +3. Create an issue with detailed information |
| 179 | +4. Contact the development team |
| 180 | + |
| 181 | +--- |
| 182 | + |
| 183 | +**Note**: These rulesets are designed to balance security, quality, and development velocity. Adjust configurations based on your team's needs and project requirements. |
0 commit comments