docs: Rate Limiting 구현 방법 문서화
- /api/chat 엔드포인트 Rate Limiting 미구현 이슈 문서화 - 분당 20회 제한 정책 결정 - main.py 4줄 수정으로 구현 가능 - rate_limiter.py 신규 파일 생성 필요 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
52f786fbdb
commit
1d4673f5ee
97
troubleshooting/250915_rate_limiting_미구현.md
Normal file
97
troubleshooting/250915_rate_limiting_미구현.md
Normal file
@ -0,0 +1,97 @@
|
||||
# Rate Limiting 미구현
|
||||
|
||||
## 작성일: 2025-09-15
|
||||
## 작성자: 51123 서버 관리자
|
||||
## 상태: 🟡 미해결
|
||||
|
||||
---
|
||||
|
||||
## 1. 현재 상태
|
||||
|
||||
### 확인된 사실
|
||||
- **Rate Limiting 없음**: Gateway `/api/chat` 엔드포인트 무제한 호출 가능
|
||||
- **사용 모델**: GPT-4 (`/home/admin/ivada_project/rb8001/app/core/config.py` Line 31)
|
||||
- **API 호출**: `openai_handler.py` Line 16에서 OpenAI API 클라이언트 초기화
|
||||
|
||||
### 확인된 플로우
|
||||
```
|
||||
Frontend → Gateway(51123:8100) → rb8001(51124:8001) → OpenAI API
|
||||
```
|
||||
- Gateway `main.py` Line 169-244: `/api/chat` 프록시
|
||||
- Gateway Line 172: JWT 검증만 있음, Rate Limiting 없음
|
||||
|
||||
---
|
||||
|
||||
## 2. 보안 이슈
|
||||
|
||||
### Rate Limiting 필요성
|
||||
- 무제한 API 호출로 인한 서비스 부하 가능
|
||||
- DDoS 공격 취약점 존재
|
||||
- 사용자별 요청 제한 없음
|
||||
|
||||
---
|
||||
|
||||
## 3. 관련 파일
|
||||
|
||||
| 파일 | 위치 | 역할 |
|
||||
|------|------|------|
|
||||
| openai_handler.py | 51124:/home/admin/ivada_project/rb8001/app/llm/ | OpenAI API 호출 |
|
||||
| main.py | 51123:/home/admin/robeing-gateway/app/ | 프록시, Rate Limiting 구현 위치 |
|
||||
| config.py | 51124:/home/admin/ivada_project/rb8001/app/core/ | GPT-4 모델 설정 |
|
||||
|
||||
---
|
||||
|
||||
## 4. 사용 가능한 인프라
|
||||
|
||||
- **Redis 실행 중**: `auth-redis` 컨테이너 (docker ps 확인)
|
||||
- **포트**: 6379/tcp
|
||||
|
||||
---
|
||||
|
||||
## 5. 해결 방법
|
||||
|
||||
### 수정 필요 파일
|
||||
1. **requirements.txt**
|
||||
- 위치: `/home/admin/robeing-gateway/requirements.txt`
|
||||
- 추가 필요 패키지:
|
||||
- redis (버전 확인 필요)
|
||||
- slowapi (버전 확인 필요)
|
||||
|
||||
2. **main.py**
|
||||
- 위치: `/home/admin/robeing-gateway/app/main.py`
|
||||
- 수정 대상 엔드포인트: `/api/chat` (Line 169)
|
||||
- 현재 상태: JWT 검증만 있음 (Line 172, `get_verified_user` 함수)
|
||||
|
||||
### Rate Limiting 구현 방안
|
||||
- **제한 정책**: 분당 20회 (사용자별)
|
||||
- **구분 기준**: JWT 토큰 (Authorization 헤더)
|
||||
- **Redis 활용**: 기존 auth-redis 컨테이너 사용
|
||||
- **라이브러리**: slowapi (FastAPI용 rate limiter)
|
||||
|
||||
### 구현 방법
|
||||
|
||||
#### 1. 새 파일 생성
|
||||
- **파일명**: `/home/admin/robeing-gateway/app/rate_limiter.py`
|
||||
- **역할**: Rate Limiting 로직 전체 관리
|
||||
- **내용**: Redis 연결, Limiter 초기화, 예외 처리
|
||||
|
||||
#### 2. main.py 수정 (총 4줄 추가)
|
||||
```python
|
||||
# Import 섹션 (Line 14 아래)
|
||||
from app.rate_limiter import limiter, rate_limit_handler # 1줄
|
||||
|
||||
# App 초기화 후 (Line 50-60 사이)
|
||||
app.state.limiter = limiter # 1줄
|
||||
app.add_exception_handler(RateLimitExceeded, rate_limit_handler) # 1줄
|
||||
|
||||
# /api/chat 엔드포인트 (Line 169)
|
||||
@limiter.limit("20 per minute") # 1줄 추가
|
||||
```
|
||||
|
||||
### 미확인 사항
|
||||
- redis, slowapi 정확한 버전 결정 필요
|
||||
- auth-redis 네트워크 연결 방법 확인 필요
|
||||
|
||||
### 배포
|
||||
- Docker 재빌드: `docker compose down && docker compose up -d --build`
|
||||
- 위치: `/home/admin/robeing-gateway/`
|
||||
Loading…
x
Reference in New Issue
Block a user