soyailabs / remove_token_from_git_history.ps1
SOY NV AI
Security: Remove all hardcoded Hugging Face tokens from history
4434cfe
raw
history blame
3.28 kB
# Git νžˆμŠ€ν† λ¦¬μ—μ„œ 토큰을 μ™„μ „νžˆ μ œκ±°ν•˜λŠ” 슀크립트
# 이 μŠ€ν¬λ¦½νŠΈλŠ” λ¬Έμ œκ°€ λ˜λŠ” νŒŒμΌλ“€μ„ Git νžˆμŠ€ν† λ¦¬μ—μ„œ μ™„μ „νžˆ μ œκ±°ν•©λ‹ˆλ‹€.
$env:FILTER_BRANCH_SQUELCH_WARNING = "1"
$files = @(
"remove_token_from_history.ps1",
"add_exaone_with_token.py",
"download_exaone_model.py",
"install_exaone_direct.py",
"install_exaone_simple.py"
)
Write-Host "Git νžˆμŠ€ν† λ¦¬μ—μ„œ 토큰이 ν¬ν•¨λœ 파일 제거 쀑..." -ForegroundColor Yellow
Write-Host "주의: 이 μž‘μ—…μ€ Git νžˆμŠ€ν† λ¦¬λ₯Ό λ‹€μ‹œ μž‘μ„±ν•©λ‹ˆλ‹€." -ForegroundColor Red
# 각 νŒŒμΌμ— λŒ€ν•΄ Git νžˆμŠ€ν† λ¦¬μ—μ„œ 제거
foreach ($file in $files) {
Write-Host "`n처리 쀑: $file" -ForegroundColor Cyan
# 파일이 μ‘΄μž¬ν•˜λŠ”μ§€ 확인
if (Test-Path $file) {
# ν˜„μž¬ νŒŒμΌμ—μ„œ 토큰이 μžˆλŠ”μ§€ 확인
$content = Get-Content $file -Raw -Encoding UTF8 -ErrorAction SilentlyContinue
if ($content -and $content -match "YOUR_HUGGINGFACE_TOKEN_HERE") {
Write-Host " ν˜„μž¬ νŒŒμΌμ—μ„œ 토큰 발견, 제거 쀑..." -ForegroundColor Yellow
$content = $content -replace [regex]::Escape("YOUR_HUGGINGFACE_TOKEN_HERE"), "YOUR_HUGGINGFACE_TOKEN_HERE"
Set-Content $file -Value $content -Encoding UTF8 -NoNewline
Write-Host " βœ“ ν˜„μž¬ νŒŒμΌμ—μ„œ 토큰 제거 μ™„λ£Œ" -ForegroundColor Green
}
}
# Git νžˆμŠ€ν† λ¦¬μ—μ„œ 파일 제거 (토큰이 ν¬ν•¨λœ λͺ¨λ“  μ»€λ°‹μ—μ„œ)
Write-Host " Git νžˆμŠ€ν† λ¦¬μ—μ„œ 제거 쀑..." -ForegroundColor Yellow
# git filter-branchλ₯Ό μ‚¬μš©ν•˜μ—¬ νŒŒμΌμ„ νžˆμŠ€ν† λ¦¬μ—μ„œ 제거
$result = git filter-branch --force --index-filter "git rm --cached --ignore-unmatch `"$file`"" --prune-empty --tag-name-filter cat -- --all 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " βœ“ Git νžˆμŠ€ν† λ¦¬μ—μ„œ 제거 μ™„λ£Œ" -ForegroundColor Green
} else {
Write-Host " ⚠ νžˆμŠ€ν† λ¦¬ 처리 μ‹€νŒ¨ λ˜λŠ” 파일이 νžˆμŠ€ν† λ¦¬μ— μ—†μŒ" -ForegroundColor Yellow
}
}
# EXAONE_μΆ”κ°€_μ•ˆλ‚΄.md 파일 처리 (ν•œκΈ€ 파일λͺ…)
Write-Host "`n처리 쀑: EXAONE_μΆ”κ°€_μ•ˆλ‚΄.md" -ForegroundColor Cyan
if (Test-Path "EXAONE_μΆ”κ°€_μ•ˆλ‚΄.md") {
$content = Get-Content "EXAONE_μΆ”κ°€_μ•ˆλ‚΄.md" -Raw -Encoding UTF8 -ErrorAction SilentlyContinue
if ($content -and $content -match "YOUR_HUGGINGFACE_TOKEN_HERE") {
Write-Host " ν˜„μž¬ νŒŒμΌμ—μ„œ 토큰 발견, 제거 쀑..." -ForegroundColor Yellow
$content = $content -replace [regex]::Escape("YOUR_HUGGINGFACE_TOKEN_HERE"), "YOUR_HUGGINGFACE_TOKEN_HERE"
Set-Content "EXAONE_μΆ”κ°€_μ•ˆλ‚΄.md" -Value $content -Encoding UTF8 -NoNewline
Write-Host " βœ“ ν˜„μž¬ νŒŒμΌμ—μ„œ 토큰 제거 μ™„λ£Œ" -ForegroundColor Green
}
}
# Git νžˆμŠ€ν† λ¦¬ 정리
Write-Host "`nGit νžˆμŠ€ν† λ¦¬ 정리 쀑..." -ForegroundColor Yellow
git reflog expire --expire=now --all
git gc --prune=now --aggressive
Write-Host "`nμ™„λ£Œ!" -ForegroundColor Green
Write-Host "이제 λ‹€μŒ λͺ…λ Ήμ–΄λ‘œ κ°•μ œ ν‘Έμ‹œν•˜μ„Έμš”:" -ForegroundColor Yellow
Write-Host " git push origin master --force" -ForegroundColor Cyan
Write-Host " git push space master:main --force" -ForegroundColor Cyan