{"title":"Multi-Tenancy & Isolation","slug":"multi-tenancy","category":"concepts","summary":"วิธีที่ Synapse แยกข้อมูลระหว่างผู้ใช้และ mind — อธิบายขอบเขตความปลอดภัย","audience":["human","llm"],"tags":["concept","multi-tenancy","security","isolation"],"difficulty":"intermediate","updated":"2026-06-27","word_count":382,"read_minutes":2,"lang":"th","translated":true,"requested_lang":"th","content_markdown":"\n# Multi-Tenancy & Isolation\n\nSynapse เป็น multi-tenant: หลายผู้ใช้ แต่ละคนมีหลาย mind ที่แยกจากกันโดยสมบูรณ์ เอกสารหน้านี้อธิบายโมเดล isolation\n\n## ลำดับชั้น Tenant\n\n```\nSynapse Instance\n  │\n  ├── User Account 1 (email: alice@example.com)\n  │   ├── Mind A (Mind Key mk_aaa...)\n  │   │   ├── Memories (only accessible via mk_aaa...)\n  │   │   ├── Tasks\n  │   │   └── Chat\n  │   └── Mind B (Mind Key mk_bbb...)\n  │       └── ... (isolated from Mind A)\n  │\n  ├── User Account 2 (email: bob@example.com)\n  │   └── Mind C (Mind Key mk_ccc...)\n  │       └── ... (isolated from Alice's minds)\n  │\n  └── ... (more users)\n```\n\n## ระดับ Isolation\n\n### ระดับ 1: User Isolation\n\nแต่ละบัญชีผู้ใช้ถูกแยกกัน Alice ไม่สามารถ:\n\n- เห็น mind ของ Bob\n- เข้าถึง memory ของ Bob (แม้ด้วย JWT ของเธอ)\n- ดูข้อมูลบัญชีของ Bob\n\nบังคับโดย: column `user_id` บนทุกตาราง, JWT มี `user_id`, ทุก query กรองตาม `user_id`\n\n### ระดับ 2: Mind Isolation\n\nภายในผู้ใช้ แต่ละ mind ถูกแยกกัน Mind A ไม่สามารถ:\n\n- เห็น memory ของ Mind B\n- เข้าถึง task, chat, script ของ Mind B\n\nบังคับโดย: column `mind_id` บนตารางข้อมูลทั้งหมด, Mind Key มี `mind_id`, ทุก query กรองตาม `mind_id`\n\n> [!CRITICAL]\n> Mind Key isolation เป็นขอบเขตความปลอดภัยหลัก Mind Key ที่รั่วไหลให้สิทธิ์เข้าถึงข้อมูล mind นั้นอย่างเต็ม — แต่เฉพาะ mind นั้น\n\n## Authentication Token\n\n| Token | Scope | เข้าถึงอะไรได้ |\n|-------|-------|-------------------|\n| Mind Key | mind เดียว | ข้อมูล mind นั้นเท่านั้น |\n| JWT | บัญชีผู้ใช้ | การจัดการบัญชี (สร้าง/รายการ/ลบ mind) |\n| Computer Token | computer เดียว | คำสั่งของ computer นั้น |\n\n## การเข้าถึงข้าม Mind\n\n### ภายในผู้ใช้เดียวกัน\n\nผู้ใช้เข้าถึง mind ทั้งหมดของตนผ่าน JWT (เช่น `GET /minds` รายการทั้งหมด) แต่เพื่ออ่าน/เขียนข้อมูล memory ต้องใช้ Mind Key เฉพาะ\n\n### ข้ามผู้ใช้\n\nผู้ใช้ไม่สามารถเข้าถึงข้อมูลของกันและกัน — เว้นแต่จะแชร์ mind อย่างชัดเจนผ่าน Sharing API:\n\n```bash\n# Alice shares Mind A with Bob\ncurl -X POST https://synapse.schaefer.zone/sharing \\\n  -H \"Authorization: Bearer ALICE_JWT\" \\\n  -d '{\"mind_id\": \"m_aaa\", \"email\": \"bob@example.com\", \"role\": \"read\"}'\n```\n\nหลังแชร์ Bob สามารถเข้าถึง Mind A ผ่าน JWT ของเขา (อ่านอย่างเดียวหาก `role=read`)\n\n## ขอบเขตความปลอดภัย\n\n```\n┌─────────────────────────────────────────────────┐\n│              Synapse Instance                    │\n│  ┌─────────────────────────────────────────┐    │\n│  │         User Account Boundary           │    │\n│  │  ┌──────────────┐  ┌──────────────┐    │    │\n│  │  │  Mind Bound. │  │  Mind Bound. │    │    │\n│  │  │  (Mind Key)  │  │  (Mind Key)  │    │    │\n│  │  │              │  │              │    │    │\n│  │  │  Memories    │  │  Memories    │    │    │\n│  │  │  Tasks       │  │  Tasks       │    │    │\n│  │  │  Chat        │  │  Chat        │    │    │\n│  │  │  Scripts     │  │  Scripts     │    │    │\n│  │  └──────────────┘  └──────────────┘    │    │\n│  └─────────────────────────────────────────┘    │\n└─────────────────────────────────────────────────┘\n```\n\n## รูปแบบ Multi-Tenancy ทั่วไป\n\n### รูปแบบ 1: ผู้ใช้เดียว, mind เดียว\n\nทั่วไปที่สุดสำหรับผู้ใช้ LLM agent รายบุคคล\n\n- 1 บัญชีผู้ใช้\n- 1 mind\n- 1 Mind Key\n- memory ทั้งหมดใน scope เดียว\n\n### รูปแบบ 2: ผู้ใช้เดียว, หลาย mind\n\nสำหรับผู้ใช้ที่มีหลาย context (งาน, ส่วนตัว, โปรเจกต์)\n\n- 1 บัญชีผู้ใช้\n- N mind (เช่น \"work\", \"personal\", \"project-x\")\n- N Mind Key\n- แต่ละ LLM session ใช้หนึ่ง Mind Key\n\n### รูปแบบ 3: Mind ที่แชร์ในทีม\n\nสำหรับทีมที่ทำงานร่วมกันในโปรเจกต์\n\n- 1 ผู้ใช้สร้าง mind (ได้ Mind Key)\n- ผู้สร้างแชร์กับสมาชิกทีมผ่าน JWT\n- สมาชิกทีมทั้งหมดเข้าถึงผ่าน JWT (หรือ Mind Key ที่แชร์)\n\n> [!WARNING]\n> การแชร์ Mind Key ให้สิทธิ์อ่าน/เขียนเต็ม สำหรับการทำงานร่วมในทีม แนะนำ Sharing API (ใช้ JWT) มากกว่าการแชร์ Mind Key โดยตรง\n\n### รูปแบบ 4: SaaS Provider\n\nสำหรับแอปที่ฝัง Synapse เป็น memory layer\n\n- ลูกค้าแต่ละราย = 1 บัญชีผู้ใช้\n- โปรเจกต์ลูกค้าแต่ละโปรเจกต์ = 1 mind\n- แอปเก็บ Mind Key ตามลูกค้า/โปรเจกต์\n- แยกอย่างสมบูรณ์ระหว่างลูกค้า\n\n## การตรวจสอบ Isolation\n\n### ทดสอบ: Mind Key เข้าถึง mind อื่นไม่ได้\n\n```bash\n# Mind A's key cannot read Mind B's memories\ncurl -H \"Authorization: Bearer mk_aaa...\" \\\n     \"https://synapse.schaefer.zone/memory/search?q=test\"\n# Returns only Mind A's memories\n\ncurl -H \"Authorization: Bearer mk_bbb...\" \\\n     \"https://synapse.schaefer.zone/memory/search?q=test\"\n# Returns only Mind B's memories (different results)\n```\n\n### ทดสอบ: JWT อ่านข้อมูล memory โดยตรงไม่ได้\n\n```bash\n# JWT can list minds\ncurl -H \"Authorization: Bearer YOUR_JWT\" \\\n     https://synapse.schaefer.zone/minds\n# Returns: list of minds\n\n# JWT CANNOT read memories (need Mind Key)\ncurl -H \"Authorization: Bearer YOUR_JWT\" \\\n     https://synapse.schaefer.zone/memory/recall\n# Returns: 401 Unauthorized\n```\n\n## แนวทางปฏิบัติที่ดีที่สุด\n\n> [!TIP]\n> - **ใช้หนึ่ง mind ต่อโปรเจกต์/context** — isolation เป็นเพื่อนของคุณ\n> - **อย่าแชร์ Mind Key** — ใช้ Sharing API แทน\n> - **หมุนเวียน Mind Key** หากถูกโจมตี (ลบ mind, สร้างใหม่)\n> - **ตรวจสอบ mind ที่แชร์** — ตรวจ `GET /sharing` เป็นคาบ\n> - **ใช้ JWT สำหรับ human UI** — อย่าเปิดเผย Mind Key ต่อ end user\n\n## ขั้นตอนถัดไป\n\n- [Authentication](/docs/getting-started/authentication)\n- [Mind Key vs JWT](/docs/getting-started/mind-key-vs-jwt)\n- [Architecture](/docs/concepts/architecture)\n","content_html":"<h1>Multi-Tenancy &amp; Isolation</h1>\n<p>Synapse เป็น multi-tenant: หลายผู้ใช้ แต่ละคนมีหลาย mind ที่แยกจากกันโดยสมบูรณ์ เอกสารหน้านี้อธิบายโมเดล isolation</p>\n<h2>ลำดับชั้น Tenant</h2>\n<pre><code class=\"hljs language-plaintext\">Synapse Instance\n  │\n  ├── User Account 1 (email: alice@example.com)\n  │   ├── Mind A (Mind Key mk_aaa...)\n  │   │   ├── Memories (only accessible via mk_aaa...)\n  │   │   ├── Tasks\n  │   │   └── Chat\n  │   └── Mind B (Mind Key mk_bbb...)\n  │       └── ... (isolated from Mind A)\n  │\n  ├── User Account 2 (email: bob@example.com)\n  │   └── Mind C (Mind Key mk_ccc...)\n  │       └── ... (isolated from Alice&#x27;s minds)\n  │\n  └── ... (more users)</code></pre><h2>ระดับ Isolation</h2>\n<h3>ระดับ 1: User Isolation</h3>\n<p>แต่ละบัญชีผู้ใช้ถูกแยกกัน Alice ไม่สามารถ:</p>\n<ul>\n<li>เห็น mind ของ Bob</li>\n<li>เข้าถึง memory ของ Bob (แม้ด้วย JWT ของเธอ)</li>\n<li>ดูข้อมูลบัญชีของ Bob</li>\n</ul>\n<p>บังคับโดย: column <code>user_id</code> บนทุกตาราง, JWT มี <code>user_id</code>, ทุก query กรองตาม <code>user_id</code></p>\n<h3>ระดับ 2: Mind Isolation</h3>\n<p>ภายในผู้ใช้ แต่ละ mind ถูกแยกกัน Mind A ไม่สามารถ:</p>\n<ul>\n<li>เห็น memory ของ Mind B</li>\n<li>เข้าถึง task, chat, script ของ Mind B</li>\n</ul>\n<p>บังคับโดย: column <code>mind_id</code> บนตารางข้อมูลทั้งหมด, Mind Key มี <code>mind_id</code>, ทุก query กรองตาม <code>mind_id</code></p>\n<div class=\"callout callout-critical\">Mind Key isolation เป็นขอบเขตความปลอดภัยหลัก Mind Key ที่รั่วไหลให้สิทธิ์เข้าถึงข้อมูล mind นั้นอย่างเต็ม — แต่เฉพาะ mind นั้น</div><h2>Authentication Token</h2>\n<table>\n<thead>\n<tr>\n<th>Token</th>\n<th>Scope</th>\n<th>เข้าถึงอะไรได้</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>Mind Key</td>\n<td>mind เดียว</td>\n<td>ข้อมูล mind นั้นเท่านั้น</td>\n</tr>\n<tr>\n<td>JWT</td>\n<td>บัญชีผู้ใช้</td>\n<td>การจัดการบัญชี (สร้าง/รายการ/ลบ mind)</td>\n</tr>\n<tr>\n<td>Computer Token</td>\n<td>computer เดียว</td>\n<td>คำสั่งของ computer นั้น</td>\n</tr>\n</tbody></table>\n<h2>การเข้าถึงข้าม Mind</h2>\n<h3>ภายในผู้ใช้เดียวกัน</h3>\n<p>ผู้ใช้เข้าถึง mind ทั้งหมดของตนผ่าน JWT (เช่น <code>GET /minds</code> รายการทั้งหมด) แต่เพื่ออ่าน/เขียนข้อมูล memory ต้องใช้ Mind Key เฉพาะ</p>\n<h3>ข้ามผู้ใช้</h3>\n<p>ผู้ใช้ไม่สามารถเข้าถึงข้อมูลของกันและกัน — เว้นแต่จะแชร์ mind อย่างชัดเจนผ่าน Sharing API:</p>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># Alice shares Mind A with Bob</span>\ncurl -X POST https://synapse.schaefer.zone/sharing \\\n  -H <span class=\"hljs-string\">&quot;Authorization: Bearer ALICE_JWT&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{&quot;mind_id&quot;: &quot;m_aaa&quot;, &quot;email&quot;: &quot;bob@example.com&quot;, &quot;role&quot;: &quot;read&quot;}&#x27;</span></code></pre><p>หลังแชร์ Bob สามารถเข้าถึง Mind A ผ่าน JWT ของเขา (อ่านอย่างเดียวหาก <code>role=read</code>)</p>\n<h2>ขอบเขตความปลอดภัย</h2>\n<pre><code class=\"hljs language-plaintext\">┌─────────────────────────────────────────────────┐\n│              Synapse Instance                    │\n│  ┌─────────────────────────────────────────┐    │\n│  │         User Account Boundary           │    │\n│  │  ┌──────────────┐  ┌──────────────┐    │    │\n│  │  │  Mind Bound. │  │  Mind Bound. │    │    │\n│  │  │  (Mind Key)  │  │  (Mind Key)  │    │    │\n│  │  │              │  │              │    │    │\n│  │  │  Memories    │  │  Memories    │    │    │\n│  │  │  Tasks       │  │  Tasks       │    │    │\n│  │  │  Chat        │  │  Chat        │    │    │\n│  │  │  Scripts     │  │  Scripts     │    │    │\n│  │  └──────────────┘  └──────────────┘    │    │\n│  └─────────────────────────────────────────┘    │\n└─────────────────────────────────────────────────┘</code></pre><h2>รูปแบบ Multi-Tenancy ทั่วไป</h2>\n<h3>รูปแบบ 1: ผู้ใช้เดียว, mind เดียว</h3>\n<p>ทั่วไปที่สุดสำหรับผู้ใช้ LLM agent รายบุคคล</p>\n<ul>\n<li>1 บัญชีผู้ใช้</li>\n<li>1 mind</li>\n<li>1 Mind Key</li>\n<li>memory ทั้งหมดใน scope เดียว</li>\n</ul>\n<h3>รูปแบบ 2: ผู้ใช้เดียว, หลาย mind</h3>\n<p>สำหรับผู้ใช้ที่มีหลาย context (งาน, ส่วนตัว, โปรเจกต์)</p>\n<ul>\n<li>1 บัญชีผู้ใช้</li>\n<li>N mind (เช่น &quot;work&quot;, &quot;personal&quot;, &quot;project-x&quot;)</li>\n<li>N Mind Key</li>\n<li>แต่ละ LLM session ใช้หนึ่ง Mind Key</li>\n</ul>\n<h3>รูปแบบ 3: Mind ที่แชร์ในทีม</h3>\n<p>สำหรับทีมที่ทำงานร่วมกันในโปรเจกต์</p>\n<ul>\n<li>1 ผู้ใช้สร้าง mind (ได้ Mind Key)</li>\n<li>ผู้สร้างแชร์กับสมาชิกทีมผ่าน JWT</li>\n<li>สมาชิกทีมทั้งหมดเข้าถึงผ่าน JWT (หรือ Mind Key ที่แชร์)</li>\n</ul>\n<div class=\"callout callout-warn\">การแชร์ Mind Key ให้สิทธิ์อ่าน/เขียนเต็ม สำหรับการทำงานร่วมในทีม แนะนำ Sharing API (ใช้ JWT) มากกว่าการแชร์ Mind Key โดยตรง</div><h3>รูปแบบ 4: SaaS Provider</h3>\n<p>สำหรับแอปที่ฝัง Synapse เป็น memory layer</p>\n<ul>\n<li>ลูกค้าแต่ละราย = 1 บัญชีผู้ใช้</li>\n<li>โปรเจกต์ลูกค้าแต่ละโปรเจกต์ = 1 mind</li>\n<li>แอปเก็บ Mind Key ตามลูกค้า/โปรเจกต์</li>\n<li>แยกอย่างสมบูรณ์ระหว่างลูกค้า</li>\n</ul>\n<h2>การตรวจสอบ Isolation</h2>\n<h3>ทดสอบ: Mind Key เข้าถึง mind อื่นไม่ได้</h3>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># Mind A&#x27;s key cannot read Mind B&#x27;s memories</span>\ncurl -H <span class=\"hljs-string\">&quot;Authorization: Bearer mk_aaa...&quot;</span> \\\n     <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/memory/search?q=test&quot;</span>\n<span class=\"hljs-comment\"># Returns only Mind A&#x27;s memories</span>\n\ncurl -H <span class=\"hljs-string\">&quot;Authorization: Bearer mk_bbb...&quot;</span> \\\n     <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/memory/search?q=test&quot;</span>\n<span class=\"hljs-comment\"># Returns only Mind B&#x27;s memories (different results)</span></code></pre><h3>ทดสอบ: JWT อ่านข้อมูล memory โดยตรงไม่ได้</h3>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># JWT can list minds</span>\ncurl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_JWT&quot;</span> \\\n     https://synapse.schaefer.zone/minds\n<span class=\"hljs-comment\"># Returns: list of minds</span>\n\n<span class=\"hljs-comment\"># JWT CANNOT read memories (need Mind Key)</span>\ncurl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_JWT&quot;</span> \\\n     https://synapse.schaefer.zone/memory/recall\n<span class=\"hljs-comment\"># Returns: 401 Unauthorized</span></code></pre><h2>แนวทางปฏิบัติที่ดีที่สุด</h2>\n<div class=\"callout callout-ok\"></div><h2>ขั้นตอนถัดไป</h2>\n<ul>\n<li><a href=\"/docs/getting-started/authentication\">Authentication</a></li>\n<li><a href=\"/docs/getting-started/mind-key-vs-jwt\">Mind Key vs JWT</a></li>\n<li><a href=\"/docs/concepts/architecture\">Architecture</a></li>\n</ul>\n","urls":{"html":"/docs/concepts/multi-tenancy","text":"/docs/concepts/multi-tenancy?format=text","json":"/docs/concepts/multi-tenancy?format=json","llm":"/docs/concepts/multi-tenancy?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}