feat: add browser-based SSO authentication#646
feat: add browser-based SSO authentication#646solganik wants to merge 7 commits intografana:mainfrom
Conversation
|
|
e47d093 to
aa4832b
Compare
Add chromedp-based browser login flow that opens a real browser window for SSO authentication, captures the grafana_session cookie, and persists it to disk. Includes automatic re-authentication on 401 responses via a custom http.RoundTripper middleware. New files: - auth/browser.go: chromedp browser login with persistent Chrome profile - auth/session_store.go: cookie persistence to ~/.config/mcp-grafana/ - auth/transport.go: SessionAuthTransport with auto 401 re-login Modified: - cmd/mcp-grafana/main.go: --browser-auth CLI flag - mcpgrafana.go: wire browser auth transport into Grafana client
aa4832b to
5983064
Compare
…oard/panel deeplinks When generating dashboard or panel deeplinks, callers previously had to know the exact internal value for var-datasource, which differs from both the datasource display name and UID. Now, passing datasourceUid for dashboard/panel types auto-fetches the dashboard JSON, finds the datasource-type template variable, looks up the datasource by UID, and injects the correct var-<name>=<value> into the URL. Also documents that TimeRange must use relative or epoch ms format (not ISO timestamps, which Grafana silently ignores).
…riable substitution (grafana#539) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
…#649) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
New tool `render_panel_image_local` renders Grafana dashboard panels as PNG screenshots using local headless Chromium (chromedp). Does not require the Grafana Image Renderer plugin to be installed server-side. Uses browser SSO session cookie for authentication, monitors network activity via CDP to detect panel readiness (waits for all HTTP requests to complete + quiet period), and disables auto-refresh to prevent infinite network activity during rendering. Supports datasourceUid for auto-resolving the datasource template variable, matching the generate_deeplink improvement.
…ore deeplinks Add extraJSON field to ExploreQuery that allows passing arbitrary datasource-specific properties (query, metrics, bucketAggs, timeField) directly into the query object. This enables generating working Explore deeplinks for Elasticsearch-based datasources like Coralogix, which use a different query structure than PromQL/LogQL datasources.
| }) | ||
|
|
||
| return result | ||
| } |
There was a problem hiding this comment.
Duplicate variable substitution logic across two functions
Low Severity
The new substituteVariables in dashboard_helpers.go and the existing substituteTemplateVariables in run_panel_query.go both replace the same three Grafana template variable patterns (${varname}, $varname, [[varname]]) with different implementations. The new version additionally handles ${varname:option} but otherwise serves the same purpose. This duplication increases maintenance burden and risks inconsistent behavior.


Add chromedp-based browser login flow that opens a real browser window for SSO authentication, captures the grafana_session cookie, and persists it to disk. Includes automatic re-authentication on 401 responses via a custom http.RoundTripper middleware.
New files:
Modified:
Note
High Risk
Introduces cookie-based authentication with automated browser login and persistence, and injects it into all Grafana HTTP traffic; mistakes here could leak sessions or break auth across requests. Also adds chromedp-based local rendering and expands query/deeplink generation logic, increasing dependency and behavioral surface area.
Overview
Adds browser-based SSO authentication as an alternative to API tokens: a new
authpackage drives a chromedp login flow, captures thegrafana_sessioncookie, persists it to~/.config/mcp-grafana/sessions.json, and injects/refreshes it via aSessionAuthTransportthat auto re-logins on401(enabled via--browser-authorGRAFANA_AUTH_BROWSER).Expands tooling around dashboards and navigation:
get_dashboard_panel_queriesnow supportspanelIdfiltering, row-nested panels, multi-datasource query extraction, and optional template variable substitution withprocessedQuery/requiredVariables;generate_deeplinknow builds full Exploreleftstate (including queries and embedded time range) and can auto-resolve dashboard datasource template variables from a provideddatasourceUid.Adds
render_panel_image_local, a new headless-Chrome screenshot renderer that uses the stored SSO session (no Grafana Image Renderer plugin), and wires it into rendering tools. Updates transports to ensureOrgIDis consistently applied and adds/updates unit/integration tests, plus newchromedpdependencies and changelog entry for0.11.3.Written by Cursor Bugbot for commit 0db86dc. This will update automatically on new commits. Configure here.