# Security Incident Response Playbooks

## Incident Classification

### P0 - Critical Security Incident
- System compromise confirmed
- Data breach suspected
- Service unavailable due to attack

### P1 - High-Severity Security Event
- Active attack in progress
- Authentication system compromise
- Safety system bypass

### P2 - Medium-Severity Security Event
- Anomalous activity detected
- Policy violations increasing
- Potential threat indicators

### P3 - Low-Severity Security Event
- Routine security events
- Minor policy violations
- Informational alerts

## Response Playbooks

### P0 Playbook: Critical Security Incident

#### Immediate Response (0-5 minutes)
1. **Confirm Incident**
   ```bash
   # Check security dashboard
   curl "$OBSERVABILITY_URL/v1/security/dashboard"
   # Verify system health
   kubectl get pods -n lilith
   ```

2. **Isolate Affected Systems**
   ```bash
   # Scale down affected services
   kubectl scale deployment/auth-service --replicas=0 -n lilith
   # Apply emergency network policies
   kubectl apply -f deploy/kubernetes/security/emergency-isolation.yaml
   ```

#### Containment (5-15 minutes)
3. **Preserve Evidence**
   ```bash
   # Capture logs
   kubectl logs deployment/auth-service -n lilith > incident-logs-$(date +%Y%m%d-%H%M%S).log
   # Capture security events
   curl "$OBSERVABILITY_URL/v1/security/events?timeframe=24h" > security-events.json
   ```

4. **Block Threat Sources**
   ```bash
   # Block malicious IPs
   kubectl patch configmap nginx-config -n lilith --patch '{"data":{"block-ips":"1.2.3.4,5.6.7.8"}}'
   # Update rate limits
   kubectl apply -f deploy/kubernetes/rate-limits/emergency.yaml
   ```

#### Investigation (15-30 minutes)
5. **Root Cause Analysis**
   ```bash
   # Analyze authentication logs
   kubectl logs deployment/auth-service -n lilith --since=1h --grep="auth_failed"
   # Check observability service logs
   kubectl logs deployment/observability -n lilith --since=1h
   ```

6. **Impact Assessment**
   ```bash
   # Check affected user accounts
   curl "$AUTH_SERVICE_URL/v1/users/compromised"
   # Verify data integrity
   kubectl exec deployment/postgres -n lilith -- pg_dump lilith_db > backup-verification.sql
   ```

#### Investigation Phase (30-60 minutes)
7. **Root Cause Analysis**
   ```bash
   # Deep analysis of attack patterns
   kubectl logs deployment/auth-service -n lilith --since=4h --grep="error|failed|suspicious"
   ```

8. **Impact Assessment**
   ```bash
   # Assess data integrity
   kubectl exec deployment/postgres -n lilith -- psql lilith_db -c "SELECT count(*) FROM users;"
   ```

#### Recovery Phase (1-4 hours)
9. **Apply Security Patches**
   ```bash
   # Deploy security updates
   kubectl set image deployment/auth-service auth-service=auth:latest-secure -n lilith
   ```

10. **Restore Services**
    ```bash
    # Restore service replicas
    kubectl scale deployment/auth-service --replicas=3 -n lilith
    ```

11. **Verify Security Posture**
12. **Communication**

### P1 Playbook: High-Severity Event

#### Immediate Response (0-5 minutes)
1. **Threat Assessment**
   ```bash
   # Quick threat analysis
   curl "$OBSERVABILITY_URL/v1/security/dashboard"
   ```

#### Containment (5-15 minutes)
2. **Containment Actions**
   ```bash
   # Isolate affected components
   kubectl patch service auth-service -n lilith -p '{"spec":{"type":"ClusterIP"}}'
   # Apply rate limiting
   kubectl apply -f deploy/kubernetes/rate-limits/strict.yaml
   ```

#### Investigation Phase (15-30 minutes)
3. **Investigation**
   ```bash
   # Investigate security events
   curl "$OBSERVABILITY_URL/v1/security/events?severity=high&timeframe=1h"
   ```

#### Recovery Phase (30-60 minutes)
4. **Remediation**
   ```bash
   # Apply fixes and restore
   kubectl rollout restart deployment/auth-service -n lilith
   ```

### Automation Scripts

#### Emergency Response
```bash
#!/bin/bash
# emergency-response.sh - Automated incident response

INCIDENT_TYPE=$1
SEVERITY=$2

case $INCIDENT_TYPE in
  "auth_compromise")
    kubectl scale deployment/auth-service --replicas=0 -n lilith
    kubectl apply -f security/emergency-auth-isolation.yaml
    ;;
  "ddos_attack")
    # Update WAF rules
    aws wafv2 update-web-acl --scope CLOUDFRONT --id $WAF_ID --default-action Block={}
    ;;
esac
```

## Contact Information

### Security Team
- **Primary**: security-oncall@lilith.platform
- **Secondary**: engineering-lead@lilith.platform
- **Emergency**: +1-555-SECURITY

### External Contacts
- **AWS Support**: Case management portal
- **Legal**: legal@lilith.platform for compliance issues

## Escalation

### P0 Escalation Path
- 0-5 minutes: Immediate containment
- 5-15 minutes: Senior security engineer
- 15-30 minutes: Security team lead
- 30+ minutes: Executive escalation

---
*Generated automatically by security-docs-generator.js*
*Last updated: 2025-09-27T18:05:41.732Z*
