Govern

Embedded analytics

Mint signed embed tokens, drop a Goni chart or dashboard into a third-party app, and keep row filters and column masks intact.

Drop a Goni chart or dashboard into your own app with a signed token that carries the viewer’s identity, allow-list, row filters, and column masks.

You’ll learn:

  • How to mint an embed token with POST /api/embed/token
  • How the /embed and /embed/dashboard routes render chromeless
  • How row filters and column masks stay identical to the interactive UI
  • How to debug a token with GET /api/embed/decode
  • How to revoke a live token with POST /api/embed/{jti}/revoke
  • Rate-limit behaviour and the security caveats bearer tokens inherit

What an embed token is

An embed token is an HS256-signed JWT. Goni signs it with GONI_EMBED_SECRET and verifies it on every request the iframe makes. The claim body carries the subject user, an allow-list of metrics, models, dashboards, charts, and queries the viewer may address, and per-table row filters and column masks. Those claims become the request’s EffectivePermissions on the server, so the same access-control gate that runs for an interactive user runs for an embed viewer.

The signer is initialised from GONI_EMBED_SECRET at boot. Production must set a real value; every token minted before rotation stays valid on every replica until it expires.

Mint a token

The mint endpoint is admin-only. It requires the allow_admin_policies capability, not allow_save, because a token is a bearer credential handed to a third party.

curl -X POST https://your-goni-host/api/embed/token \
  -H "Authorization: Bearer <admin-pat>" \
  -H "Content-Type: application/json" \
  -d '{
    "sub": "acme-corp-tenant-42",
    "name": "Acme Corp",
    "roles": ["viewer"],
    "metrics": ["active_arr", "active_customers"],
    "row_filters": {
      "marts_semantic.fct_subscriptions": "country = '\''LT'\''",
      "marts_semantic.dim_customers":     "country = '\''LT'\''"
    },
    "ttl_seconds": 86400
  }'

Response:

{
  "token": "eyJhbGciOi...",
  "expires_at": "2026-08-14T09:00:00Z",
  "ttl_seconds": 86400,
  "embed_url_template": "/embed?metric=<METRIC>&dims=<COMMA_SEP>&grain=<day|week|month|quarter|year>&token=...",
  "jti": "5c6f5e8a1b2c3d4e5f60718293a4b5c6",
  "api_usage_hint": "send Authorization: Bearer <token> OR query ?embed_token=<token>"
}

Persist the returned jti alongside the audience it was minted for; you’ll need it to call the revoke endpoint below if the token leaks or the audience is off-boarded.

Request fields

FieldPurpose
subSubject id. Required. Bound into the JWT as the viewer’s identity for audit.
nameDisplay name. Falls back to sub if omitted.
rolesRole labels baked into the claim. Used only when the explicit allow-lists below are empty.
metrics, models, dashboards, charts, queriesAllow-lists. At least one must be non-empty. Use ["*"] for full access; empty means deny-all for that resource class.
row_filtersMap of <schema>.<table> to a SQL predicate. AND-merged into every query touching that table.
col_masksNested map: col_masks[table][column] = sql_expr. Rewrites the column at read time (e.g. sha256(email)).
row_filters_optionalExplicit attestation. When row_filters is empty and this is not true, the API returns 400.
passwordOptional password gate. When set, viewers must send X-Embed-Password or ?embed_password=. Stored on the token as a hex SHA-256 salted with the signing secret (never plaintext).
workspace_idBinds the token to a single workspace. Downstream canAccessWorkspace refuses any artifact outside this workspace; an empty value means “any workspace the caller’s roles permit”.
ttl_secondsDefaults to 24 hours. Server clamps to a 7-day ceiling. Override the ceiling per instance with GONI_EMBED_MAX_TTL_SECONDS - see Environment variables.

The row_filters_optional flag is consumed at mint time only. It never enters the JWT. Its purpose is to stop an admin from silently shipping a full-tenant read by forgetting the row_filters field.

Note: Embed tokens are read-only. AllowSave and AllowDelete are cleared on every token regardless of what the caller asks for.

Frame the iframe

Two chromeless routes render without the layout, sidebar, or topbar:

  • GET /embed?metric=<name>&dims=<comma-sep>&grain=<day|week|month|quarter|year>&limit=<n>&token=<jwt> renders a single metric chart. The /embed page reads ?token= from its own URL and re-sends it as Authorization: Bearer <token> on every /api/* fetch. Parent sites do not need to inject headers into the iframe.
  • GET /embed/dashboard?id=<dashboard-id>#token=<jwt> renders a full dashboard. The token lives in the URL fragment (never sent to the server, never in access logs) and is re-sent as Authorization: Bearer <token> on every /api/* fetch the dashboard fires. Legacy ?token= in the query string is still accepted for pre-2026-08 embeds.

When calling /api/* endpoints directly (no /embed shell in the middle), send the token as either Authorization: Bearer <token> or as the query parameter ?embed_token=<token>. Note that the query key is embed_token, not token; only the /embed HTML shell recognises ?token=.

Iframe origin pinning. The /embed* routes are served with Content-Security-Policy: frame-ancestors * so any origin can iframe them; parent-site origin restriction has to be enforced by the customer’s own reverse proxy or by pinning frame-ancestors at the CDN in front of Goni.

Minimal embed:

<iframe
  src="https://goni.example.com/embed?metric=active_arr&dims=country&grain=week#token=eyJhbGciOi..."
  width="100%"
  height="500"
  frameborder="0">
</iframe>

Or for a dashboard:

<iframe
  src="https://goni.example.com/embed/dashboard?id=exec-overview#token=eyJhbGciOi..."
  width="100%"
  height="800"
  frameborder="0">
</iframe>

RBAC parity

The claim’s row_filters and col_masks are copied into the request’s EffectivePermissions. The metric compiler, chart endpoint, and dashboard endpoint all read those same fields, so an embed viewer runs through the exact same policy gate as an interactive user of the access-control system.

Three properties are worth pinning:

  1. Empty allow-lists are deny-all, not wildcard. If you mint a token with metrics: ["active_arr"] and no dashboards, that token cannot open a dashboard.
  2. dashboards with no explicit charts implies charts: ["*"], because an allowlisted dashboard has to render its constituent charts.
  3. Column masks are deep-copied into the permission struct. A handler mutating a mask on one request cannot corrupt the JWT-supplied mask for the next.

Debug a token

The decode endpoint is the fastest way to inspect what a token actually carries. It is gated on the same allow_admin_policies capability as mint, because the decoded body exposes the row filter and allow-list.

curl "https://your-goni-host/api/embed/decode?token=eyJhbGciOi..." \
  -H "Authorization: Bearer <admin-pat>"

The response is the full claim payload:

  • sub, name, roles - viewer identity and the label baked into the JWT
  • metrics, models, dashboards, charts, queries - allow-lists (empty means deny-all for that resource class)
  • row_filters, col_masks - the per-table row filter and column mask maps enforced on every query
  • tenant_id - the caller’s tenant, pinned at mint time (empty on legacy pre-2026-08-21 tokens)
  • workspace_id - workspace binding (empty means “any workspace the roles permit”)
  • kind - empty for embed tokens; pat for personal access tokens
  • jti - the revocation id; pass this to POST /api/embed/{jti}/revoke
  • pwd - hex SHA-256 of the salted password when the token has a password gate. Not the plaintext, but still sensitive: it can be brute-forced offline and it tells you a password gate exists
  • iat, exp, iss - issuance / expiry / issuer

Because the decoded body exposes row filters, allow-lists, and the salted password hash, decode is admin-only and every call (success or failure) is written to the audit log under the embed.decode action.

Build one from the UI

The Goni app ships an admin page at /embed-builder that wires the fields above into a form, mints a token, and renders a live iframe preview. It surfaces:

  • Multi-select metrics (first is the preview metric)
  • Row filter table + predicate, plus the explicit cross-tenant attestation checkbox
  • A column-mask editor: table.column -> sql expr rows
  • Password gate
  • TTL input with a preemptive warning when the requested value exceeds the 7-day server ceiling (or the narrower ceiling set via GONI_EMBED_MAX_TTL_SECONDS)
  • A copyable <iframe> snippet

Use it when handing an embed to a partner without touching curl.

Revoke a token

Every mint returns a jti (JWT id). Push it to the revocation endpoint to burn the token from every replica without restart or secret rotation:

curl -X POST https://your-goni-host/api/embed/{jti}/revoke \
  -H "Authorization: Bearer <admin-pat>"

Response: {"jti": "...", "status": "revoked"}. The endpoint is admin-only (allow_admin_policies), idempotent (calling twice is a no-op), and writes an embed.revoke audit row on both the ok and fail branches. The revocation entry lives in Redis with a TTL matching the signer’s max-age, so it evicts naturally once no valid token could still carry that jti - you don’t need to clean it up. Requires the control-plane Redis to be reachable; the endpoint returns 503 if the revocation store is not wired.

If you didn’t save the jti at mint time, decode any live copy of the token via GET /api/embed/decode (above) - the jti claim is in the response.

Vanilla-JS SDK

For a slightly higher-level integration than a raw <iframe> tag, drop the goni-embed.js script tag and instantiate GoniEmbed. It handles auto-resize, click events, and postMessage origin pinning to your Goni base URL:

<div id="acme-dashboard"></div>
<script src="https://your-goni-host/goni-embed.js"></script>
<script>
  const e = new GoniEmbed({
    container: document.getElementById("acme-dashboard"),
    base:      "https://your-goni-host",
    dashboard: "exec-overview",
    token:     "<JWT minted via POST /api/embed/token>",
    autoResize: true,
  });
  e.on("tile-click", (msg) => console.log("clicked", msg.tile, msg.name));
  e.on("ready",      (msg) => console.log("loaded", msg.dashboard));
  e.on("error",      (msg) => console.warn("embed error", msg.message));
</script>

Fields: container (DOM node), base (Goni origin), token (JWT), and one of dashboard (id) or metric (name) plus optional dimensions, grain, theme (dark/light), height, autoResize. Events: ready, height, tile-click, error, or * for a firehose.

The SDK ships with the Goni web app; no npm install is required. Serve goni-embed.js from your Goni origin with a modest Cache-Control: public, max-age=3600. Never expose GONI_EMBED_SECRET to the browser - mint tokens from a backend and hand only the JWT to the SDK.

Rate limiting

Embed requests share the heavy / cheap / auth budgets described in Environment variables and REST API - Rate limiting. The bucket key is the token’s sub claim, so every viewer under a single mint (e.g. every user of one partner’s app) shares one budget; a chatty embed can push the audience past heavy and start returning 429s to the rest. Split high-fan-out audiences into per-user sub values, or raise GONI_RATE_HEAVY_BURST / GONI_RATE_HEAVY_RPS at the deployment if a large embed rollout needs more headroom than an interactive workspace.

Security caveats

Embed tokens are bearer credentials. A few operational realities the mint flow does not enforce for you:

  • Token in the URL is sensitive. The ?token= on /embed?... and the #token= fragment on /embed/dashboard?... end up in server access logs (for the query-string variant), browser history, and the Referer header of any outbound link the embed page renders. Scrub token / embed_token from your reverse-proxy access log format, keep the embed iframe on a page that does not send Referer cross-origin, and prefer the dashboard route’s fragment form (never sent to the server) when the choice exists.
  • TLS everywhere. JWTs in query strings and Bearer headers must never traverse plain HTTP. Terminate TLS at the edge and reject http:// origins.
  • Recommended CSP on the parent page. On the customer-app page that hosts the iframe, set Content-Security-Policy: frame-src https://your-goni-host so a compromised parent script cannot swap the iframe origin. If you need per-token frame-ancestors pinning on Goni’s side, put a reverse proxy in front of /embed* and rewrite the CSP header from a per-tenant allow-list.
  • Claims are baked in at mint. Row filters, column masks, allow-lists, and workspace binding are fixed for the token’s lifetime. A mid-session role change - user removed from the audience, workspace re-pinned, row filter tightened - takes effect only after the token is revoked (see above) or expires. Short TTLs are the primary lever.
  • Secret rotation. Rotate GONI_EMBED_SECRET by putting the new value into GONI_EMBED_SECRET, moving the old value into GONI_EMBED_SECRET_PREV, and redeploying. Verify accepts both secrets for one TTL window; Mint always uses the new secret. Drop GONI_EMBED_SECRET_PREV once the window (default 7 days) elapses. A cold rotation without the overlap window invalidates every outstanding token at the moment of redeploy.
  • Decode is a privileged read. The decode endpoint returns row filters, allow-lists, and the salted password hash of any token whose signature a caller can supply. Keep the admin PAT that gates it out of any shared tool that logs request bodies.

Last updated