feat(grafana): auth proxy + per-user PostgreSQL datasources#41
Merged
Conversation
- grafana/provisioning/datasources/postgres.yml: replace single myuser datasource with per-user datasources (demo_openmrg, demo_orange_cameroun) each connecting as the matching PG login role, plus an admin datasource connecting as webserver_role for cross-tenant operator dashboards. - docker-compose.yml: enable Grafana auth proxy mode (GF_AUTH_PROXY_ENABLED), trust X-WEBAUTH-USER header from the webserver container only (GF_AUTH_PROXY_WHITELIST=webserver), disable anonymous access and the Grafana login form. - webserver/main.py (grafana_proxy): strip any X-WEBAUTH-USER header supplied by the browser (prevents identity forgery), then inject current_user.id so Grafana maps the request to the correct Grafana user. Data isolation chain: Flask session → X-WEBAUTH-USER → Grafana user → per-user datasource → PG role → RLS / security-barrier views
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #41 +/- ##
==========================================
+ Coverage 81.18% 81.58% +0.39%
==========================================
Files 24 24
Lines 2371 2373 +2
==========================================
+ Hits 1925 1936 +11
+ Misses 446 437 -9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
GF_AUTH_PROXY_WHITELIST requires IP/CIDR notation; passing the service hostname 'webserver' caused Grafana to log: 'could not parse the network: invalid CIDR address: webserver/32' and silently skip auth proxy initialization entirely. All iframe requests therefore arrived as anonymous (userId=0) and were redirected to the Grafana welcome page instead of the dashboard. Fix: remove the whitelist entry and the host port-3000 mapping. Port 3000 is now only reachable from within the Docker Compose network, providing equivalent isolation without the broken setting.
- docker-compose.yml: fix Grafana healthcheck regex; add init_grafana service that bootstraps org 2 via API on startup - grafana/init_grafana.py: new bootstrap script - creates org 2, datasource, copies dashboards from org 1, creates tenant users - grafana/Dockerfile: image for init_grafana service - grafana/provisioning/dashboards/dashboards.yml: remove org 2 entry (was crashing Grafana at startup with org.notFound); org 2 handled by init_grafana - grafana/provisioning/datasources/postgres.yml: remove org 2 entry (same reason); simplify org 1 config - grafana/provisioning/dashboards/definitions/*.json: replace cml_data_1h aggregate with cml_data_1h_secure security-barrier view so tenant DB roles can query without permission errors - webserver/configs/users.json: add grafana_org_id field per user - webserver/main.py: read grafana_org_id from user config; pass to tem- webserver/main.py: read grafana_org_id from user config; pass to tem- webserver/main.py: read grafana_org_id from user config; patml- webserver/main.py: read grafana_org_id from user config; pass to tem- websing migration
…orized_keys setup - Refactored generate_ssh_keys.sh to loop over tenants, generate keys, and set up per-tenant authorized_keys - Ensured idempotency and clear output for onboarding new tenants - Updated authorized_keys for demo_openmrg and demo_orange_cameroun - Validated SFTP upload and stack health after changes This commit ensures robust, automated SSH key management for all tenants.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
This PR implements secure, multi-tenant support for Grafana and SFTP onboarding, with the following major changes:
Grafana Authentication Proxy & Per-User Datasources
demo_openmrg,demo_orange_cameroun) is mapped to a dedicated PostgreSQL login role and Grafana datasource.X-WEBAUTH-USERheader, ensuring requests are mapped to the correct Grafana user and data source.Grafana Proxy Security & Testing
X-WEBAUTH-USERheader supplied by the browser to prevent identity forgery.Security Fixes
GF_AUTH_PROXY_WHITELISTto avoid using an invalid hostname (webserver), which caused Grafana to skip proxy initialization and broke authentication.Multi-Tenant Grafana Setup
init_grafanaservice and bootstrap script to automate onboarding of additional organizations (org 2) via the Grafana API.grafana_org_idfor correct org mapping.Documentation
Automated SSH Key Management
authorized_keyssetup (commit not shown in full log above but present in branch).