External PR Approval System Verification
This document verifies that the external PR approval system properly restricts access to secrets and only allows maintainers to approve PRs for testing.
π Security Verification Checklist
β Permission Checking
Requirement: Only maintainers with write
, maintain
, or admin
permissions can approve external PRs.
Implementation:
- Uses GitHub API
getCollaboratorPermissionLevel
to check user permissions - Only allows approval if permission is one of:
['admin', 'maintain', 'write']
- Provides clear error messages for unauthorized users
Code Location: .github/workflows/external-pr.yml
- comment-approval
job
β External PR Detection
Requirement: Only external PRs (from forks) should require approval.
Implementation:
- Compares
pr.head.repo.full_name
with current repository - Internal PRs automatically approved
- External PRs require manual approval
Code Location: .github/workflows/external-pr.yml
- security-check
job
β Comment-Based Approval
Requirement: Maintainers can approve via comments with specific keywords.
Implementation:
- Monitors for approval keywords:
/approve
,/approve-testing
,approved for testing
, etc. - Validates commenter permissions before processing
- Adds
approved-for-testing
label automatically - Posts confirmation comment with audit trail
Supported Commands:
/approve
(recommended)/approve-testing
approved for testing
approve for testing
/test-approved
β Clear Instructions
Requirement: Maintainers receive clear instructions on how to approve PRs.
Implementation:
- Automatic comment posted on external PRs
- Step-by-step approval instructions
- Security checklist for reviewers
- Clear distinction between approved and unapproved tests
π§ͺ Test Scenarios
Scenario 1: External PR from Fork
Expected Behavior:
- PR opened from fork triggers security check
- Automatic comment posted with approval instructions
- Basic tests run immediately (no secrets)
- Integration tests wait for approval
Verification Steps:
- Create PR from fork
- Verify security comment appears
- Verify basic tests run
- Verify integration tests donβt run until approved
Scenario 2: Maintainer Approval via Comment
Expected Behavior:
- Maintainer comments
/approve
- System checks maintainer permissions
- Label added automatically
- Confirmation comment posted
- Full test suite runs
Verification Steps:
- Maintainer comments
/approve
on external PR - Verify permission check passes
- Verify
approved-for-testing
label added - Verify confirmation comment posted
- Verify full tests run
Scenario 3: Non-Maintainer Attempts Approval
Expected Behavior:
- Non-maintainer comments
/approve
- System checks permissions
- Permission denied message posted
- No approval granted
- Tests remain restricted
Verification Steps:
- External contributor or read-only user comments
/approve
- Verify permission check fails
- Verify error message explains permission requirements
- Verify no label added
- Verify tests remain restricted
Scenario 4: Internal PR (Same Repository)
Expected Behavior:
- PR opened from same repository
- No approval required
- All tests run automatically
- No security comment posted
Verification Steps:
- Create PR from branch in same repository
- Verify no approval workflow triggered
- Verify all tests run immediately
- Verify regular test workflows handle the PR
π‘οΈ Security Controls Summary
Control | Implementation | Status |
---|---|---|
Permission Validation | GitHub API getCollaboratorPermissionLevel | β Implemented |
External PR Detection | Repository comparison logic | β Implemented |
Approval Keywords | Pattern matching with validation | β Implemented |
Audit Trail | Approval comments with timestamps | β Implemented |
Label Management | Automatic label application | β Implemented |
Clear Instructions | Enhanced comment formatting | β Implemented |
Error Handling | Permission denied messages | β Implemented |
Secret Protection | Environment-based access control | β Implemented |
π Manual Testing Guide
For Repository Maintainers
-
Test External PR Flow:
# 1. Have external contributor create PR from fork # 2. Verify security comment appears # 3. Comment "/approve" on the PR # 4. Verify full test suite runs
-
Test Permission Boundaries:
# 1. Ask read-only user to comment "/approve" # 2. Verify permission denied message # 3. Verify no tests run with secrets
-
Test Different Approval Methods:
# Test various approval commands: # - "/approve" # - "/approve-testing" # - "approved for testing" # - Manual label addition
For External Contributors
-
Understand the Process:
- Open PR from fork
- Read security comment explanation
- Wait for maintainer approval
- See basic tests run immediately
- Understand which tests need approval
-
Verify Basic Tests Run:
- Unit tests should run without approval
- Linting should run without approval
- Docker build should run without approval
- Integration tests should wait for approval
π Monitoring and Alerts
Key Metrics to Monitor
- Approval Rate: How many external PRs get approved
- Time to Approval: How long maintainers take to approve
- Permission Errors: Failed approval attempts
- Test Coverage: Success rate of approved PRs
Audit Points
- All approval actions logged in PR comments
- GitHub audit log captures label changes
- Workflow run history shows test execution
- Permission checks logged in workflow outputs
π¨ Security Incident Response
If Unauthorized Approval Detected
-
Immediate Actions:
- Remove
approved-for-testing
label - Cancel running workflows
- Review PR changes thoroughly
- Remove
-
Investigation:
- Check workflow logs for permission validation
- Verify user permissions in GitHub
- Review audit log for suspicious activity
-
Prevention:
- Review and update permission requirements
- Consider additional approval requirements
- Update security documentation
If Secrets Potentially Exposed
-
Immediate Actions:
- Rotate affected secrets immediately
- Cancel all running workflows
- Review logs for secret exposure
-
Assessment:
- Determine scope of potential exposure
- Check if secrets were logged or transmitted
- Evaluate impact on systems
-
Recovery:
- Update all affected secrets
- Notify relevant stakeholders
- Document incident and lessons learned
β Verification Status
Last Verified: $(date -u β+%Y-%m-%d %H:%M:%S UTCβ) Verification Method: Code review and system design analysis Next Review: Recommended after any changes to approval workflow
Overall Security Rating: β SECURE
The external PR approval system implements proper security controls and follows GitHub security best practices for protecting repository secrets while maintaining contributor accessibility.