1
0
Fork 0

fix(release): 릴리즈 스크립트의 평문 자격증명 제거 — .env FORGEJO_TOKEN 사용

- curl/REST 인증을 Basic(아이디:비밀번호 리터럴)에서 토큰 헤더로 전환
- 토큰이 없으면 빌드 전에 즉시 중단
- 결과를 쓰지 않던 git credential fill 프로세스 제거
- .env 를 .gitignore 에 추가
- ReleaseScriptSecretsTests: 스크립트에 자격증명이 다시 들어오지 않도록 고정
This commit is contained in:
Yun Chan 2026-10-06 03:03:31 +09:00
parent 8003ff95ca
commit 4c942cf00b
3 changed files with 66 additions and 11 deletions

3
.gitignore vendored
View file

@ -54,3 +54,6 @@ test_assets/
packages/
tools/*
!tools/*.ps1
# 로컬 비밀 (Forgejo 토큰 등) — 절대 커밋하지 않는다
.env

View file

@ -0,0 +1,47 @@
using System.IO;
using System.Text.RegularExpressions;
using Xunit;
namespace Everything2Everything.Tests;
/// <summary>
/// 릴리즈 스크립트는 저장소에 커밋되므로 자격증명을 담지 않는다.
/// 토큰은 .gitignore 된 .env 의 FORGEJO_TOKEN 으로만 받는다.
/// </summary>
public class ReleaseScriptSecretsTests
{
private static readonly string Root = FindRoot();
private static readonly string Script = Path.Combine(Root, "tools", "Publish-Release.ps1");
private static string FindRoot()
{
var dir = Directory.GetCurrentDirectory();
while (dir != null && !File.Exists(Path.Combine(dir, "Everything2Everything.slnx")))
dir = Directory.GetParent(dir)?.FullName;
return dir ?? throw new DirectoryNotFoundException("솔루션 루트를 찾을 수 없습니다.");
}
[Fact]
public void PublishRelease_MustNotEmbedCredentials()
{
var text = File.ReadAllText(Script);
Assert.DoesNotMatch(@"-u\s+""[^""$]+:[^""]+""", text); // curl -u "user:pass"
Assert.DoesNotMatch(@"GetBytes\(\s*""[^""$]+:[^""]+""\s*\)", text); // Basic 인증 리터럴
Assert.DoesNotMatch(@"https://[^/\s:@]+:[^@\s]+@", text); // URL에 박힌 자격증명
}
[Fact]
public void PublishRelease_MustReadTokenFromEnvironment_AndFailFastWithoutIt()
{
var text = File.ReadAllText(Script);
Assert.Contains("$env:FORGEJO_TOKEN", text);
Assert.Matches(new Regex(@"if\s*\(\s*-not\s+\$env:FORGEJO_TOKEN"), text);
}
[Fact]
public void DotEnv_MustBeGitIgnored()
{
var ignore = File.ReadAllLines(Path.Combine(Root, ".gitignore"));
Assert.Contains(ignore, l => l.Trim() is ".env" or "/.env");
}
}

View file

@ -48,6 +48,13 @@ function Import-EnvFile {
}
Import-EnvFile (Join-Path $RootDir '.env')
# Forgejo 인증은 .gitignore 된 .env 의 FORGEJO_TOKEN 으로만 받는다 (스크립트에 자격증명을 두지 않는다).
# 몇 분짜리 빌드를 돌리기 전에 먼저 확인한다.
if (-not $env:FORGEJO_TOKEN -and -not $DryRun) {
Write-Error "FORGEJO_TOKEN 이 없습니다. 저장소 루트 .env 에 FORGEJO_TOKEN=<액세스 토큰> 을 넣으세요. (Forgejo → 설정 → 애플리케이션 → 액세스 토큰, 권한: write:repository)"
exit 1
}
Write-Host "==========================================================" -ForegroundColor Cyan
Write-Host " Everything2Everything 릴리즈 파이프라인" -ForegroundColor Cyan
Write-Host " 버전: $Version (Tag: $Tag, Manifest: $FourPartVersion)" -ForegroundColor Cyan
@ -217,12 +224,10 @@ if (-not $DryRun) {
# ── Forgejo REST API 릴리즈 등록 ─────────────────────────────────
Write-Host "`n[Gate 5] Forgejo REST API 릴리즈 등록 중..." -ForegroundColor Yellow
# 자격증명 조회
$credProcess = Start-Process git -ArgumentList "credential fill" -NoNewWindow -PassThru -RedirectStandardInput ([IO.Path]::GetTempFileName()) -RedirectStandardOutput ([IO.Path]::GetTempFileName())
# 기본 Windows Credential 사용
$authHeader = @{ "Content-Type" = "application/json" }
$tokenBytes = [Text.Encoding]::ASCII.GetBytes("yunchan:ONVI2v4J#y")
$authHeader["Authorization"] = "Basic " + [Convert]::ToBase64String($tokenBytes)
$authHeader = @{
"Content-Type" = "application/json"
"Authorization" = "token $env:FORGEJO_TOKEN"
}
$releaseBody = @{
tag_name = $Tag
@ -260,31 +265,31 @@ $ReleaseNotes
if (Test-Path $innoExe) {
Write-Host " - Inno Setup 표준 설치 파일(Setup-x64.exe) 업로드 중..." -ForegroundColor Gray
curl.exe -s -u "yunchan:ONVI2v4J#y" -X POST "$uploadUrl`?name=Everything2Everything-$Version-Setup-x64.exe" -F "attachment=@$innoExe" | Out-Null
curl.exe -s -H "Authorization: token $env:FORGEJO_TOKEN" -X POST "$uploadUrl`?name=Everything2Everything-$Version-Setup-x64.exe" -F "attachment=@$innoExe" | Out-Null
Write-Host " -> Inno Setup 설치 파일 업로드 완료!" -ForegroundColor Gray
}
if (Test-Path $portableZip) {
Write-Host " - Portable ZIP 업로드 중..." -ForegroundColor Gray
curl.exe -s -u "yunchan:ONVI2v4J#y" -X POST "$uploadUrl`?name=Everything2Everything-$Version-win-x64-portable.zip" -F "attachment=@$portableZip" | Out-Null
curl.exe -s -H "Authorization: token $env:FORGEJO_TOKEN" -X POST "$uploadUrl`?name=Everything2Everything-$Version-win-x64-portable.zip" -F "attachment=@$portableZip" | Out-Null
Write-Host " -> Portable ZIP 업로드 완료!" -ForegroundColor Gray
}
if (Test-Path $msixFile) {
Write-Host " - MSIX 패키지 업로드 중..." -ForegroundColor Gray
curl.exe -s -u "yunchan:ONVI2v4J#y" -X POST "$uploadUrl`?name=Everything2Everything-x64.msix" -F "attachment=@$msixFile" | Out-Null
curl.exe -s -H "Authorization: token $env:FORGEJO_TOKEN" -X POST "$uploadUrl`?name=Everything2Everything-x64.msix" -F "attachment=@$msixFile" | Out-Null
Write-Host " -> MSIX 업로드 완료!" -ForegroundColor Gray
}
if (Test-Path $setupZip) {
Write-Host " - 1-클릭 설치 번들 ZIP 업로드 중..." -ForegroundColor Gray
curl.exe -s -u "yunchan:ONVI2v4J#y" -X POST "$uploadUrl`?name=Everything2Everything-$Version-Setup.zip" -F "attachment=@$setupZip" | Out-Null
curl.exe -s -H "Authorization: token $env:FORGEJO_TOKEN" -X POST "$uploadUrl`?name=Everything2Everything-$Version-Setup.zip" -F "attachment=@$setupZip" | Out-Null
Write-Host " -> 1-클릭 설치 번들 ZIP 업로드 완료!" -ForegroundColor Gray
}
if (Test-Path $cerFile) {
Write-Host " - 공개 개발자 인증서(.cer) 업로드 중..." -ForegroundColor Gray
curl.exe -s -u "yunchan:ONVI2v4J#y" -X POST "$uploadUrl`?name=Everything2Everything-DevCert.cer" -F "attachment=@$cerFile" | Out-Null
curl.exe -s -H "Authorization: token $env:FORGEJO_TOKEN" -X POST "$uploadUrl`?name=Everything2Everything-DevCert.cer" -F "attachment=@$cerFile" | Out-Null
Write-Host " -> 공개 개발자 인증서 업로드 완료!" -ForegroundColor Gray
}
} catch {