This project provides a secure proxy solution for accessing Grafana dashboards, along with a management API for configuring tenants, API keys, and dashboard permissions.
GrafanaProxy.Web: An ASP.NET Core application acting as a YARP (Yet Another Reverse Proxy) reverse proxy. It authenticates incoming requests using API keys and forwards authorized requests to the appropriate Grafana public dashboard endpoint based on tenant permissions.GrafanaProxy.Management.Api: A separate ASP.NET Core Web API intended for internal use. It provides endpoints for managing tenants, generating/regenerating API keys, and assigning dashboard permissions to tenants.
- Tenant-based access control for Grafana dashboards.
- API key authentication for proxy access.
- Management API for configuration.
- SQLite database for storing configuration (tenants, keys, permissions).
- Dockerized for easy deployment.
- GitHub Actions workflow for building and pushing Docker images to Docker Hub on version tags (
v*.*.*).
- .NET 9 SDK
- Docker & Docker Compose
The easiest way to run both applications locally is using Docker Compose:
-
Clone the repository:
git clone https://github.com/bjth/grafana-proxy.git cd grafana-proxy -
(Optional) Configure HTTPS Development Certificate: Ensure you have ASP.NET Core development certificates trusted:
dotnet dev-certs https --trust
If your certificate requires a password, set the
KESTREL_CERT_PASSWORDenvironment variable (e.g., in a.envfile in the project root). -
Run Docker Compose: From the project root directory:
docker-compose -f build/docker/docker-compose.yml up --build
This will:
- Build the Docker images for both applications.
- Create a Docker volume (
grafana_proxy_data) to store the sharedgrafana_proxy_config.dbSQLite database. - Start containers for both applications.
Access Points:
- Web Proxy:
http://localhost:8080/https://localhost:8081 - Management API:
http://localhost:8090/https://localhost:8091 - Management API Swagger UI:
http://localhost:8090/swaggerorhttps://localhost:8091/swagger
You can also run the applications directly using the .NET CLI:
- Run Management API:
dotnet run --project src/GrafanaProxy.Management.Api/GrafanaProxy.Management.Api.csproj
- Run Web Proxy (in a separate terminal):
(Note: The database file
dotnet run --project src/GrafanaProxy.Web/GrafanaProxy.Web.csproj
src/grafana_proxy_config.dbwill be created relative to thesrcdirectory when running this way). Fix the YARP HealthCheck issue if running this way.
A Postman collection for testing the Management API endpoints is located at tests/integration/GrafanaProxy.Management.postman_collection.json.
- Ensure the Management API is running (either via
docker-compose upordotnet run). - Import the collection file into Postman.
- The collection uses a variable
{{baseUrl}}which defaults tohttp://localhost:8090. Adjust this variable in Postman if your API is running on a different address (e.g.,https://localhost:8091). - Run the requests individually or use the Postman Collection Runner to execute them in sequence.
- The
Create Tenantrequest uses random data and saves the created tenant's ID and ShortCode to collection variables. - Subsequent requests use these variables to target the created tenant.
- The
- Database: Configuration (tenants, keys, permissions) is stored in a SQLite database (
grafana_proxy_config.db). When running via Docker Compose, this is stored in thegrafana_proxy_datavolume. - YARP & Grafana URL: The reverse proxy configuration (routes, clusters) is defined in
src/GrafanaProxy.Web/appsettings.json.- When running via Docker Compose, the Grafana destination address can be overridden by setting the
GRAFANA_URLenvironment variable (e.g., in a.envfile in the project root). It defaults tohttps://play.grafana.org/if not set. - If running directly (
dotnet run), you might need to adjust the Grafana destination address (clusters.grafana-cluster.destinations.destination1.address) inappsettings.jsonand potentially the health check policy (clusters.grafana-cluster.HealthCheck.Active.Policy) if you encounter startup errors likeNo matching IActiveHealthCheckPolicy found.
- When running via Docker Compose, the Grafana destination address can be overridden by setting the
- API Keys: Use the Management API (
POST /api/tenants) to create tenants and initial API keys. - Dashboard Permissions: Use the Management API (
POST /api/tenants/{tenantId}/dashboards) to grant tenants access to specific Grafana dashboard UIDs.
A GitHub Actions workflow (.github/workflows/docker-publish.yml) is configured to:
- Build Docker images for both applications.
- Push images to Docker Hub (
<your-username>/grafana-proxyand<your-username>/grafana-proxy-api) when a tag matchingv*.*.*is pushed to themainbranch. - Requires
DOCKERHUB_USERNAMEandDOCKERHUB_TOKENsecrets to be configured in the GitHub repository settings.
(Add contribution guidelines if applicable)
(Add license information if applicable)