Many users are getting the “401: Unauthorized” error when embedding Grafana into an iframe card.
The community suggests adding GF_AUTH_ANONYMOUS_ENABLED or GF_SECURITY_ALLOW_EMBEDDING to Grafana configration, but this did not solve the problem in my environment.
Finally, I found another solution and I’ll share it with the community.
In my environment, I use Nginx Proxy Manager, Let’s Encrypt, Google Cloud DNS, and Home Assistant OS, but I think this method will work for other DNS services and reverse proxy based environments.
Create Proxy Host for Grafana
-
Create a proxy host that supports Grafana’s port
-
Set the letsencrypt SSL Certificate.
-
You will see the following screen.
- Home Assistant: port 8123
- Grafana: port 3000.
Configure Grafana
Open the Grafana settings page in Supervisor and configure the ports. (no need to change Option)
Create a view only user
-
Open “Grafana Web UI > Configuration > Users”
-
Click “Invite” and create a new user
-
Click “Submit”
-
Click “Pending Invites”, then “Copy Invite”
The invitation code of the clipboard should look like this.
http://localhost:3000/api/hassio_ingress/xxxxxx-yyyyyy/invite/zzzzzzz
Change “htt://localhost:3000” to the domain you assigned. (Don’t forget to change http to https)
https://grafana.your-domain.tld/api/hassio_ingress/xxxxxx-yyyyyy/invite/zzzzzzz -
Access the modified invitation URL and enter your username and password to create a user.
Configure an iframe card
- Set the ingress url for the iframe card with the Grafana url, not the Home Assistant url.
- type: iframe
url: >-
https://grafana.your-domain.tld/api/hassio_ingress/xxxxxx-xxxxxx/d/xxxx-xxxx/sensor-monitor?orgId=1&from=now-24h&to=now&fullscreen&kiosk=1&refresh=30s
aspect_ratio: 200%
-
When you access the Loverace dashboard with the iframe card, you will see the Grafana login page and login with the viewer account you created.
-
Now you can access Grafana embedded in the iframe card.