> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formal.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Business Intelligence

> Integrate Formal with BI tools for end-user identity propagation and access control

## Overview

Formal integrates with Business Intelligence applications to enable end-user identity propagation. This ensures that queries from BI tools are attributed to the actual end-user rather than a shared machine user, enabling accurate auditing and per-user policy enforcement.

The Connector accepts an end-user identity only from a machine user. It ignores identities asserted by human users and native database users.

## How It Works

When you set up a BI integration:

1. **Sync**: The BI sync worker, running in your infrastructure, fetches user identities from your BI application. You can also map users by hand
2. **Map**: Each BI user's ID is assigned as an external ID to the matching Formal user
3. **Propagate**: When BI tool users execute queries, their identity is passed to the Connector
4. **Enforce**: Policies evaluate based on the end-user, not the BI tool's machine user

```mermaid theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
sequenceDiagram
    participant User as BI User (Katie)
    participant BI as BI Tool
    participant Connector
    participant Database

    User->>BI: Create dashboard
    BI->>Connector: Query (Machine User + End-User ID)
    Connector->>Connector: Policy eval for Katie
    Connector->>Database: Execute as Machine User
    Database-->>Connector: Results
    Connector->>Connector: Mask based on Katie's permissions
    Connector-->>BI: Filtered results
    BI-->>User: Dashboard data
```

> [!NOTE]
>
> The Connector automatically fetches user information from the Control Plane,
> so no additional configuration is needed in your Connector deployment.

## Supported BI Applications

![Supported BI tools](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/supported_bis.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=a01a8da94fcecb925e57afe72bf50a99)

* **Metabase**
* **Looker**
* **Omni**
* **Fivetran**
* **Custom applications** (via SQL commenter)

## Setup

### Metabase

**1. Navigate to BI Integrations**

Go to [BI Integrations](https://app.formal.ai/bi-integrations) in the
Control Plane

**2. Add Integration**

Click **Create Integration**

**3. Select Metabase**

Choose Metabase from the list

**4. Create the integration**

Enter a name and click **Create**. Open the integration and copy its **ID**.

**5. Run the sync worker**

Run the [BI sync worker](https://github.com/formalco/formal-metabase-sync-worker)
somewhere that can reach both Metabase and Formal, with:

* `FORMAL_API_KEY`: a Formal API key
* `METABASE_BI_INTEGRATION_ID`: the integration's ID
* `METABASE_HOSTNAME` and `METABASE_VERSION`
* `METABASE_USERNAME` and `METABASE_PASSWORD` for a Metabase admin, or
  `METABASE_USE_API_KEY=true` and `METABASE_API_KEY`
* `FREQUENCY`, for example `1h`, to keep syncing. Without it, the worker
  syncs once and exits.

The repository's README lists every setting.

> [!NOTE]
>
> Formal doesn't connect to Metabase itself. The worker reads users from
> Metabase and writes their external IDs to Formal.

#### Terraform

```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
resource "formal_integration_bi" "metabase" {
  name = "production-metabase"
  sync = false

  metabase {
    hostname = "metabase.example.com"
  }
}
```

Pass `formal_integration_bi.metabase.id` to the worker as
`METABASE_BI_INTEGRATION_ID`.

### Looker

Looker supports end-user identity propagation via JDBC connection parameters.

**1. Open Database Connection**

Go to **Admin → Connections** in Looker

**2. Edit Connection**

Select your database connection

**3. Add Parameter**

In the "Additional Params" section, add:

```text theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
options=formal_enduser={{ _user_attributes['email'] }}
```

**4. Save**

Save the connection settings

This configuration tells Looker to pass the end-user's email in the connection string, which Formal extracts and uses for policy evaluation.

### Omni

Omni supports connecting to Snowflake through the Formal Connector using a host override. Unlike other BI tools that embed end-user identity in SQL comments, Omni propagates identity at session login time via the `QUERY_TAG` session parameter containing the `omniOrganizationUserId`.

#### Connection Setup

**1. Add a Snowflake Connection**

In Omni, go to your connection settings and select **Snowflake** as the database type.

**2. Choose Host & Port**

Select the **Host & port** connection option instead of the default account identifier method.

**3. Configure Host Override**

Set the host override to `account.<connector-hostname>`, where `<connector-hostname>` is your Formal connector hostname. For example:

```text theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
account.my-org.connectors.joinformal.com
```

The `account.` prefix is required for the connector to correctly route Snowflake requests.

**4. Set Port**

Set the port to match the listener port configured for your Snowflake resource on the connector (e.g., `1443`).

**5. Set Database and Warehouse**

Specify the **Database** and **Warehouse** that match your Snowflake resource configuration.

**6. Configure Authentication**

If the native user on your Formal resource uses key-pair authentication (`SNOWFLAKE_JWT`):

1. Select **Key Pair Authentication** as the authentication type
2. Set the **Username** to your Formal machine user (e.g., `idp:formal:machine:omni`)
3. Add a keypair using the private key available via the **Download Private Key** button on the machine user details page in the Control Plane

If the native user uses password authentication, enter the machine user's Formal token as the password instead.

**7. Test Connection**

Save and test the connection to verify queries are routed through the Formal Connector.

#### End-User Identity Setup

**1. Create Omni Integration**

In the Control Plane, go to [BI Integrations](https://app.formal.ai/bi-integrations) and create a new **Omni** integration.

**2. Map External IDs**

Open the Formal user → **External Connections**, click **Map External ID**,
select the Omni integration, and set the external ID to the user's
`omniOrganizationUserId` in Omni.

**3. Verify**

Run a query through Omni and check [Logs](https://app.formal.ai/logs) to confirm the end-user is correctly attributed.

> [!NOTE]
>
> Omni resolves end-user identity once per session at login time. All queries within that session are attributed to the resolved end-user. For more details on how this works at the Snowflake proxy level, see [Snowflake End-User Identity Propagation](https://docs.formal.ai/docs/guides/core-concepts/resources/snowflake.md#end-user-identity-propagation).

### Fivetran

Connect Fivetran to monitor data pipelines.

**1. Navigate to BI Integrations**

Go to [BI Integrations](https://app.formal.ai/bi-integrations) in the
Control Plane

**2. Add Integration**

Click **Create Integration**

**3. Select Fivetran**

Choose Fivetran from the list

**4. Enter Credentials**

* **Name**: A name for the integration
* **API Key**: Your Fivetran API key
* **API Secret**: Your Fivetran API secret

### Custom Applications

For internal applications or custom BI tools, use the **formal-sqlcommenter** library to propagate end-user identity.

#### Python/Django

Install the package:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
pip install formal-sqlcommenter
```

Use in your application:

```python theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
from formal_sqlcommenter import add_sql_comment
import psycopg2

# Connect as machine user
conn = psycopg2.connect(
    host="connector.joinformal.com",
    port=5432,
    user="idp:formal:machine:my_app",
    password="machine_user_token",
    database="production_db"
)

# Add end-user ID to queries
cursor = conn.cursor()
query = "SELECT * FROM users WHERE id = %s"

# This query will be attributed to the human user
commented_query = add_sql_comment(
    query,
    external_user_id="katie@example.com"  # End-user's Formal external ID
)

cursor.execute(commented_query, (123,))
```

## Configuring External IDs

External IDs map end-users in external systems to Formal users.

**1. Create Formal User**

Ensure a Formal user exists for the BI tool user

**2. Map External ID**

Open the Formal user → **External Connections**, then click **Map External
ID**. Choose the BI integration and enter the user's ID from the BI tool.
For example, if Katie's Looker user ID is `12345`, map `12345` to Katie's
Formal user.

**3. Verify**

Check [Logs](https://app.formal.ai/logs) to confirm queries are
attributed to the correct end-user

### Automatic Sync

For Metabase and Omni, the [BI sync worker](https://github.com/formalco/formal-metabase-sync-worker) runs in your infrastructure and:

1. Fetches user lists from the BI application
2. Matches them to Formal users by email
3. Assigns external IDs

Set `FREQUENCY` so users added to the BI tool later are mapped too.

## Policy Examples

### End-User Access Control

```rego theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
package formal.v2

import future.keywords.if
import future.keywords.in

# Block if end-user (not machine user) lacks access
session := {
  "action": "block",
  "type": "block_with_formal_message",
  "message": "You do not have permission to access this resource",
  "reason": "End-user not in approved group"
} if {
  # Connection is from BI tool (machine user)
  input.user.type == "machine"

  # End-user is not in analyst group
  not "analyst" in input.end_user.groups
}
```

### Per-User Data Masking

```rego theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
package formal.v2

import future.keywords.if
import future.keywords.in

# Mask PII unless end-user has special access
response := {
  "action": "mask",
  "type": "nullify",
  "columns": pii_columns
} if {
  # Identify PII columns
  pii_columns := [col |
    col := input.row[_]
    col["data_label"] in ["email_address", "social_security_number", "phone_number"]
  ]

  count(pii_columns) > 0

  # End-user doesn't have PII access
  not "pii_access" in input.end_user.groups
}
```

### Audit BI Tool Access

```rego theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
package formal.v2

import future.keywords.if

# Log all BI tool queries with end-user context
request := {
  "action": "allow",
  "reason": "BI tool query logged",
  "contextual_data": sprintf(
    "BI User: %s, Tool: %s, Query: %s",
    [input.end_user.email, input.user.username, input.sql_query.query]
  )
} if {
  input.user.type == "machine"
  startswith(input.user.username, "idp:formal:machine:")
}
```

## Monitoring

### View End-User Attribution

1. Navigate to [Logs](https://app.formal.ai/logs)
2. Filter by machine user (BI tool)
3. Check "End User" column to see attributed end-users
4. Verify queries are attributed correctly

### Session Details

In [Sessions](https://app.formal.ai/sessions), you'll see:

* **User**: Machine user (BI tool)
* **End-User**: Actual human user in the BI tool
* **Queries**: Full query history with end-user attribution

## Troubleshooting

> [accordion] Queries not attributed to end-users
>
> **Possible causes:**
>
> * BI integration not set up
> * External IDs not mapped
> * BI tool not passing end-user information
>
> **Solution:**
>
> 1. Verify the BI integration is active in the Control Plane
> 2. On the Formal user → **External Connections**, confirm the external ID matches the BI tool user ID
> 3. For Looker, verify JDBC parameters are configured
> 4. Review Connector logs for end-user extraction errors

> [accordion] Metabase sync not working
>
> **Possible causes:**
>
> * The sync worker isn't running, or ran once and exited because `FREQUENCY` isn't set
> * Incorrect Metabase credentials or API key in the worker's environment
> * `METABASE_BI_INTEGRATION_ID` doesn't match the integration in Formal
> * The worker can't reach Metabase or Formal
>
> **Solution:**
>
> 1. Check the worker's logs for authentication or connection errors
> 2. Verify the Metabase credentials the worker uses
> 3. Confirm `METABASE_BI_INTEGRATION_ID` is the integration's ID
> 4. Make sure the worker's network can reach Metabase and the Formal API

> [accordion] Policies not evaluating for end-users
>
> **Possible causes:**
>
> * Policy references `input.user` instead of `input.end_user`
> * End-user not in expected groups
>
> **Solution:**
>
> 1. Update policies to use `input.end_user` for BI tool queries
> 2. Verify end-user's group memberships in Control Plane
> 3. Test policy in dry-run mode and review logs

## Best Practices

> [accordion] Always Use End-User Policies
>
> For BI tools, write policies that evaluate `input.end_user` attributes, not
> `input.user` (which is the machine user).

> [accordion] Implement Row-Level Security
>
> Use end-user attributes to filter results, ensuring each BI user only sees
> data they're authorized to access.

> [accordion] Audit BI Access
>
> Regularly review logs to ensure end-user attribution is working and no queries
> are misattributed.

> [accordion] Sync Regularly
>
> For Metabase and Omni, keep the BI sync worker running with `FREQUENCY`
> set. For other BI tools and custom apps, update external IDs when users
> are added or removed.

## Next Steps

> [card] [Configure External IDs](https://docs.formal.ai/docs/guides/core-concepts/identities.md#external-ids-and-identity-propagation)
>
> Map BI users to Formal users

> [card] [Write Policies](https://docs.formal.ai/docs/guides/policies/introduction.md)
>
> Create end-user-based policies

> [card] [View Logs](https://docs.formal.ai/docs/guides/observability/logs.md)
>
> Monitor end-user queries


## Related topics

- [Integrations](https://docs.formal.ai/docs/guides/integrations/overview.md)
- [Protect Sensitive Data](https://docs.formal.ai/docs/guides/use-cases/protect-sensitive-data.md)
- [Apollo.io](https://docs.formal.ai/docs/guides/core-concepts/connectors/mcp-servers/apollo.md)
- [Policies](https://docs.formal.ai/docs/guides/policies/introduction.md)
- [Glossary](https://docs.formal.ai/docs/glossary/index.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.