The keycloak project ended with four open questions that design could not
settle. A two-VM lab was built to answer them by measurement, and this is
that material: 26 experiments, 125 raw command outputs, 22 browser captures.
Follows the import procedure in README.md.
source/ the originating repository verbatim — 78 documents, 28 SVGs,
8 manifests, plus .source-revision recording the commit
final/ the SSOT
document.md 729 lines written from the 29 experiment documents, not
concatenated: what was predicted, what was measured, and
where the measurement itself was wrong
evidence/raw 125 outputs, flattened to <experiment>__<file> because
the originals collided (01-baseline.txt appeared three
times) and the audit only globs the top level
evidence/meta one per raw file; command and exitCode are null and the
README says why rather than inventing them
evidence/browser 22 captures
assets/ three diagrams through techviz
.techviz/ their VizSpecs
A separate project rather than an addition to keycloak: the B-layer answers
that project's four questions, but the A, C and D layers are about cluster
failure, SSO and operations, and one document.md should hold one subject.
The four question records there can point here through 관계.
Recorded rather than papered over: only three of the 28 diagrams were
remade. The repository forbids hand-drawn SVG and forbids titles inside the
canvas; all 28 originals carry both, so converting them is redrawing, not
reformatting. They stay in source/ and the gap is written into the document.
verify-pipeline.py passes. audit-records.py reports no issues.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
5.1 KiB
kind, slug, title, topic, project, status, sourceRevision, rootTreeNode, evidenceCapturedOn, assets, evidence, source
| kind | slug | title | topic | project | status | sourceRevision | rootTreeNode | evidenceCapturedOn | assets | evidence | source | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| CONCEPT | rls-three-preconditions | RLS가 성립하기 위한 세 전제 | multitenancy-isolation | clean-architecture-backend-template | 게시 전 | 21234e38cdb9a926cbc92bb97a2aee2e4a7d2916 | concept:rls-three-preconditions | 2026-09-01 |
|
|
|
RLS가 성립하기 위한 세 전제
PostgreSQL 의 행 수준 보안이 실제로 격리하려면 세 가지가 동시에 참이어야 한다. 셋 중 하나만 어긋나도 정책은 올바르게 설정된 것처럼 보이면서 모든 쿼리가 모든 테넌트의 행을 돌려준다.
관계
- RLS가 아무것도 하지 않는 세 가지 방법 세 전제를 검증기가 실제로 확인하는 사례다.
- Hibernate filter는 보안 경계가 아니다 ORM 기능을 격리 경계로 쓸 때의 문제를 다룬 규칙이다.
- 격리 설정은 트랜잭션 로컬이어야 한다 테넌트 바인딩이 세션에 남지 않게 하는 규칙이다.
본문
PostgreSQL RLS가 실제로 격리하려면 세 가지가 동시에 참이어야 한다.
격리가 성립하는 세 조건
:::evidence key="rls-three-preconditions-diagram" alt="ENABLE RLS 와 FORCE RLS 와 BYPASSRLS 없는 롤이 격리 성립 조건 안에 나란히 놓인다" caption="격리가 성립하는 세 조건" zoom="false" :::
ENABLE ROW LEVEL SECURITY— 테이블에 policy를 켠다.FORCE ROW LEVEL SECURITY— 테이블 OWNER에게도 적용한다. 없으면 owner는 자기 policy에서 면제되고, owner는 흔히 마이그레이션 롤이며 그것이 사람들이 테스트하는 롤이다.- 런타임 롤이
BYPASSRLS를 갖지 않는다 — 이것은 테이블 속성이 아니라 롤 속성이라 startup에서 assert해야 한다.
동시에 참이어야 하는 세 가지
:::evidence key="rls-three-preconditions" alt="분석 문서 final/document.md 에서 이 기록의 근거 절을 그대로 잘라낸 18줄. 코드베이스를 측정한 것이 아니라 원본 판정이 무엇을 적었는지를 보여 준다." caption="final/document.md 발췌 — 18줄" zoom="true" :::
두 번째 인자 true 가 fail-closed 를 만든다
policy가 current_setting('app.tenant_id', true)를 쓴다 — 두 번째 인자 true가 미설정 시 raise 대신 NULL을 반환하고, NULL은 절대 tenant_id와 같지 않다.
:::note
실제 RLS 환경을 세워 세 전제를 하나씩 깨보지 않았다
:::
세 전제
/**
* Proves the runtime role cannot bypass row-level security (experimental plan Task 3).
*
* <p>Three ways RLS silently does nothing, all checked here:
*
* <ul>
* <li>The table has no policy, or RLS was never enabled on it.
* <li>The runtime role has {@code BYPASSRLS}.
* <li>The runtime role <em>owns</em> the table — table owners are exempt from RLS unless the
* table is set to {@code FORCE ROW LEVEL SECURITY}, which is the one people forget.
* </ul>
*
* <p>Each of those produces a system where every query returns every tenant's rows while the
* policies look correctly configured.
*/
세 번째가 이 개념의 핵심이다.
| 전제 | 무엇인가 | 왜 놓치는가 |
|---|---|---|
| 정책과 RLS 활성화 | 테이블 속성 | 가장 명시적이라 잘 보인다 |
런타임 롤이 BYPASSRLS 를 갖지 않음 |
롤 속성 | 테이블을 봐서는 알 수 없다 |
| 테이블 소유자에게도 강제 | 테이블 속성 | 소유자가 대개 마이그레이션 롤이고, 사람들이 그 롤로 테스트한다 |
소유자 면제가 왜 함정인가
테이블 소유자는 자기 정책에서 면제된다. FORCE ROW LEVEL SECURITY 를 켜야 소유자에게도 적용된다.
그리고 소유자는 흔히 마이그레이션 롤이다. 그 롤이 스키마를 만들었기 때문이다. 검증할 때 쓰는 롤도 대개 그것이다.
:::danger
마이그레이션 롤로 테스트하면 정책이 전혀 적용되지 않은 상태에서도 통과한다. 그리고 그 롤은 정책이 잘 붙어 있다고 보고한다.
:::
롤 속성은 시작에서 확인해야 한다
BYPASSRLS 는 테이블 속성이 아니라 롤 속성이다. 스키마를 아무리 살펴도 나오지 않는다.
그래서 시작 시점에 단언한다. 런타임 롤이 그 속성을 갖지 않는지 데이터베이스에 물어본다.
미설정 시 fail-closed
정책이 세션 설정을 읽을 때 두 번째 인자를 참으로 준다.
current_setting('app.tenant_id', true)
그 인자가 참이면 설정이 없을 때 예외를 던지는 대신 널을 돌려준다. 그리고 널은 어떤 테넌트 식별자와도 같지 않다.
즉 테넌트 바인딩을 잊은 세션은 아무 행도 보지 못한다. 모든 행을 보는 것이 아니라.