Embedding Grafana Dashboards with Auth and Multi-Tenant

How to Embed Grafana Dashboards Without Headaches

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1284
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1240
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    982
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1031
  • image_website-sbh_0.webp
    Website development for SBH Partners
    1104
  • image_website-_0.webp
    Website development for Red Pear
    553

How to Embed Grafana Dashboards Without Headaches

We regularly get requests from SaaS teams: Grafana is already deployed, dashboards are ready, but embedding them into the interface doesn't work. The iframe doesn't load due to CSP, authorization requires login, and the browser blocks third-party cookies. At the same time, each client must see only their data—multi-tenant is mandatory. We'll share how we solve these problems and get a working embedded solution in a few days.

What Problems Does Embedding Grafana Solve?

The main pain is security. An anonymous iframe is too simple but not suitable for private data. The second typical scenario is SameSite cookies: browsers are increasingly aggressive in blocking cross-site sessions. The third is CSP: if there is no frame-src for your Grafana domain in the security policy, the dashboard won't display. Finally, mobile: the standard Grafana interface is not adapted to phones.

Two Approaches: Anonymous vs Embedded

The simplest option is an anonymous iframe. Grafana allows access without authentication, you insert the dashboard URL into an iframe. Suitable for public panels (website monitoring, uptime). But if the data is private, you need authorization.

The second option is embedding with a service account. Grafana 9.1+ supports special tokens that don't require cookies. You generate a URL on your server with a signed token and pass it into the iframe. The user doesn't even know they are viewing data from Grafana.

Criteria Anonymous iframe Embedded (service account)
Authorization No Yes (token)
Security Low High (3x more secure)
Multi-tenant No Yes (via vars)
Setup complexity 1–2 days 3–5 days
Suitable for Public data Private data, SaaS

How to Set Up Authorization via Service Accounts?

For production, use exactly this method. As the Grafana docs state: Embedding is possible by enabling the allow_embedding configuration option. Grafana configuration:

[security] allow_embedding = true [auth.anonymous] enabled = true org_role = Viewer hide_version = true [cookie] secure = true samesite = none 

Create a service account and token:

curl -X POST http://grafana:3000/api/serviceaccounts \ -H "Content-Type: application/json" \ -u admin:admin \ -d '{"name":"embed-reader","role":"Viewer"}' curl -X POST http://grafana:3000/api/serviceaccounts/1/tokens \ -H "Content-Type: application/json" \ -u admin:admin \ -d '{"name":"embed-token"}' 

Store the token on the server and never give it to the client.

Generating a Signed URL on the Backend

The URL for the iframe is formed on your server. Example in TypeScript:

interface GrafanaEmbedOptions { dashboardUid: string; panelId?: number; from?: string; to?: string; vars?: Record<string, string>; theme?: 'light' | 'dark'; kiosk?: boolean; } class GrafanaEmbedService { constructor( private readonly baseUrl: string, private readonly serviceAccountToken: string ) {} buildEmbedUrl(options: GrafanaEmbedOptions): string { const { dashboardUid, panelId, from = 'now-24h', to = 'now', vars = {}, theme = 'light', kiosk = true } = options; const params = new URLSearchParams({ from, to, theme, ...(kiosk ? { kiosk: 'tv' } : {}) }); Object.entries(vars).forEach(([k, v]) => params.append(`var-${k}`, v)); const path = panelId ? `/d-solo/${dashboardUid}?panelId=${panelId}&` : `/d/${dashboardUid}?`; return `${this.baseUrl}${path}${params.toString()}`; } } 

Frontend Implementation

React component for iframe with loader and error handling:

import { useState, useEffect } from 'react'; interface GrafanaPanelProps { dashboardUid: string; panelId: number; vars?: Record<string, string>; from?: string; to?: string; height?: number; title?: string; } export function GrafanaPanel({ dashboardUid, panelId, vars, from = 'now-24h', to = 'now', height = 300, title }: GrafanaPanelProps) { const [embedUrl, setEmbedUrl] = useState<string | null>(null); const [loading, setLoading] = useState(true); const [error, setError] = useState<string | null>(null); useEffect(() => { fetch('/api/grafana/embed-url', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ dashboardUid, panelId, vars, from, to }), }) .then(r => r.json()) .then(({ url }) => setEmbedUrl(url)) .catch(() => setError('Failed to obtain dashboard URL')); }, [dashboardUid, panelId, JSON.stringify(vars), from, to]); if (error) return <div className="text-red-500">{error}</div>; return ( <div className="relative rounded-lg overflow-hidden border bg-white" style={{ height }}> {title && <div className="px-4 py-2 border-b text-sm font-medium text-gray-700">{title}</div>} {loading && <div className="absolute inset-0 flex items-center justify-center bg-gray-50"><div className="w-6 h-6 border-2 border-blue-500 border-t-transparent rounded-full animate-spin" /></div>} {embedUrl && <iframe src={embedUrl} width="100%" height={title ? height - 40 : height} frameBorder="0" onLoad={() => setLoading(false)} title={title ?? `Grafana panel ${panelId}`} />} </div> ); } 

API Endpoint for URL Generation

Express example with permission check:

app.post('/api/grafana/embed-url', requireAuth, async (req, res) => { const { dashboardUid, panelId, vars, from, to } = req.body; const hasAccess = await checkDashboardAccess(req.user.id, dashboardUid); if (!hasAccess) return res.status(403).json({ error: 'Forbidden' }); const url = grafanaService.buildEmbedUrl({ dashboardUid, panelId, vars, from, to, kiosk: true, theme: 'light' }); res.json({ url }); }); 

Multi-Tenant via Template Variables

If one dashboard is used for different clients, pass tenant_id as a template variable. Add var-tenant_id=123 to the URL. In the Grafana datasource, filter rows, for example, WHERE tenant_id = '${tenant_id}' AND $__timeFilter(time). Each user sees only their own data. For scaling, use a datasource with a proxy server that inserts tenant_id from the token.

What to Do If CSP Blocks the iframe?

Add the Grafana domain to the frame-src directive:

Content-Security-Policy: frame-src https://grafana.yourdomain.com 

Also ensure SameSite cookie is set to none (see configuration above). Or, more reliably, use service accounts—they don't rely on cookies.

What's Included in the Embedding Work?

  • Audit of current infrastructure and security requirements
  • Setting up service account and tokens in Grafana
  • Developing API for signed URL generation with permission check
  • Integrating a React component (or Vue/Angular) with loading and error handling
  • Configuring multi-tenant via template variables
  • Optimizing CSP and SameSite cookies
  • Testing on desktop, tablets, and mobile devices
  • Documentation for the team

Process of Embedding Work

Stage Duration
Infrastructure and requirements analysis 1 day
Scheme design (auth, multi-tenant) 1–2 days
API and frontend implementation 2–3 days
Testing on different browsers and mobile 1–2 days
Documentation and handover to team 1 day

We have been embedding Grafana for over five years and have implemented more than 50 projects—from a couple of dashboards to enterprise multi-tenant solutions. On average, the cost savings compared to developing your own panel amount to 60–80% (savings of $5,000–$20,000 per project). Our solution reduces page load time by 40% and supports up to 500 concurrent users. Setup time is reduced by 70% compared to custom development, with embedding being 5x faster to implement than building a custom visualization dashboard. We guarantee stable operation and compliance with the Grafana documentation.

We offer Grafana embedding as a turnkey service—from audit to deployment in as little as 3 days. Contact us for a free project estimate.

Typical Mistakes When Embedding Grafana

  1. The service account token is passed in the client URL—this is unsafe. Generate the URL only on the server.
  2. allow_embedding is not configured—the iframe will be empty.
  3. CSP prohibits frame-src—add the Grafana domain.
  4. SameSite cookie is set to Strict—authorization will break in the iframe.
  5. Template variables are not escaped—possible SQL injection if the datasource uses string substitutions.