# Milestone 4: Governance & Access Control > **Status:** Completed > **Started:** 2025-12-21 > **Completed:** 2025-12-21 ## Overview Milestone 4 implements governance features that enable secure, multi-user collaboration with proper access control. This includes repository permissions, organizations with teams, and a webhook system for CI/CD integration. ## Goals 1. **Repository Permissions**: Granular access control (Read, Write, Admin) 2. **Organizations**: Multi-user repository ownership with teams 3. **Teams**: Group users for easier permission management 4. **Branch Protection**: Protect branches from direct pushes 5. **Webhooks**: Event notifications for external integrations ### New Crate: `guts-auth` ### Data Models #### Permission Levels #### Organization #### Team #### Collaborator #### Branch Protection #### Webhook ### API Endpoints #### Organizations | Method | Endpoint | Description | |--------|----------|-------------| | GET | `/api/orgs` | List organizations | | POST | `/api/orgs` | Create organization | | GET | `/api/orgs/{org}` | Get organization | | PATCH | `/api/orgs/{org}` | Update organization | | DELETE | `/api/orgs/{org}` | Delete organization | | GET | `/api/orgs/{org}/members` | List members | | PUT | `/api/orgs/{org}/members/{user}` | Add/update member | | DELETE | `/api/orgs/{org}/members/{user}` | Remove member | #### Teams | Method | Endpoint | Description | |--------|----------|-------------| | GET | `/api/orgs/{org}/teams` | List teams | | POST | `/api/orgs/{org}/teams` | Create team | | GET | `/api/orgs/{org}/teams/{team}` | Get team | | PATCH | `/api/orgs/{org}/teams/{team}` | Update team | | DELETE | `/api/orgs/{org}/teams/{team}` | Delete team | | GET | `/api/orgs/{org}/teams/{team}/members` | List team members | | PUT | `/api/orgs/{org}/teams/{team}/members/{user}` | Add member | | DELETE | `/api/orgs/{org}/teams/{team}/members/{user}` | Remove member | | GET | `/api/orgs/{org}/teams/{team}/repos` | List team repos | | PUT | `/api/orgs/{org}/teams/{team}/repos/{repo}` | Add repo to team | | DELETE | `/api/orgs/{org}/teams/{team}/repos/{repo}` | Remove repo from team | #### Collaborators | Method | Endpoint | Description | |--------|----------|-------------| | GET | `/api/repos/{owner}/{repo}/collaborators` | List collaborators | | PUT | `/api/repos/{owner}/{repo}/collaborators/{user}` | Add collaborator | | DELETE | `/api/repos/{owner}/{repo}/collaborators/{user}` | Remove collaborator | | GET | `/api/repos/{owner}/{repo}/collaborators/{user}/permission` | Check permission | #### Branch Protection | Method | Endpoint | Description | |--------|----------|-------------| | GET | `/api/repos/{owner}/{repo}/branches/{branch}/protection` | Get protection | | PUT | `/api/repos/{owner}/{repo}/branches/{branch}/protection` | Set protection | | DELETE | `/api/repos/{owner}/{repo}/branches/{branch}/protection` | Remove protection | #### Webhooks | Method | Endpoint | Description | |--------|----------|-------------| | GET | `/api/repos/{owner}/{repo}/hooks` | List webhooks | | POST | `/api/repos/{owner}/{repo}/hooks` | Create webhook | | GET | `/api/repos/{owner}/{repo}/hooks/{id}` | Get webhook | | PATCH | `/api/repos/{owner}/{repo}/hooks/{id}` | Update webhook | | DELETE | `/api/repos/{owner}/{repo}/hooks/{id}` | Delete webhook | | POST | `/api/repos/{owner}/{repo}/hooks/{id}/ping` | Ping webhook | ### P2P Message Types New message types for governance data replication: ### CLI Commands ### Phase 1: Core Types (guts-auth crate) 1. Create crate structure 2. Implement `Permission` enum with ordering 3. Implement `Organization` with member management 4. Implement `Team` with repo associations 5. Implement `Collaborator` type 6. Implement `BranchProtection` rules 7. Implement `Webhook` type 8. Create `AuthStore` for in-memory storage 9. Add comprehensive unit tests ### Phase 2: Permission Checking 2. Handle org → team → user permission inheritance 3. Implement branch protection checks 4. Add authorization middleware for API ### Phase 3: API Integration (guts-node) 1. Add `guts-auth` dependency 2. Integrate `AuthStore` into `AppState` 3. Implement organization endpoints 4. Implement team endpoints 5. Implement collaborator endpoints 6. Implement branch protection endpoints 7. Implement webhook endpoints 8. Add authorization checks to existing endpoints 9. Add API integration tests ### Phase 4: P2P Replication (guts-p2p) 1. Add auth message types to P2P protocol 2. Implement auth event broadcasting 3. Implement auth sync protocol 4. Handle concurrent updates 5. Add P2P integration tests ### Phase 5: CLI Commands (guts-cli) 1. Add `org` subcommand 2. Add `team` subcommand 3. Add `collaborator` subcommand 4. Add `protect`/`unprotect` commands 5. Add `webhook` subcommand ### Phase 6: E2E Testing 1. Create multi-user permission test 2. Test organization workflow 3. Test team permissions inheritance 4. Test branch protection enforcement 5. Test webhook delivery ## Success Criteria - [x] Create and manage organizations via API - [x] Create teams within organizations - [x] Add collaborators with specific permissions - [x] Permission checks on all repository operations - [x] Branch protection rules enforced - [x] Webhooks fire on repository events - [ ] P2P replication of auth data across nodes (future enhancement) - [ ] CLI commands for governance operations (future enhancement) - [x] E2E test passing for permission scenarios ## Dependencies - `guts-types`: Core types (Identity, ObjectId) - `guts-collaboration`: PR/Issue integration - `guts-p2p`: P2P networking layer - `serde`: Serialization - `thiserror`: Error handling ## Security Considerations 1. **Permission Escalation**: Prevent users from granting higher permissions than they have 2. **Org Takeover**: Ensure at least one owner exists 3. **Webhook Security**: HMAC signing of payloads, secret storage 4. **Rate Limiting**: Prevent brute-force permission enumeration 5. **Audit Logging**: Track all permission changes ## Future Considerations These features are out of scope for Milestone 4 but should be considered: 1. **Fine-grained Permissions**: Path-based permissions 2. **Permission Templates**: Predefined permission sets 3. **Audit Trail**: Complete history of permission changes 4. **SSO Integration**: External identity providers 5. **API Keys**: Non-user authentication for CI/CD 6. **2FA Enforcement**: Require 2FA for sensitive operations ## References - [GitHub Organizations API](https://docs.github.com/en/rest/orgs) - [GitHub Branch Protection API](https://docs.github.com/en/rest/branches/branch-protection) - [GitHub Webhooks API](https://docs.github.com/en/rest/webhooks) - [Guts PRD](./PRD.md)