ADR-0041: Bindings stored per tenant beside the operator's, read across tenants for the intake¶
Status: Accepted Date: 2026-11-01 Deciders: Alex Nodeland Implements: lattice ADR-0040's action item 2, lattice RFC-0013's bindings; beside ADR-0035 and ADR-0038
Context¶
lattice-core declares Binding and the Bindings port (lattice ADR-0040). RFC-0013 says grantr stores the tenant's bindings, beside the operator's layer from the deployment's configuration, changed by audited commands under grantr:manage_bindings, which a tenant's owners and admins hold. Two questions are grantr's to settle:
- Where the rows go. Each tenant's rows sit under row-level security.
- How the deployment's intake reads a connection's bindings in every tenant. A deployment's connection, such as Alertmanager's, reaches many tenants, and the intake routes each occurrence to the tenant the source names.
Decision¶
grantr_bindingsholds each tenant's bindings (migration 0009):- Rows are keyed by tenant and id, with the workspace, source and connection as columns and the binding as JSON.
- Two indexes after the tenant: one for a connection's bindings, one for a workspace's.
- The tenant policy every other table has.
Grants.bindings()returnsGrantrBindings, which holds the commands and the port:bind(tenant, workspace, source, connection, select=, types=, trust=, options=, by=)returns its audit entry (binding_added):- It mints the id and records the subject as
by(user:alice). - Its
bound_atis the entry's time. - A binding that isn't well formed is
Invalidbefore anything is checked or written.
- It mints the id and records the subject as
unbind(tenant, id, by=)returnsbinding_removed. One of the operator's is refused: it is the deployment's configuration.listed(tenant, by=, workspace=)returns the operator's, then the tenant's.- Each needs
grantr:manage_bindingson the tenant, which owners and admins hold and no workspace role does: a workspace's admin pauses a source with itssource:<name>switch instead (RFC-0013).
- The operator's layer is
Grants(operator_bindings=...), given as the deployment starts and never stored. An id it repeats is refused. for_connection(source, connection)returns the operator's bindings of the connection, then each live tenant's, read tenant by tenant under its own policy, as the approvals sweep reads them. The intake filters them by the occurrence's tenant.for_workspacereads one tenant's.- Deleting a tenant deletes its bindings.
- The admin API:
GET,POST /tenants/{tenant}/bindingsandDELETE /tenants/{tenant}/bindings/{id}. portalr's admin words both events ("bound forge inst_1 to workspace api, trusted as untrusted").
Options considered¶
Option A: Each tenant's rows, read tenant by tenant (chosen)¶
Pros: every row stays under its tenant's policy, and the intake's read needs no role that crosses tenants. Cons: a connection's bindings take one read per tenant. The intake reads them as a stream starts and as bindings change, not per occurrence, so the cost is per tenant, not per event.
Option B: An index of connections to tenants, outside row-level security¶
Cons: a table every tenant's transaction could read would say which tenants bind which connections, which is a tenant's business; and it must be kept in step with the rows.
Consequences¶
- Easier: an admin binds a source to a workspace in one command, audited, and the intake reads the same type the template's
TRACKER_BINDINGSbecomes. - Harder: with many tenants,
for_connectiongrows with them. A cache in the intake, invalidated by the audit log'sbinding_*entries, is its own change if it is needed. - portalr's admin page for bindings comes with connections (#927).
Action items¶
-
grantr_bindings,GrantrBindings,grantr:manage_bindings, the two events and the admin API, tested on memory, SQLite and PostgreSQL with row-level security. - The template's
TRACKER_BINDINGSread as the operator's layer (RFC-0013). - Admin's page for bindings (#927).