프로젝트

일반

사용자정보

Actions

이슈 #434

진행중
JL HP

[Go backport] Supabase GoTrue 인증 전환 — Phase 1: 인프라 + 인증 코어

이슈 #434: [Go backport] Supabase GoTrue 인증 전환 — Phase 1: 인프라 + 인증 코어

James Lee이(가) 약 7시간 전에 추가함.

상태:
해결
우선순위:
높음
담당자:
목표버전:
시작일:
2026/05/11
완료일:
진척도:

0%

추정시간:

설명

배경

Rust 포팅(alphea-ai-edge)에서 진행된 Supabase GoTrue 인증 전환(#411, #421, #424) 과 관련 부속 작업(#375, #390, #256)을 원본 Go 프로젝트(alphea-rpc-next, branch next)로 백포트한다. 현재 프로젝트는 Rust 포팅을 중단하고 다시 Go 원본에서 예정 항목들을 진행하는 방향으로 복귀했다.

Phase 분할

본 이슈는 Phase 1 — 인프라 + 인증 코어 에 한정한다. 후속 phase 는 별도 이슈로 분리한다.

Phase 범위 이슈
1 (본 이슈) GoTrue 인프라 + 표준 JWT + AuthContext user_id + 스키마 user_id 전환 + AuthService 축소 + Node/User/Wallet 핸들러 caller 전환 본 이슈
2 AGX 회계 user_id 종속 전환 + wallet_adjustments ledger 후속 (#421 백포트)
3 Admin Dev Console GoTrue Sign Up/Log In proxy + UI 후속 (#424 백포트)

Phase 1 작업 범위

인프라

  • alphea-rpc/docker-compose.yml 에 gotrue 서비스 추가 (supabase/gotrue:v2.158.1, port 9011)
  • Postgres init 스크립트 추가 (db/init/01-gotrue-schema.sql):
    • CREATE EXTENSION pgcrypto, uuid-ossp
    • CREATE SCHEMA auth, GRANT ALL ON SCHEMA auth TO alphea
    • Supabase 표준 role 5개(postgres, anon, authenticated, service_role, supabase_auth_admin) NOLOGIN 으로 생성 + alphea 에 멤버십 부여 (PG16+ grantor 요구사항)
  • .env.example 정리: GOTRUE_URL, GOTRUE_INTERNAL_URL, GOTRUE_MAILER_AUTOCONFIRM, SITE_URL 추가. AUTH_SALT/PASSWORD_SALT 제거.

JWT 검증

  • 비표준 SHA256(sigInput + secret) 방식을 표준 HMAC-SHA256 으로 교체 (github.com/golang-jwt/jwt/v5)
  • GoTrue 발행 토큰 호환: typ claim 없음 → token_type = "user"
  • Node 토큰: typ = "node", sub = node_id 유지
  • JWT_SECRET 은 GoTrue 의 GOTRUE_JWT_SECRET 과 동일값 사용

AuthContext / 인터셉터

  • internal/server/interceptors.go 의 AuthContext 에 UserID (UUID), Email, TokenType 추가
  • WalletFromContext → UserIDFromContext, NodeIDFromContext 헬퍼 추가
  • Public path allow-list 정리: 제거된 Auth RPC 제외, GoTrue proxy 경로 미포함(Phase 3)

DB 스키마 (v12 마이그레이션, clean rewrite)

  • accounts: user_id UUID UNIQUE 컬럼 추가, email, display_name, profile_icon, last_active_at 유지. wallet_address/password/account_type/referral_code 는 deprecated 표시 (Phase 1 에서는 제거하지 않고 NOT NULL 제약 완화)
  • wallets: 기존 (account_id, balance) 구조 폐기. 신규 (user_id UUID, wallet_address TEXT) 1:N. UNIQUE(user_id, wallet_address). 기존 데이터 DROP.
  • nodes: owner_user_id UUID 컬럼 추가, owner_wallet_address 는 호환 위해 유지하되 더 이상 권한 판단에 사용 안 함
  • 기존 wallet 식별 기반 dev 데이터 DROP 허용 (clean rewrite)

AuthService 축소 (proto)

  • auth.proto 에서 다음 RPC 완전 제거:
    • Challenge, Verify, SetPassword, Login, EmailRegister, EmailRecover
  • 유지: GenerateKeypair
  • 관련 메시지 타입 제거 (ChallengeRequest/Response, VerifyRequest, LoginRequest, EmailRecoveryRequest/Response, SetPasswordRequest/Response)
  • handler/auth.go 단순화
  • internal/domain/auth/challenge.go 는 노드 등록 챌린지 용도로 유지 (NodeService.NodeChallenge 만 사용)

NodeService

  • NodeChallenge: owner_wallet_address 요청 필드 제거(또는 무시)
  • RegisterNode: user JWT 필수, owner_user_id = JWT sub UUID 로 저장
  • Heartbeat / DeleteNode: owner_user_id 기준 소유권 검증
  • ConnectNode: node 토큰 검증 흐름 유지. token 의 sub 는 node_id (또는 owner user_id) 와 노드 헤더 일치 확인

UserService

  • GetUser(wallet_address) → wallets 테이블에서 user_id 조회 → accounts 조회. 미존재 시 NOT_FOUND
  • friend_count 계산은 기존 friends 테이블 그대로 사용 (Phase 2 에서 user_id 기반 재설계)

WalletService

  • 모든 RPC: caller user_id 로 본인 소유 wallets 확인. 요청의 wallet_address 가 caller 의 wallets 에 속하지 않으면 PermissionDenied
  • 잔액/수익 계산 로직 자체는 Phase 2 에서 처리. Phase 1 에서는 인증 흐름만 전환하고 기존 wallet_address 기반 receipts 합산 유지.

마이그레이션 전략

  • Clean rewrite — Rust 측과 동일. dev/qa DB 는 reset 필요. scripts/ec2/reset-db.sh 와 호환.
  • 기존 wallet challenge/verify 로 만들어진 accounts/wallets/nodes dev 데이터는 마이그레이션 시 DROP.
  • 운영(prod) 에는 본 phase 미적용 (브랜치는 next 한정).

DoD

  • GoTrue 가 docker compose up 으로 정상 기동(Listening on :9011, autoconfirm=true)
  • Postgres init script 가 pgcrypto/uuid-ossp/auth schema + supabase role 5종 생성
  • GoTrue 발행 access_token 으로 Authorization: Bearer <jwt> 헤더 보내면 WalletService/GetReceipts 등 보호 RPC 통과
  • AuthContext.UserID 가 GoTrue sub (UUID) 와 일치
  • NodeService.RegisterNode 가 user JWT 없으면 거부
  • NodeService.Heartbeat/DeleteNode 가 다른 사용자 노드 조작 시 PermissionDenied
  • UserService.GetUser(wallet) 가 wallets join 으로 정상 조회
  • make build, make test 통과
  • auth.proto 에서 제거된 RPC 들에 대한 클라이언트 호환성은 본 phase 에서 보장하지 않음 — 클라이언트 마이그레이션은 모바일 SDK 측에서 별도 처리

관련 이슈

  • Rust 측 원본: #411(GoTrue 인증), #421(AGX 회계 — Phase 2), #424(Admin UI — Phase 3), #375(전역 JWT 인터셉터 — Go 측에는 이미 존재), #390(UserService.GetUser), #256(JWT 인증 API)
  • DB: #254 (스키마 변경 — refs 라인에 동반)

연결된 일감 8 (8 건 진행 중 — 모두 미완료)

다음 일감과 관련됨: 이슈 #411: Supabase GoTrue 인증 전환 — wallet-based auth 제거 및 GoTrue JWT 통합해결James Lee2026/04/24

Actions
다음 일감과 관련됨: 이슈 #421: AGX 잔액을 Wallet 종속 → Account(GoTrue user_id) 종속으로 전환해결James Lee2026/04/27

Actions
다음 일감과 관련됨: 이슈 #424: Dev Console 에 GoTrue Sign Up / Log In 통합 — 테스트 환경 간소화해결James Lee2026/04/27

Actions
다음 일감과 관련됨: 업무 #390: Port UserService.GetUser to alphea-ai-edge해결James Lee2026/04/20

Actions
다음 일감과 관련됨: 이슈 #375: JWT 전역 인터셉터 구현 (alphea-ai-edge)해결James Lee2026/04/15

Actions
다음 일감과 관련됨: 이슈 #256: 8-4. 사용자 인증 API (JWT)해결James Lee2026/04/282026/04/30

Actions
다음 일감과 관련됨: 이슈 #254: 8-2. 데이터베이스 스키마 설계 (사용자. 앱. 일정)진행James Lee2026/04/282026/04/29

Actions
다음에 진행할 일감: 이슈 #435: [Go backport] AGX 회계 user_id 종속 전환 — Phase 2해결Henry Park2026/05/122026/05/12

Actions
Actions

내보내기 PDF Atom