Repository navigation
chore(db): spatial_ref_sys 쓰기 가드(09-15 운영 적용분)를 저장소에 기록 — 마이그레이션·t27·outofband - #219
Merged
Merged
Conversation
…outofband 09-15 에 운영에 적용한 가드 트리거(schema_migrations 의 spatial_ref_sys_write_guard)의 마이그레이션 파일과 테스트가 커밋되지 않은 채 로컬에만 있었다. 스냅샷에는 함수만 실려 있고(pg_dump 는 확장 소유 테이블의 트리거를 싣지 않는다) 베이스라인이 그 함수를 흡수해 리플레이는 초록이었지만, 트리거 자체는 아무도 대조하지 않았고 t27 도 CI 에 없었다. docs/supabase-db.md 는 이미 이 마이그레이션과 t27 을 가리키고 있다. - supabase/migrations/20260915100000_spatial_ref_sys_write_guard.sql: 운영 적용본 그대로. - supabase/tests/t27_spatial_ref_sys_guard_test.sql: anon/authenticated 의 INSERT·UPDATE· DELETE 는 42501, 운영 롤은 통과, 4326 행은 그대로 읽힌다(7 단언). - scripts/_schema_dump.sh + outofband.txt: 확장 소유 테이블에 건 트리거를 밖 객체 스냅샷에 포함(+1줄). 리플레이가 이 줄을 대조하므로 트리거가 빠지면 빨간불이 된다. - supabase/schema/baseline.sql: 재생성 — 함수가 마이그레이션 쪽으로 옮겨가 -18줄. - supabase/schema/replay-platform-grants.sql + scripts/replay_check.sh: 작업용 DB 는 새로 만든 DB 라 플랫폼이 확장 테이블에 주는 권한(supabase_admin 의 기본 권한)이 없다. 그대로면 create trigger 가 permission denied 다. prelude 직후 수퍼유저로 같은 권한을 줘서 운영과 같은 출발점을 만든다. - README: 재현 절차 표와 밖 객체 목록 갱신. 검증: 운영 스키마를 다시 덤프해 커밋된 schema.sql 과 바이트 동일함을 확인(드리프트 없음), outofband.txt 차이는 트리거 한 줄뿐. t27 은 운영 DB 와 테스트 서버에서 7/7 (전부 롤백). 리플레이 잡의 수퍼유저 단계는 로컬에 docker 가 없어 CI 에서 확인한다. Co-Authored-By: Claude <noreply@anthropic.com>
리플레이 작업용 DB 와 이미지 기본 DB 에서 확장 테이블의 소유자·ACL 을 찍어, replay-platform-grants.sql 이 실제로 필요한지 실측한다. Co-Authored-By: Claude <noreply@anthropic.com>
직전 커밋의 진단으로 확인한 것(supabase/postgres 17.6.1.121): - 리플레이 작업용 DB: pg_default_acl 0행, spatial_ref_sys ACL 은 소유자 + PUBLIC=r 뿐, postgres 의 create trigger 는 permission denied for table spatial_ref_sys. - 이미지 기본 DB(pgtap 잡): 운영과 같은 ACL — 추가 권한이 필요 없다. Co-Authored-By: Claude <noreply@anthropic.com>
seizeh
added a commit
that referenced
this pull request
Nov 21, 2026
pg_dump 는 REVOKE 를 내보내지 않고, Supabase 프로젝트의 public 스키마에는 "새 객체는 anon·authenticated·service_role 에 ALL" 기본 권한이 걸려 있다. 그래서 스냅샷을 호스팅 프로젝트에 복원하면 운영에서 회수한 권한이 전부 되살아난다. pgTAP 스냅샷 DB 에서 두 번 겪은 것과 같은 원인인데, 테스트 서버는 인터넷에 열려 있다. 2026-11-11 실측: 스냅샷으로 세운 테스트 서버에서 서버 전용 함수가 anon 에게 실행 가능했고 테이블 수준 권한이 컬럼 권한을 덮고 있었다. 그때 손으로 한 대조·정렬을 도구로 남긴다(#219 의 후속). - scripts/align_test_privs.py: 운영(기준, 읽기 전용 트랜잭션)과 테스트(대상)의 카탈로그를 뽑아 양쪽에 모두 있는 객체의 PUBLIC/anon/authenticated/service_role 권한을 대조한다. 함수 EXECUTE · 테이블/뷰/시퀀스(컬럼 권한 포함) · RLS 스위치 · postgres 기본 권한 · spatial_ref_sys 가드 트리거. 기본은 대조만(차이 있으면 exit 1), --apply 는 같은 문장을 트랜잭션 안에서 돌려 anon/authenticated 읽기 결과가 운영과 같을 때만 적용하고 sync.sql·undo.sql 을 남긴다. 방향은 고정이고 기준과 대상이 같은 DB 면 멈춘다. 스키마 차이는 세어서 보여 주기만 한다. - scripts/align_test_privs_selftest.sh + db-tests.yml(replay 잡): 새 프로젝트 기본 권한 위에 스냅샷을 복원해 권한이 풀린 DB 를 만들고(풀렸는지도 단언), 도구로 리플레이 DB 에 맞춘 뒤 차이 0 과 개별 권한(서버 전용 함수·users 컬럼·TRUNCATE·가드·새 함수 기본 권한)을 잰다. - README: "테스트 서버 권한 정렬" 절. 검증: - 로컬 Postgres 17 의 합성 스키마: 대조·적용·undo·리허설 중단(--force)·같은 DB 거부· 가드 트리거 경로. - CI 자체 검증(실제 스키마): 풀린 상태 재현(함수 144·테이블 70·뷰 14·기본 권한 5·가드 1) → 정렬 → 차이 0, 읽기 점검 84건이 기준과 동일. - 실사용: 테스트 서버에 7/28 이후 마이그레이션 49건을 적용한 뒤 이 도구로 대조해 남은 권한 차이 1건(app.blocked_ids 의 PUBLIC EXECUTE)을 맞췄고, 스키마 덤프가 운영 스냅샷과 완전히 일치함을 확인했다. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
무엇을
09-15 에 운영에 적용한
spatial_ref_sys쓰기 가드 트리거의 마이그레이션 파일과 테스트(t27) 가 커밋되지 않은 채 로컬에만 있었다. 운영에는 적용돼 있고docs/supabase-db.md도 이미 이 둘을 가리키는데, 저장소에는 없었다.스냅샷(
schema.sql)에는 함수만 실려 있고(pg_dump는 확장 소유 테이블의 트리거를 싣지 않는다) 베이스라인이 그 함수를 흡수해서 리플레이는 초록이었다. 그래서 트리거 자체는 아무도 대조하지 않았고, 가드를 검사하는 t27 도 CI 에 없었다.변경
supabase/migrations/20260915100000_spatial_ref_sys_write_guard.sqlsupabase/tests/t27_spatial_ref_sys_guard_test.sqlscripts/_schema_dump.sh,supabase/schema/outofband.txtsupabase/schema/baseline.sqlsupabase/schema/replay-platform-grants.sql,scripts/replay_check.shREADME.md리플레이에 수퍼유저 단계가 하나 생긴다
Supabase 프로젝트의 DB 에는 "
supabase_admin이public에 만드는 테이블은 postgres·anon·authenticated·service_role 에 ALL" 이라는 기본 권한이 걸려 있다. postgis 는supabase_admin이 설치하므로 운영의spatial_ref_sys는 그 권한을 받고, 가드 마이그레이션은 그중 postgres 의 TRIGGER 권한으로 트리거를 건다.리플레이가 쓰는 작업용 DB 는 새로 만든 DB 라 그 기본 권한이 없다(
pg_default_acl은 DB 별 카탈로그). 그대로면create trigger가 permission denied 로 멈춘다. 그래서 prelude 직후 수퍼유저로 같은 권한을 준다 —supabase/postgres이미지는supabase_admin비밀번호를POSTGRES_PASSWORD로 맞춰 두므로 연결문자열의 사용자 이름만 갈아끼운다(REPLAY_SUPERUSER로 바꿀 수 있다). 스냅샷 쪽(A)에도 똑같이 적용해 덤프 비교가 대칭이 되게 했다.검증
schema.sql과 바이트 동일함을 확인(드리프트 없음).outofband.txt차이는 트리거 한 줄뿐.build_baseline.py재실행 후 추가 diff 없음.supabase/postgres:17.6.1.121, 진단 커밋으로 찍어 본 뒤 제거):pg_default_acl0행,spatial_ref_sysACL 은 소유자 +PUBLIC=r뿐 → postgres 의create trigger는permission denied for table spatial_ref_sys. 수퍼유저 단계가 실제로 필요하다.replay잡: 225건 적용, 스냅샷 일치, 밖 객체 26줄(트리거 포함) 일치. t27 은pgtap·replay두 잡에서 각각 7/7.머지 후
로컬 워킹트리에 같은 이름의 미추적 파일(마이그레이션·t27)과
_schema_dump.sh수정이 남아 있으면git pull이 거부한다 — 로컬 사본을 지우고 받으면 된다(내용은 이 PR 과 같다).🤖 Generated with Claude Code