Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
357 changes: 357 additions & 0 deletions .github/BRANCH_PROTECTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,357 @@
# 🛡️ Branch Protection Rules Configuration

## Overview
This document outlines the branch protection rules for the HealthLinc repository to ensure code quality, security, and compliance with healthcare regulations.

## Branch Protection Rules

### Main Branch (`main`)
```yaml
protection_rules:
required_status_checks:
strict: true
contexts:
- "lint-and-test"
- "security-scan"
- "build-and-push"
- "healthcare-compliance-check"

enforce_admins: true

required_pull_request_reviews:
required_approving_review_count: 2
dismiss_stale_reviews: true
require_code_owner_reviews: true
restrict_dismissals:
users: []
teams: ["healthcare-compliance", "security-team"]

restrictions:
users: []
teams: ["developers", "healthcare-team"]
apps: []

required_linear_history: true
allow_force_pushes: false
allow_deletions: false
```

### Develop Branch (`develop`)
```yaml
protection_rules:
required_status_checks:
strict: true
contexts:
- "lint-and-test"
- "security-scan"
- "build-and-push"

enforce_admins: false

required_pull_request_reviews:
required_approving_review_count: 1
dismiss_stale_reviews: true
require_code_owner_reviews: false

restrictions:
users: []
teams: ["developers"]
apps: []

required_linear_history: false
allow_force_pushes: false
allow_deletions: false
```

### Feature Branches (`feature/*`)
```yaml
protection_rules:
required_status_checks:
strict: false
contexts:
- "lint-and-test"
- "security-scan"

enforce_admins: false

required_pull_request_reviews:
required_approving_review_count: 1
dismiss_stale_reviews: false
require_code_owner_reviews: false

required_linear_history: false
allow_force_pushes: true
allow_deletions: true
```

## Healthcare Compliance Rules

### HIPAA Compliance Checks
```yaml
hipaa_compliance:
required_checks:
- "phi-data-protection-scan"
- "access-control-validation"
- "audit-trail-verification"
- "encryption-compliance-check"

approval_requirements:
- security_team_approval: true
- compliance_officer_approval: true
- healthcare_lead_approval: true

restricted_files:
- "**/*patient*"
- "**/*medical*"
- "**/*phi*"
- "backend/*/database/migrations/*"
- "config/*production*"
```

### Security Review Requirements
```yaml
security_review:
required_for_paths:
- "backend/auth/**"
- "backend/gateway/**"
- "backend/fhir-gateway/**"
- "src/api/auth/**"
- "**/*secrets*"
- "**/*config*"
- ".github/workflows/**"

reviewers:
- "@security-team"
- "@healthcare-compliance"

checks:
- "vulnerability-scan"
- "secret-detection"
- "compliance-validation"
```

## Automated PR Rules

### PR Automation Configuration
```yaml
pr_automation:
auto_merge:
enabled: true
conditions:
- all_checks_passed: true
- approved_by_required_reviewers: true
- no_changes_requested: true
- branch_up_to_date: true

excluded_paths:
- "backend/*/migrations/**"
- "config/production/**"
- ".github/workflows/**"

auto_assign:
enabled: true
reviewers:
- "@healthcare-team"
- "@security-team"

based_on_files:
"backend/auth/**": ["@auth-team"]
"backend/claimlinc/**": ["@nphies-team"]
"backend/payments/**": ["@payments-team"]
"frontend/**": ["@frontend-team"]
"docs/**": ["@docs-team"]

labels:
auto_apply:
- path: "backend/**"
label: "backend"
- path: "frontend/**"
label: "frontend"
- path: "docs/**"
label: "documentation"
- path: "**/*test*"
label: "tests"
- path: "**/*security*"
label: "security"
- path: "**/*healthcare*"
label: "healthcare"
```

### PR Templates
```yaml
pr_templates:
default:
title_format: "[{branch_type}] {title}"

required_sections:
- description
- testing_checklist
- security_checklist
- compliance_checklist

security_checklist:
- "[ ] No hardcoded secrets or API keys"
- "[ ] Proper input validation implemented"
- "[ ] Authentication/authorization checks in place"
- "[ ] PHI data properly encrypted"
- "[ ] Audit logging implemented"

compliance_checklist:
- "[ ] HIPAA compliance verified"
- "[ ] NPHIES integration standards followed"
- "[ ] Data privacy requirements met"
- "[ ] Audit trails maintained"
- "[ ] Access controls implemented"
```

## Status Checks Configuration

### Required Status Checks
```yaml
status_checks:
healthcare_compliance:
name: "Healthcare Compliance Check"
description: "Validates HIPAA and healthcare regulations compliance"
required: true

security_scan:
name: "Security Vulnerability Scan"
description: "Scans for security vulnerabilities and secrets"
required: true

code_quality:
name: "Code Quality Check"
description: "Linting and code quality validation"
required: true

automated_tests:
name: "Automated Test Suite"
description: "Unit, integration, and end-to-end tests"
required: true

phi_data_protection:
name: "PHI Data Protection Scan"
description: "Ensures proper handling of patient health information"
required: true

nphies_integration:
name: "NPHIES Integration Test"
description: "Validates Saudi healthcare system integration"
required: false
allowed_to_fail: true
```

## Implementation Guide

### 1. GitHub Repository Settings
Navigate to: Repository → Settings → Branches

### 2. Create Branch Protection Rules
1. Click "Add rule"
2. Set branch name pattern (e.g., `main`, `develop`, `feature/*`)
3. Configure protection settings as per the rules above

### 3. Configure Required Status Checks
1. Enable "Require status checks to pass before merging"
2. Add required status checks from the list above
3. Enable "Require branches to be up to date before merging"

### 4. Set Up Code Owners
Create `.github/CODEOWNERS` file:
```
# Global owners
* @healthcare-team @security-team

# Backend services
backend/auth/ @auth-team @security-team
backend/claimlinc/ @nphies-team @healthcare-team
backend/payments/ @payments-team @security-team
backend/fhir-gateway/ @interoperability-team @healthcare-team

# Frontend
frontend/ @frontend-team
frontend/clinician-portal/ @frontend-team @healthcare-team

# Infrastructure and CI/CD
.github/ @devops-team @security-team
scripts/ @devops-team
docker-compose.yml @devops-team
wrangler.toml @devops-team

# Documentation
docs/ @docs-team @healthcare-team
README.md @docs-team
```

### 5. Configure PR Templates
Create `.github/pull_request_template.md`:
```markdown
## Description
Brief description of changes

## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
- [ ] Security fix
- [ ] Healthcare compliance update

## Testing Checklist
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed
- [ ] Performance impact assessed

## Security Checklist
- [ ] No hardcoded secrets
- [ ] Input validation implemented
- [ ] Authentication checks in place
- [ ] PHI data properly handled
- [ ] Audit logging added

## Healthcare Compliance Checklist
- [ ] HIPAA compliance verified
- [ ] NPHIES standards followed
- [ ] Data privacy requirements met
- [ ] Audit requirements satisfied
- [ ] Access controls implemented

## Deployment Checklist
- [ ] Environment variables updated
- [ ] Database migrations tested
- [ ] Rollback plan prepared
- [ ] Monitoring configured
```

## Monitoring and Alerts

### Set up monitoring for:
- Branch protection violations
- Failed security checks
- Healthcare compliance violations
- Unauthorized access attempts

### Configure alerts for:
- Direct pushes to protected branches
- Security scan failures
- Compliance check failures
- Failed required reviews

## Maintenance

### Regular Tasks
1. Review and update protection rules monthly
2. Audit code owner assignments quarterly
3. Update compliance requirements as regulations change
4. Review and adjust security checks based on threat landscape

### Compliance Audits
1. Monthly compliance review meetings
2. Quarterly security assessments
3. Annual healthcare regulation compliance audit
4. Continuous monitoring of protection rule effectiveness

---

**⚠️ Important**: These rules ensure code quality, security, and healthcare compliance. Contact the DevOps team before making changes to branch protection rules.
Loading