Grafana Dashboards As Code

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up grafana dashboards as code by saving chart files in Git. Then, an automated tool pushes those saved files to your server. Many teams start by clicking buttons in the web app to build charts. Over time, people make manual edits that break shared views and alerts. Moving these files to version control stops random changes and tracks every update. Still, broad server roles still let users run unsafe queries against live data. How to set up grafana dashboards as code In a normal setup,

Infrastructure as Code Security Scanning + Grafana Access Control: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You set up grafana dashboards as code by saving chart files in Git. Then, an automated tool pushes those saved files to your server. Many teams start by clicking buttons in the web app to build charts. Over time, people make manual edits that break shared views and alerts. Moving these files to version control stops random changes and tracks every update. Still, broad server roles still let users run unsafe queries against live data.

How to set up grafana dashboards as code

In a normal setup, every chart is just a structured text file. This text file holds the layout, colors, and queries for each panel. Instead of editing charts in the browser, engineers write these files locally. Some teams write raw text files, while others use code libraries to generate them. Code libraries let you reuse common panels across many different services.

Once an engineer finishes a change, they open a pull request in Git. Teammates check the diff to spot bad queries or broken layout rules. After the team approves the change, a pipeline job runs. This job connects to the server API or drops files into a watched folder. The server reads the new files and updates the live charts right away.

To keep this workflow clean, teams turn off manual saving in the web app. If someone tries to edit a provisioned chart in the browser, the system blocks the save. This forces all changes to go through the Git review process first. You get a clear history of who changed a chart and why they did it.

What native provisioning solves and what it misses

Managing charts in Git solves the problem of lost work and broken views. If a bad deploy breaks a chart, you can roll back the commit in seconds. You can also spin up a fresh server and load all your charts at once. New apps get standard monitoring views on day one without manual click work.

Still, file provisioning only controls how charts get onto the server. It does not control how the server talks to your databases or what data returns. The server still needs a stored database password or key to run panel queries. Often, teams give the charting tool a broad database role so every query works.

Infrastructure as Code Security Scanning + Grafana Access Control: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

This creates a major gap when engineers use the explore view or test new panels. Anyone with editor rights on the server can write raw queries against that shared database role. Native roles decide who logs in to the chart app, not what individual queries do in flight. If a query hits a table with customer emails or card numbers, the database sends them back. Static setup files cannot rewrite sensitive fields in results or block heavy queries before they run.

Keeping data sources safe during chart updates

To reduce risk, teams must look beyond the Git pipeline and check data source permissions. First, create read-only database users for your chart server. Never share the main app write role with your reporting tools. Second, limit that read role to specific views or tables that hold safe metrics.

Even with read-only roles, engineers often need to inspect production logs or user tables during an incident. When they query these sources through a chart panel, sensitive fields can leak onto shared screens. Protecting these live queries requires controls that inspect traffic in flight and mask fields like phone numbers or national IDs.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Can we still test chart changes in the browser first?

Yes, engineers often build a draft chart in a local test app using the browser. Once the layout looks right, they export the text file and commit it to Git.

How do we handle secrets in provisioned data source files?

Never save plain database passwords or API keys inside your Git repo. Use secret variables that the server reads from a secure store when it boots up.

What happens if someone edits a provisioned chart in the UI?

The server blocks permanent saves on provisioned charts by default. Even if someone bypasses this, the next pipeline run will overwrite their manual change with the Git file.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.