Commit 5ba52b0
fix(driver-sql): honor tenancy.enabled:false in driver org-scoping (ADR-0066) (#2241)
* fix(driver-sql): honor tenancy.enabled:false in driver org-scoping (ADR-0066)
The SqlDriver auto-detects `organization_id` as a tenant-isolation column and,
when the caller passes `DriverOptions.tenantId`, injects `WHERE organization_id
= <tenantId>` on reads/updates/deletes (and the column on inserts). The
detection had two branches: a declarative one that correctly respected
`tenancy.enabled !== false`, and an implicit `organization_id`-column fallback
that did NOT — so an object explicitly opting OUT of tenancy still got
org-scoped whenever it happened to carry an `organization_id` column.
Impact (surfaced verifying ADR-0066 Phase 1): `sys_license` is platform-global
(`tenancy.enabled:false`) but keeps an optional, often-NULL `organization_id`
owner FK. A platform admin with an active org reads it through the data API
with `ctx.tenantId = <org>`, so the engine threads that into DriverOptions and
the driver silently filtered to `organization_id = <org>` — excluding the
NULL-org rows. Net: the admin saw ZERO licenses while an unscoped/anonymous
read still returned them. The filter is injected inside the driver's query
builder, not the AST, which is why it presented as an empty result with no
visible RLS `where` (astWhere=undefined).
Fix: extract a single `computeTenantField()` helper (shared by `initObjects`
and `registerExternalObject`, which had drifted) that returns `null` for any
schema with `tenancy.enabled === false`, before the implicit column heuristic.
Genuine org-scoped objects (no tenancy decl, or `enabled:true`) are unaffected.
TursoDriver extends SqlDriver and delegates initObjects to super, so the prod
control plane (Neon/Postgres and libsql) is covered by the same fix.
Adds regression tests: tenancy-disabled object registers no tenant field, reads
are unscoped regardless of `tenantId`, scoped/unscoped reads agree, and inserts
don't auto-inject `organization_id`.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* chore(changeset): driver-sql tenancy.enabled:false opt-out patch
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 57261f3 commit 5ba52b0
3 files changed
Lines changed: 108 additions & 31 deletions
File tree
- .changeset
- packages/plugins/driver-sql/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
222 | 276 | | |
223 | 277 | | |
224 | 278 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1306 | 1306 | | |
1307 | 1307 | | |
1308 | 1308 | | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
1309 | 1342 | | |
1310 | 1343 | | |
1311 | 1344 | | |
| |||
1368 | 1401 | | |
1369 | 1402 | | |
1370 | 1403 | | |
1371 | | - | |
1372 | | - | |
1373 | | - | |
1374 | | - | |
1375 | | - | |
1376 | | - | |
1377 | | - | |
1378 | | - | |
1379 | | - | |
1380 | | - | |
1381 | | - | |
1382 | | - | |
| 1404 | + | |
1383 | 1405 | | |
1384 | 1406 | | |
1385 | 1407 | | |
| |||
1425 | 1447 | | |
1426 | 1448 | | |
1427 | 1449 | | |
1428 | | - | |
1429 | | - | |
1430 | | - | |
1431 | | - | |
1432 | | - | |
1433 | | - | |
1434 | | - | |
1435 | | - | |
1436 | | - | |
1437 | | - | |
1438 | | - | |
1439 | | - | |
1440 | | - | |
1441 | | - | |
1442 | | - | |
1443 | | - | |
1444 | | - | |
1445 | | - | |
1446 | | - | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
1447 | 1454 | | |
1448 | 1455 | | |
1449 | 1456 | | |
| |||
0 commit comments