UI-তে অন্য company-এর record লুকানো tenant isolation না।
Filter।
Real isolation user URL বদলালে, request replay করলে, ID guess করলে, background job চালালে, export খুললে বা stale cache পেলেও টিকবে।
তাই multi-tenant security interface-এর নিচে শুরু।
Trusted identity থেকে tenant context
Client tenant request করতে পারে।
Server decide করে identity ওই tenant-এর member কি না।
Request path:
- session বা token verify;
- actor resolve;
- tenant membership আর role validate;
- trusted tenant context;
- domain operation-এ context pass।
Browser field proof না:
{ "tenantId": "company-b" }
Intent বোঝাতে পারে। Permission prove করতে পারে না।
প্রতিটি read scope
Dangerous pattern দেখতে harmless:
const project = await Project.findById(projectId);
ID valid হতে পারে।
অন্য tenant-এরও হতে পারে।
Ownership boundary query-তে:
const project = await Project.findOne({
_id: projectId,
tenantId: context.tenantId,
});
List, count, aggregate, search, export আর report-এ একই rule।
এক unscoped helper ভালো route guard bypass করতে পারে।
Write আর write-এর আগের read scope
ID দিয়ে update unsafe।
Tenant scope ছাড়া load, app code-এ check, পরে অন্য query দিয়ে write-ও unsafe।
সম্ভব হলে এক ownership-aware operation:
const updated = await Project.findOneAndUpdate(
{
_id: projectId,
tenantId: context.tenantId,
},
{
$set: allowedChanges,
},
{ new: true },
);
Controlled not-found বা forbidden result দিন। ID অন্য tenant-এর—এটা leak করবেন না।
Uniqueness tenant-relative
Email, project code, slug, invoice number বা integration key পুরো database না, এক tenant-এর ভেতর unique হতে পারে।
Compound constraint:
schema.index(
{ tenantId: 1, projectCode: 1 },
{ unique: true },
);
Application validation আর persisted index একই rule বলবে।
না হলে concurrent request friendly pre-check pass করে duplicate বানাতে পারে।
Cache key-তে tenant
এই key incomplete:
`dashboard:${userId}`
এক user multiple tenant-এ থাকলে data cross করতে পারে।
Full ownership scope:
`tenant:${tenantId}:user:${userId}:dashboard:v2`
Invalidation-ও একই dimension।
Memoization, CDN response, request cache আর generated export-এও একই warning।
Job, webhook আর file-ও tenant path
Async system-এ isolation ভুলে যাওয়া সহজ।
Job validated tenant reference বহন করবে, execute করার সময় resource আবার check করবে।
Webhook provider object-কে server-side data দিয়ে internal tenant-এ map করবে—client label দিয়ে না।
Storage path, signed URL, export আর attachment lookup ownership enforce করবে।
Request thread-এর বাইরে নেওয়া মানে security model-এর বাইরে না।
Admin boundary explicit
“Admin” এক universal role না।
আলাদা:
- tenant admin;
- support operator;
- platform admin;
- background system actor।
Platform access rare, auditable আর deliberately invoked।
Broad internal role-কে tenant check bypass shortcut বানাবেন না।
Negative test boundary prove করে
Happy path বলে Company A নিজের project পড়ে।
Security test বলে Company A, Company B-এর project:
- পড়তে পারে না;
- update পারে না;
- delete পারে না;
- export পারে না;
- count দিয়ে infer পারে না;
- cache থেকে পায় না;
- job trigger পারে না;
- file reach পারে না।
Reusable cross-tenant test helper রাখি, যাতে new resource একই hostile check পায়।
জরুরি: authentication actor কে—সেটা প্রমাণ করে। Tenant authorization কোন organization আর resource access করা যাবে—সেটা প্রমাণ করে। দুটোই দরকার।
Leak ছাড়া observe
Log-এ investigation-এর জন্য:
- request বা trace ID;
- internal actor ID;
- tenant ID;
- operation;
- authorization decision;
- safe error code।
Session token, provider secret, private file content বা অপ্রয়োজনীয় personal data না।
Observability-তেও security আর privacy।
Foundation checklist
Tenant-safe বলার আগে trace করি:
- identity থেকে membership;
- membership থেকে trusted context;
- context থেকে read/write;
- tenant-relative constraint;
- cache key/invalidation;
- async job/webhook;
- file ownership;
- admin escalation;
- negative test;
- safe audit event।
Interface final layer।
Boundary নিচে।
API behavior-এর জন্য পড়ুন growth সহ্য করা API contract। Production review-এর জন্য code-review checklist।
Existing SaaS audit করতে এক protected resource আর তার read/write path পাঠান।
- #SaaS
- #Multi-Tenant
- #সিকিউরিটি
- #Authorization
- #Data Isolation

আরও পড়ুন
ইঞ্জিনিয়ারিং, SaaS, ফ্রিল্যান্সিং আর নির্ভরযোগ্য প্রোডাক্ট তৈরির সম্পর্কিত লেখা।