# Connector-Level Security (/core/build/security-and-governance/connector-level-security)

:::info
**Target Audience**: Makers & Developers
:::

## TL;DR [#tldr]

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 [#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)](./row-level-security-rls-operators.mdx) or [column-level security (CLS)](./column-level-security-cls.mdx). You can combine the three.

## How to use a variable [#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.

```json
{
  "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 [#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 [#security]

:::warning

- 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.

:::

## Related pages [#related-pages]

- [Route a database connection with a user attribute](./how-to/route-a-database-connection.mdx)
- [Best practices: choosing an isolation setup](./connector-level-security-best-practices.mdx)
- [Variable management](../variable-management.mdx)
- [Add a database](../data-connections/how-to/add-a-database.mdx)
