docs: Slack 멀티 워크스페이스 해결 방안 확정 - Gateway 경유 방식
This commit is contained in:
parent
53fecf100a
commit
3e28ef2cab
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
## 작성일: 2025-09-03
|
## 작성일: 2025-09-03
|
||||||
## 작성자: 51123 서버 관리자
|
## 작성자: 51123 서버 관리자
|
||||||
## 상태: 🔴 해결 필요
|
## 상태: 🟡 해결 방안 확정 (구현 대기)
|
||||||
## 영향: Company-X 워크스페이스 응답 실패
|
## 영향: Company-X, GoodGang Labs 워크스페이스 응답 실패
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -13,10 +13,11 @@
|
|||||||
- **에러**: `channel_not_found` - 잘못된 토큰으로 채널 접근
|
- **에러**: `channel_not_found` - 잘못된 토큰으로 채널 접근
|
||||||
|
|
||||||
## 2. 토큰 현황 (2025-09-03 DB 확인)
|
## 2. 토큰 현황 (2025-09-03 DB 확인)
|
||||||
- **디지털비잉_로빙**: xoxb-9073915808149-... (환경변수 SLACK_BOT_TOKEN)
|
- **Robeing (T0925SXPS4D)**: xoxb-9073915808149-9107868204992-... (DB 등록)
|
||||||
- **Company-X**: xoxb-9253435471507-... (slack_workspaces.bot_token)
|
- **Company-X (T097FCTDVEX)**: xoxb-9253435471507-... (DB 등록)
|
||||||
- **GoodGang Labs**: xoxb-3199535658754-... (slack_workspaces.bot_token)
|
- **GoodGang Labs (T035VFRKCN6)**: xoxb-3199535658754-... (DB 등록)
|
||||||
- **문제**: 환경변수 토큰만 사용, DB 토큰 미조회
|
- **문제**: rb8001이 환경변수 토큰만 사용, DB 토큰 미조회
|
||||||
|
- **DB 구조**: 모든 팀이 container_port 8001 (rb8001 공유)
|
||||||
|
|
||||||
## 3. 상세 분석
|
## 3. 상세 분석
|
||||||
|
|
||||||
@ -35,25 +36,52 @@ ERROR: Failed to send final response: The request to the Slack API failed.
|
|||||||
The server responded with: {'ok': False, 'error': 'channel_not_found'}
|
The server responded with: {'ok': False, 'error': 'channel_not_found'}
|
||||||
```
|
```
|
||||||
|
|
||||||
## 4. 해결 방안
|
## 4. 해결 방안 (2025-09-03 확정)
|
||||||
|
|
||||||
### 4.1 단기 해결
|
### 4.1 Gateway 경유 방식 채택
|
||||||
- team_id 기반 토큰 동적 선택 로직 구현
|
- Slack Event URL을 Gateway(8100)로 변경
|
||||||
- slack_workspaces 테이블에서 bot_token 조회
|
- Gateway에서 team_id별 토큰 조회 및 주입
|
||||||
|
- rb8001은 헤더에서 토큰 읽어 사용
|
||||||
|
|
||||||
### 4.2 장기 해결
|
### 4.2 구현 상세
|
||||||
- auth-server의 중앙 라우터 활용
|
1. **nginx 설정**: `/api/*` → Gateway(8100) 프록시
|
||||||
- `/slack/events/router`가 team_id별 컨테이너 라우팅
|
2. **Slack App**: Event URL을 `https://ro-being.com/api/slack/events`로 변경
|
||||||
- 각 컨테이너는 해당 워크스페이스 토큰만 보유
|
3. **Gateway**: team_id로 DB 조회, 헤더에 토큰 추가
|
||||||
|
4. **rb8001**: 헤더 우선, 환경변수 폴백
|
||||||
|
|
||||||
## 5. 구현 필요 코드 (로컬 개발자)
|
## 5. 구현 필요 코드 (로컬 개발자)
|
||||||
|
|
||||||
|
### 5.1 Gateway 추가 (robeing-gateway)
|
||||||
```python
|
```python
|
||||||
# rb8001에서 team_id로 토큰 조회
|
@app.post("/api/slack/events")
|
||||||
async def get_bot_token(team_id: str):
|
async def handle_slack_event(request: Request):
|
||||||
# slack_workspaces 테이블에서 토큰 조회
|
# Slack 서명 검증
|
||||||
|
verify_slack_signature(request)
|
||||||
|
|
||||||
|
# team_id별 토큰 조회
|
||||||
|
body = await request.json()
|
||||||
|
team_id = body.get("team_id")
|
||||||
|
|
||||||
result = await db.fetch_one(
|
result = await db.fetch_one(
|
||||||
"SELECT bot_token FROM slack_workspaces WHERE team_id = :team_id",
|
"SELECT bot_token FROM slack_workspaces WHERE team_id = :team_id",
|
||||||
{"team_id": team_id}
|
{"team_id": team_id}
|
||||||
)
|
)
|
||||||
return result["bot_token"] if result else None
|
|
||||||
|
# rb8001로 전달
|
||||||
|
headers = {
|
||||||
|
"X-Slack-Bot-Token": result["bot_token"] if result else None,
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
return await forward_to_rb8001("/api/slack/events", body, headers)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.2 rb8001 수정 (slack_handler.py)
|
||||||
|
```python
|
||||||
|
# 기존: 환경변수만 사용
|
||||||
|
slack_token = os.environ.get("SLACK_BOT_TOKEN")
|
||||||
|
|
||||||
|
# 수정: 헤더 우선, 환경변수 폴백
|
||||||
|
slack_token = request.headers.get("X-Slack-Bot-Token") \
|
||||||
|
or os.environ.get("SLACK_BOT_TOKEN")
|
||||||
```
|
```
|
||||||
Loading…
x
Reference in New Issue
Block a user