Files
was-cf/DEPLOYMENT_GUIDE.md
kappa d5440630f5 Update documentation with current infrastructure state
- Update all resource IDs to match current deployment
- CloudFront Distribution: EATJ1HDQU8V51
- WAF Web ACL: d61073b6-27b1-473e-aa9f-d2aa4a4c75a6
- WAF IP Set: a9e47946-c186-4b28-83a8-fe3aeb9c296b
- ACM Certificate: b011e60a-1ea1-4dd3-844f-e0851ece4784
- Route53 Zone: Z01934581JQAF2GS71GG
- Reflect enabled ACM certificate and Route53 DNS management
- Update all AWS CLI commands with correct resource IDs

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 15:32:35 +09:00

285 lines
6.8 KiB
Markdown

# AWS CloudFront + CrowdSec 배포 가이드
## 📋 완전 배포 가이드
AWS CloudFront CDN과 CrowdSec 실시간 보안 통합 시스템의 단계별 배포 가이드입니다.
## 🎯 배포 목표
- CloudFront CDN 구성 (`origin.servidor.it.com`)
- CrowdSec 컨테이너 보안 시스템
- Lambda 기반 실시간 WAF 통합
- Nginx Proxy Manager 로그 분석
## ⚠️ 중요 제약사항
- **Origin Protocol**: HTTP-only (HTTPS 사용 시 504 에러)
- **DynamoDB Locking**: 권한 제한으로 비활성화
## ✅ 현재 활성화된 기능
- **ACM Certificate**: 활성화됨 (b011e60a-1ea1-4dd3-844f-e0851ece4784)
- **Route53 Records**: 활성화됨 (Z01934581JQAF2GS71GG)
- **WAF Protection**: 활성화됨 (d61073b6-27b1-473e-aa9f-d2aa4a4c75a6)
## 🚀 1단계: 인프라 배포
### 사전 요구사항
- AWS CLI 설정 완료
- OpenTofu 설치 (`brew install opentofu`)
- Incus 설치 및 설정
### 인프라 배포
```bash
# 프로젝트 디렉토리로 이동
cd /Users/kaffa/Projects/was-cf
# OpenTofu 초기화
tofu init
# 계획 확인
tofu plan
# 인프라 배포
tofu apply -auto-approve
```
### 배포 결과 확인
```bash
# 출력값 확인
tofu output
# CloudFront 상태 확인
aws cloudfront get-distribution --id EATJ1HDQU8V51 --query 'Distribution.Status'
# WAF 규칙 확인
aws wafv2 get-web-acl --scope CLOUDFRONT --id d61073b6-27b1-473e-aa9f-d2aa4a4c75a6 --region us-east-1
```
## 🔒 2단계: CrowdSec 컨테이너 설정
### 컨테이너 생성
```bash
# 새 Ubuntu 컨테이너 생성
incus launch ubuntu:24.04 crowdsec
incus exec crowdsec -- apt update
```
### CrowdSec 설치
```bash
# CrowdSec 설치
incus exec crowdsec -- curl -s https://install.crowdsec.net | sh
# 서비스 상태 확인
incus exec crowdsec -- systemctl status crowdsec
```
### 보안 컬렉션 설치
```bash
# Nginx Proxy Manager 컬렉션 설치
incus exec crowdsec -- cscli collections install crowdsecurity/nginx-proxy-manager
# 설치된 컬렉션 확인
incus exec crowdsec -- cscli collections list
# 설정 적용
incus exec crowdsec -- systemctl reload crowdsec
```
## 🔗 3단계: 웹훅 통합 설정
### 알림 설정 파일 생성
```bash
incus exec crowdsec -- tee /etc/crowdsec/notifications/aws-waf.yaml << 'EOF'
type: http
name: aws-waf
log_level: info
url: https://8zdmpjfnhh.execute-api.us-east-1.amazonaws.com/dev/webhook
method: POST
headers:
Content-Type: application/json
User-Agent: CrowdSec/1.7.0
timeout: 10s
format: |
{{ .|toJson }}
EOF
```
### 프로필 설정
```bash
incus exec crowdsec -- tee /etc/crowdsec/profiles.yaml << 'EOF'
name: aws_waf_profile
filters:
- Alert.Remediation == true && Alert.GetScenario() startsWith "crowdsecurity/"
notifications:
- aws-waf
on_success: break
EOF
```
### CrowdSec 재시작
```bash
incus exec crowdsec -- systemctl restart crowdsec
```
## 🧪 4단계: 통합 테스트
### 웹훅 엔드포인트 테스트
```bash
curl -X POST https://8zdmpjfnhh.execute-api.us-east-1.amazonaws.com/dev/webhook \
-H "Content-Type: application/json" \
-H "User-Agent: CrowdSec/1.7.0" \
-d '[{
"uuid": "test-123",
"decisions": [{
"value": "192.168.1.100",
"type": "ban",
"action": "add"
}]
}]'
```
**예상 응답:**
```json
{
"success": true,
"message": "WAF IP Set updated successfully",
"ips_added": ["192.168.1.100"],
"ips_removed": [],
"total_ips": 1
}
```
### WAF IP Set 확인
```bash
aws wafv2 get-ip-set --scope CLOUDFRONT --region us-east-1 \
--id a9e47946-c186-4b28-83a8-fe3aeb9c296b \
--name aws-cf-dev-blocked-ips \
--query 'IPSet.Addresses'
```
### IP 제거 테스트
```bash
curl -X POST https://8zdmpjfnhh.execute-api.us-east-1.amazonaws.com/dev/webhook \
-H "Content-Type: application/json" \
-H "User-Agent: CrowdSec/1.7.0" \
-d '[{
"uuid": "test-456",
"decisions": [{
"value": "192.168.1.100",
"type": "ban",
"action": "delete"
}]
}]'
```
### CrowdSec 알림 테스트
```bash
incus exec crowdsec -- cscli notifications test aws-waf
```
## 📊 5단계: 모니터링 설정
### Lambda 함수 로그 모니터링
```bash
# 실시간 로그 확인
aws logs tail /aws/lambda/aws-cf-dev-crowdsec-waf-updater --follow
# 특정 시간대 로그
aws logs filter-log-events \
--log-group-name /aws/lambda/aws-cf-dev-crowdsec-waf-updater \
--start-time $(date -d '1 hour ago' +%s)000
```
### CrowdSec 상태 모니터링
```bash
# 메트릭 확인
incus exec crowdsec -- cscli metrics
# 현재 차단 결정
incus exec crowdsec -- cscli decisions list
# 허브 상태
incus exec crowdsec -- cscli hub list
```
### WAF 메트릭 확인
```bash
# 차단된 요청 확인
aws cloudwatch get-metric-statistics \
--namespace AWS/WAFV2 \
--metric-name BlockedRequests \
--dimensions Name=WebACL,Value=aws-cf-dev-waf Name=Rule,Value=BlockedIPsRule \
--start-time $(date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%S) \
--end-time $(date -u +%Y-%m-%dT%H:%M:%S) \
--period 300 --statistics Sum
```
## 🔧 문제 해결
### 일반적인 문제들
**1. 웹훅 연결 실패**
```bash
# 네트워크 연결 확인
incus exec crowdsec -- curl -I https://8zdmpjfnhh.execute-api.us-east-1.amazonaws.com/dev/webhook
# CrowdSec 알림 설정 확인
incus exec crowdsec -- cat /etc/crowdsec/notifications/aws-waf.yaml
```
**2. Lambda 함수 오류**
```bash
# Lambda 함수 직접 테스트
aws lambda invoke --function-name aws-cf-dev-crowdsec-waf-updater response.json
# 에러 로그 확인
aws logs describe-log-groups --log-group-name-prefix "/aws/lambda/aws-cf-dev"
```
**3. WAF 업데이트 실패**
```bash
# IAM 권한 확인
aws iam get-role-policy --role-name aws-cf-dev-lambda-waf-role --policy-name aws-cf-dev-lambda-waf-policy
# WAF IP Set 상태 확인
aws wafv2 get-ip-set --scope CLOUDFRONT --region us-east-1 --id a9e47946-c186-4b28-83a8-fe3aeb9c296b --name aws-cf-dev-blocked-ips
```
## 📈 운영 관리
### 정기 유지보수
```bash
# CrowdSec 업데이트
incus exec crowdsec -- cscli hub update
incus exec crowdsec -- cscli hub upgrade
# 컬렉션 상태 확인
incus exec crowdsec -- cscli collections list
# 시스템 리소스 확인
incus info crowdsec
```
### 백업 및 복구
```bash
# CrowdSec 설정 백업
incus exec crowdsec -- tar -czf /tmp/crowdsec-config.tar.gz /etc/crowdsec
# 설정 파일 복사
incus file pull crowdsec/tmp/crowdsec-config.tar.gz ./
# Terraform 상태 백업
aws s3 sync s3://aws-cf-terraform-state-535294143817 ./backup/
```
## 🎯 완료 체크리스트
- [ ] AWS 인프라 배포 완료
- [ ] CrowdSec 컨테이너 설정 완료
- [ ] 웹훅 통합 설정 완료
- [ ] 통합 테스트 성공
- [ ] 모니터링 설정 완료
- [ ] 문서화 완료
---
**배포 완료 시간**: 약 30-45분
**필수 권한**: AWS WAF, Lambda, API Gateway, CloudWatch 접근
**지원**: [CrowdSec Integration Guide](CROWDSEC-WAF-INTEGRATION.md) 참조