260424 — @RONforMAC_Bot token rotation 준비
결론
자동 갱신 스크립트 작성 완료.
- 스크립트:
/Users/ron/.hermes/workspace/scripts/admin/rotate_telegram_token.py - dry-run 검증: PASS
- 기본 dry-run 기준 갱신 대상 파일 수: 39개
- 현재
secrets/*.token대상: 0개 - 실제 토큰 교체는 아직 수행하지 않음
1) 현재 사용처 스캔 요약
스캔 로그:
/tmp/ronformac_token_usage_20260424_151006.txt/tmp/ronformac_targeted_usage_20260424_151109.txt/tmp/rotate_telegram_token_dryrun_refined_20260424_151400.txt
확인 결과:
| 구분 | 결과 |
|---|---|
.hermes/.env Telegram token line |
있음 |
.openclaw/.env Telegram token line |
없음 |
.codex/.env |
없음 |
secrets/*.token 직접 대상 |
0 |
| old bot id hardcode/default 대상 | 39 files |
주요 active 대상:
/Users/ron/.hermes/.env/Users/ron/.hermes/openclaw.json/Users/ron/.openclaw/openclaw.json/Users/ron/.openclaw/cron/jobs.json/Users/ron/.openclaw/scripts/gmail_credit_monitor.py/Users/ron/.openclaw/scripts/ops/x_monitor.py/Users/ron/.openclaw/workspace/scripts/*일부 legacy sender/Users/ron/.openclaw/custom/scripts/pipeline/*일부 legacy pipeline/Users/ron/.openclaw/mcp-servers/telegram/index.js
아카이브/백업/리포트/로그성 파일은 기본 모드에서 제외한다. 필요 시 --include-archives로 별도 처리 가능.
2) 스크립트 기능
python3 ~/.hermes/workspace/scripts/admin/rotate_telegram_token.py --new-token <NEW>
동작:
- 새 토큰 형식 검사
- Telegram
getMe호출로 새 토큰 검증 - 기본적으로
@RONforMAC_Botusername인지 확인 - 모든
TELEGRAM_BOT_TOKEN*env var 갱신 - old bot id
8554125313:로 시작하는 hardcoded token 갱신 secrets/*.token중 대상이 있으면 갱신- 각 수정 파일에
.bak-rotate-YYYYMMDD_HHMMSS백업 생성 - 갱신 후
getMe재검증
토큰 값은 stdout/stderr에 출력하지 않는다. 로그에는 8554125313:<redacted> 형태만 남긴다.
3) 해리 실행 절차 — 5분 버전
A. BotFather에서 새 토큰 발급
- Telegram에서
@BotFather열기 /mybots@RONforMAC_Bot선택API TokenRevoke current token또는/revoke- 새 token 복사
B. dry-run 먼저
가장 안전한 방식은 shell history에 token을 남기지 않는 stdin 방식이다.
pbpaste | python3 ~/.hermes/workspace/scripts/admin/rotate_telegram_token.py --new-token-stdin --dry-run
출력에서 확인할 것:
getMe ok: @RONforMAC_Bot id=...
mode=DRY_RUN
changed_files=39
C. 실제 적용
pbpaste | python3 ~/.hermes/workspace/scripts/admin/rotate_telegram_token.py --new-token-stdin
사용자가 요청한 직접 인자 방식도 가능하지만 shell history/process list에 남을 수 있어 권장하지 않는다.
python3 ~/.hermes/workspace/scripts/admin/rotate_telegram_token.py --new-token '<NEW>'
D. 적용 후 빠른 검증
python3 ~/.hermes/workspace/scripts/admin/rotate_telegram_token.py --new-token-stdin --dry-run
이미 교체된 상태라면 changed_files=0 또는 archive 제외 잔여만 나와야 한다.
4) 옵션
| 옵션 | 용도 |
|---|---|
--new-token <NEW> |
직접 입력. 간단하지만 history/process 노출 가능 |
--new-token-stdin |
stdin으로 입력. 권장 |
--new-token-file <PATH> |
파일에서 입력 |
--dry-run |
실제 수정 없이 대상 확인 |
--skip-verify |
네트워크/getMe 생략. 테스트용 |
--env-policy all-telegram |
기본값. 모든 TELEGRAM_BOT_TOKEN* env를 새 토큰으로 갱신 |
--env-policy old-id-only |
기존 값이 old bot id로 시작하는 env만 갱신 |
--include-archives |
백업/아카이브/리포트성 파일까지 교체 |
5) dry-run 검증 원문 요약
getMe skipped: token=8554125313:<redacted>
mode=DRY_RUN
changed_files=39
대표 대상:
/Users/ron/.hermes/.env
/Users/ron/.openclaw/cron/jobs.json
/Users/ron/.openclaw/openclaw.json
/Users/ron/.openclaw/scripts/gmail_credit_monitor.py
/Users/ron/.openclaw/scripts/ops/x_monitor.py
/Users/ron/.openclaw/mcp-servers/telegram/index.js
/Users/ron/.openclaw/workspace/scripts/telegram_react.py
/Users/ron/.openclaw/workspace/scripts/telegram_outbox_flusher.py
6) 주의
- 이 스크립트는 값을 출력하지 않지만,
--new-token '<NEW>'방식은 shell history에 남을 수 있다. 가능하면pbpaste | ... --new-token-stdin사용. - 실제 적용 후에는 Hermes Gateway/Telegram listener류가 env를 다시 읽도록 재시작이 필요할 수 있다.
- OpenClaw legacy는 아직 하드코딩이 많으므로, 토큰 회전 후 history rewrite와 hardcoding 제거 작업을 별도로 해야 한다.
--include-archives는 백업/아카이브까지 바꾸므로 기본 실행 후 잔여 grep 확인 시에만 사용 권장.
7) 자체평가
- 정확성: 4.5/5 — 사용처 스캔, 스크립트 작성, py_compile, dry-run 검증 완료.
- 완성도: 4.4/5 — 실제 새 토큰은 아직 없어서 적용은 미수행. 실행 절차는 준비됨.
- 검증: 4.5/5 — dry-run으로 39개 대상 산출, 토큰 비출력 확인.
- 최소 변경: 4.6/5 — 신규 admin 스크립트와 보고서만 작성. 실제 토큰/설정 파일은 미수정.
종합: 4.5/5
DONE