Connector-Level Security
Route each viewer to their own data source by using user attributes in the fields of a database connection.
Target Audience: Makers & Developers
TL;DR
Connector-level security routes each viewer to their own data source. You replace a field of a database connection, such as the host or the database name, with a user attribute.
When to use it
Use it when viewers must query different hosts, databases or accounts through the same connection and dashboards. To filter inside one source, use row-level security (RLS) or column-level security (CLS). You can combine the three.
How to use a variable
In the connection form, click Variable ({} icon) next to a field, then select a user attribute.
- The variable replaces the whole field. You cannot combine it with text, as in
db-followed by a variable. - Expected values are typed: the attribute type must match the field type, for example Integer for Port.
In the embed token, pass each value under user.attributes, using the exact attribute name as the key.
{
"user": {
"distinctId": "user-123",
"role": "explorer",
"attributes": {
"db_host": "db.example.com",
"db_port": 5432
}
}
}Send integers as numbers: 5432, not "5432".
Default values and viewer values
- Setup: connection setup and database analysis in Toucan AI, such as Test Connection, schema discovery, table previews and AI analysis, use the default value of the attribute.
- Consumption: when data is queried in dashboards, AI chat or embeds, the viewer's attributes apply, such as those in the embed token. The default value is used if the viewer has no value.
Security
- Not every variable changes which data is read: variables on a schema field, and on the MySQL Database field, do not redirect queries. Test your routing with two sources.
- Do not store passwords, keys or other secrets in user attributes or their default values. Keep secrets as static values on the connection.
- Compute attribute values on your server. A wrong but valid value routes the viewer to another source.
- Use a default value that points to a source with no real tenant data.
- View as overrides also change the connection. Give roles that can use it only to people allowed to see every routed source.