Skip to main content

Multi-Tenancy & Isolation

วิธีที่ Synapse แยกข้อมูลระหว่างผู้ใช้และ mind — อธิบายขอบเขตความปลอดภัย


Multi-Tenancy & Isolation

Synapse เป็น multi-tenant: หลายผู้ใช้ แต่ละคนมีหลาย mind ที่แยกจากกันโดยสมบูรณ์ เอกสารหน้านี้อธิบายโมเดล isolation

ลำดับชั้น Tenant

Synapse Instance
  │
  ├── User Account 1 (email: alice@example.com)
  │   ├── Mind A (Mind Key mk_aaa...)
  │   │   ├── Memories (only accessible via mk_aaa...)
  │   │   ├── Tasks
  │   │   └── Chat
  │   └── Mind B (Mind Key mk_bbb...)
  │       └── ... (isolated from Mind A)
  │
  ├── User Account 2 (email: bob@example.com)
  │   └── Mind C (Mind Key mk_ccc...)
  │       └── ... (isolated from Alice's minds)
  │
  └── ... (more users)

ระดับ Isolation

ระดับ 1: User Isolation

แต่ละบัญชีผู้ใช้ถูกแยกกัน Alice ไม่สามารถ:

  • เห็น mind ของ Bob
  • เข้าถึง memory ของ Bob (แม้ด้วย JWT ของเธอ)
  • ดูข้อมูลบัญชีของ Bob

บังคับโดย: column user_id บนทุกตาราง, JWT มี user_id, ทุก query กรองตาม user_id

ระดับ 2: Mind Isolation

ภายในผู้ใช้ แต่ละ mind ถูกแยกกัน Mind A ไม่สามารถ:

  • เห็น memory ของ Mind B
  • เข้าถึง task, chat, script ของ Mind B

บังคับโดย: column mind_id บนตารางข้อมูลทั้งหมด, Mind Key มี mind_id, ทุก query กรองตาม mind_id

Mind Key isolation เป็นขอบเขตความปลอดภัยหลัก Mind Key ที่รั่วไหลให้สิทธิ์เข้าถึงข้อมูล mind นั้นอย่างเต็ม — แต่เฉพาะ mind นั้น

Authentication Token

Token Scope เข้าถึงอะไรได้
Mind Key mind เดียว ข้อมูล mind นั้นเท่านั้น
JWT บัญชีผู้ใช้ การจัดการบัญชี (สร้าง/รายการ/ลบ mind)
Computer Token computer เดียว คำสั่งของ computer นั้น

การเข้าถึงข้าม Mind

ภายในผู้ใช้เดียวกัน

ผู้ใช้เข้าถึง mind ทั้งหมดของตนผ่าน JWT (เช่น GET /minds รายการทั้งหมด) แต่เพื่ออ่าน/เขียนข้อมูล memory ต้องใช้ Mind Key เฉพาะ

ข้ามผู้ใช้

ผู้ใช้ไม่สามารถเข้าถึงข้อมูลของกันและกัน — เว้นแต่จะแชร์ mind อย่างชัดเจนผ่าน Sharing API:

# Alice shares Mind A with Bob
curl -X POST https://synapse.schaefer.zone/sharing \
  -H "Authorization: Bearer ALICE_JWT" \
  -d '{"mind_id": "m_aaa", "email": "bob@example.com", "role": "read"}'

หลังแชร์ Bob สามารถเข้าถึง Mind A ผ่าน JWT ของเขา (อ่านอย่างเดียวหาก role=read)

ขอบเขตความปลอดภัย

┌─────────────────────────────────────────────────┐
│              Synapse Instance                    │
│  ┌─────────────────────────────────────────┐    │
│  │         User Account Boundary           │    │
│  │  ┌──────────────┐  ┌──────────────┐    │    │
│  │  │  Mind Bound. │  │  Mind Bound. │    │    │
│  │  │  (Mind Key)  │  │  (Mind Key)  │    │    │
│  │  │              │  │              │    │    │
│  │  │  Memories    │  │  Memories    │    │    │
│  │  │  Tasks       │  │  Tasks       │    │    │
│  │  │  Chat        │  │  Chat        │    │    │
│  │  │  Scripts     │  │  Scripts     │    │    │
│  │  └──────────────┘  └──────────────┘    │    │
│  └─────────────────────────────────────────┘    │
└─────────────────────────────────────────────────┘

รูปแบบ Multi-Tenancy ทั่วไป

รูปแบบ 1: ผู้ใช้เดียว, mind เดียว

ทั่วไปที่สุดสำหรับผู้ใช้ LLM agent รายบุคคล

  • 1 บัญชีผู้ใช้
  • 1 mind
  • 1 Mind Key
  • memory ทั้งหมดใน scope เดียว

รูปแบบ 2: ผู้ใช้เดียว, หลาย mind

สำหรับผู้ใช้ที่มีหลาย context (งาน, ส่วนตัว, โปรเจกต์)

  • 1 บัญชีผู้ใช้
  • N mind (เช่น "work", "personal", "project-x")
  • N Mind Key
  • แต่ละ LLM session ใช้หนึ่ง Mind Key

รูปแบบ 3: Mind ที่แชร์ในทีม

สำหรับทีมที่ทำงานร่วมกันในโปรเจกต์

  • 1 ผู้ใช้สร้าง mind (ได้ Mind Key)
  • ผู้สร้างแชร์กับสมาชิกทีมผ่าน JWT
  • สมาชิกทีมทั้งหมดเข้าถึงผ่าน JWT (หรือ Mind Key ที่แชร์)
การแชร์ Mind Key ให้สิทธิ์อ่าน/เขียนเต็ม สำหรับการทำงานร่วมในทีม แนะนำ Sharing API (ใช้ JWT) มากกว่าการแชร์ Mind Key โดยตรง

รูปแบบ 4: SaaS Provider

สำหรับแอปที่ฝัง Synapse เป็น memory layer

  • ลูกค้าแต่ละราย = 1 บัญชีผู้ใช้
  • โปรเจกต์ลูกค้าแต่ละโปรเจกต์ = 1 mind
  • แอปเก็บ Mind Key ตามลูกค้า/โปรเจกต์
  • แยกอย่างสมบูรณ์ระหว่างลูกค้า

การตรวจสอบ Isolation

ทดสอบ: Mind Key เข้าถึง mind อื่นไม่ได้

# Mind A's key cannot read Mind B's memories
curl -H "Authorization: Bearer mk_aaa..." \
     "https://synapse.schaefer.zone/memory/search?q=test"
# Returns only Mind A's memories

curl -H "Authorization: Bearer mk_bbb..." \
     "https://synapse.schaefer.zone/memory/search?q=test"
# Returns only Mind B's memories (different results)

ทดสอบ: JWT อ่านข้อมูล memory โดยตรงไม่ได้

# JWT can list minds
curl -H "Authorization: Bearer YOUR_JWT" \
     https://synapse.schaefer.zone/minds
# Returns: list of minds

# JWT CANNOT read memories (need Mind Key)
curl -H "Authorization: Bearer YOUR_JWT" \
     https://synapse.schaefer.zone/memory/recall
# Returns: 401 Unauthorized

แนวทางปฏิบัติที่ดีที่สุด

ขั้นตอนถัดไป