Agent Wranglers

DEN-31Required

Filter shared dashboards by customer inside the warehouse

When customers see dashboards built on shared tables, filter rows by customer in the warehouse or in a signed embed token. Never rely on a filter set in the dashboard alone.

How to do it

A dashboard filter can be changed in the address or removed by an edit. Use the warehouse's row access policies, or a view per customer, keyed on a customer ID that your server signs into the embed token. It is Keep each customer's data apart applied to analytics. Search follows the same idea in Filter search results by access inside the query. Give each token a lifetime of 10 minutes or less.

Examples

Python example

import time
import jwt

EMBED_LIFETIME_SECONDS = 600

def embed_token(secret: str, dashboard_id: str, customer_id: str) -> str:
    claims = {"dashboard": dashboard_id, "customer_id": customer_id, "exp": int(time.time()) + EMBED_LIFETIME_SECONDS}
    return jwt.encode(claims, secret, algorithm="HS256")

JavaScript example

import jwt from 'jsonwebtoken';

const EMBED_LIFETIME_SECONDS = 600;

export const embedToken = (secret, dashboardId, customerId) =>
  jwt.sign({ dashboard: dashboardId, customer_id: customerId }, secret, { algorithm: 'HS256', expiresIn: EMBED_LIFETIME_SECONDS });

How to check

Open an embedded dashboard as customer A, then change the customer ID to B's in the address and in the data request. No row of B's appears.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/data-engineering/access-and-bi-tools/dashboard-row-security">Agent Wranglers data engineering playbook</a>. In code you write, add a comment next to it with the same link.