Skip to content

security: fix tenant-boundary checks across gateway, kv, sync, calvin, ddl and backup - #512

Draft
EnRaiha wants to merge 12 commits into
NodeDB-Lab:mainfrom
EnRaiha:fix/tenant-boundary-checks
Draft

EnRaiha wants to merge 12 commits into
NodeDB-Lab:mainfrom
EnRaiha:fix/tenant-boundary-checks

Conversation

@EnRaiha

@EnRaiha EnRaiha commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Fixes 11 operations across gateway, kv, sync, calvin, ddl and backup that skipped the caller's tenant-boundary check, letting a caller read, list, or act on another tenant's rows, keys, sessions, tasks, or auth records.

ddl: refuse the superuser role in CREATE USER and ALTER USER for a non-superuser (d89c5a161)

CREATE USER ... ROLE superuser and ALTER USER SET ROLE superuser now apply the same guard as GRANT superuser. A caller without the superuser flag receives SQLSTATE 42501.

ddl: compare the target user's tenant with the caller's tenant (f00ed895d)

ALTER USER, DROP USER, GRANT and REVOKE role, CREATE API KEY, REVOKE API KEY, DROP ROLE and ALTER ROLE now resolve the target inside the caller's tenant. LIST API KEYS returns only keys of the caller's tenant. A superuser keeps access to every tenant. A target of another tenant answers 42704.

backup: refuse a tenant id other than the caller's tenant (a3f2941c4)

COPY (BACKUP TENANT n) and COPY tenant_restore(n) compare n with the caller's tenant before the BACKUP permission check. A caller without the superuser flag receives SQLSTATE 42501 for another tenant.

ddl: list only the caller's tenant in LIST AUTH KEYS (e90e7df3b)

LIST AUTH KEYS drops keys whose tenant differs from the caller's tenant. A superuser still lists every tenant.

ddl: limit delegation, org, scope and quota listings to the caller's tenant (0a7b66ad4)

SHOW DELEGATIONS, REVOKE DELEGATION, SHOW ORGS, SHOW MEMBERS OF ORG, SHOW SCOPE GRANTS, SHOW SCOPES FOR, SHOW USAGE and SHOW QUOTA resolve the owning auth user or org and compare its tenant with the caller's tenant. An id with no record is not visible to a non-superuser. A superuser keeps access to every tenant.

ddl: require tenant_admin for REQUEUE TRIGGER DLQ before the entry lookup (bdcc0ed84)

A caller with neither the superuser flag nor the tenant_admin role receives SQLSTATE 42501 before the entry is read.

sync: refuse a session that has no tenant (301589a6d)

The entry gate and the delta collection gate refuse an authenticated sync session whose tenant is unset. Frames no longer reach the tenant 0 fallback in the engine handlers. Existing handler tests set a tenant on their authenticated sessions.

calvin: refuse a static task set that mixes tenants (221ab98e7)

The static and single-vshard builders compare each task tenant with the class tenant. A task of another tenant returns BadRequest before any key set is built.

sync: format the tenant lines in the handler tests (00c67a305)

Test-only formatting, no behavior change.

kv: refuse a second identity for one table key (8cff3156e)

register_table_identity returns an error when a table key already names another database, tenant or collection. Write, atomic, restore and undo paths propagate it. Index and checkpoint registration paths register nothing on a conflict. KvWriteRefusal and AtomicError gain an identity conflict variant, mapped to an internal error.

gateway: key the plan cache by tenant and database (4222ab63e)

PlanCacheKey carries the tenant and database of the caller. Two callers share a cached plan only when both match.

…n-superuser

CREATE USER ... ROLE superuser and ALTER USER SET ROLE superuser now apply
the same guard as GRANT superuser.
A caller without the superuser flag receives SQLSTATE 42501.
ALTER USER, DROP USER, GRANT and REVOKE role, CREATE API KEY, REVOKE API KEY,
DROP ROLE and ALTER ROLE now resolve the target inside the caller's tenant.
LIST API KEYS returns only keys of the caller's tenant.
A superuser keeps access to every tenant.
A target of another tenant answers 42704.
COPY (BACKUP TENANT n) and COPY tenant_restore(n) compare n with the caller's
tenant before the BACKUP permission check.
A caller without the superuser flag receives SQLSTATE 42501 for another tenant.
LIST AUTH KEYS drops keys whose tenant differs from the caller's tenant.
A superuser still lists every tenant.
…tenant

SHOW DELEGATIONS, REVOKE DELEGATION, SHOW ORGS, SHOW MEMBERS OF ORG,
SHOW SCOPE GRANTS, SHOW SCOPES FOR, SHOW USAGE and SHOW QUOTA resolve the
owning auth user or org and compare its tenant with the caller's tenant.
An id with no record is not visible to a non-superuser.
A superuser keeps access to every tenant.
…okup

A caller with neither the superuser flag nor the tenant_admin role receives
SQLSTATE 42501 before the entry is read.
The entry gate and the delta collection gate refuse an authenticated sync session whose tenant is unset.
Frames no longer reach the tenant 0 fallback in the engine handlers.
Existing handler tests set a tenant on their authenticated sessions.
The static and single-vshard builders compare each task tenant with the class tenant.
A task of another tenant returns BadRequest before any key set is built.
register_table_identity returns an error when a table key already names another database, tenant or collection.
Write, atomic, restore and undo paths propagate it. Index and checkpoint registration paths register nothing on a conflict.
KvWriteRefusal and AtomicError gain an identity conflict variant, mapped to an internal error.
PlanCacheKey carries the tenant and database of the caller.
Two callers share a cached plan only when both match.
…grantees

GRANT SCOPE accepts ORG, USER, ROLE and TEAM as the grantee type.
grantee_visible() only special-cased org, falling through to the
auth-user lookup for everything else. A role or team id is never an
auth user id, so the lookup always missed, and a non-superuser's own
role-type and team-type scope grants were silently dropped from SHOW
SCOPE GRANTS, even inside their own tenant. Fails closed (no leak),
but breaks a legitimate same-tenant admin query with no error.

A role grantee now resolves through the existing role_in_caller_tenant
check, the same one role assignment already uses. No team registry
exists yet, so a team grantee has no tenant to compare and stays
visible to a superuser only, same as before.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant