grafana iframe 接入备忘录

iframe 引入

部分配置修改后才能进行 iframe 嵌入,默认是不支持的

1
2
3
allow_embedding: true # 默认是 false, 为了防止 Clickjacking,如果不设置,浏览器会拒绝显示 iframe
cookie_samesite: none # 如果不设置,无法使用登录功能
cookie_secure: true # if you're using https and let us know how that works out.

配置说明 https://grafana.com/docs/grafana/latest/administration/configuration/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cookie_secure
Set to true if you host Grafana behind HTTPS. Default is false.

cookie_samesite
Sets the SameSite cookie attribute and prevents the browser from sending this cookie along with cross-site requests.
The main goal is to mitigate the risk of cross-origin information leakage.
This setting also provides some protection against cross-site request forgery attacks (CSRF), read more about SameSite here.
Valid values are lax, strict, none, and disabled. Default is lax.
Using value disabled does not add any SameSite attribute to cookies.

allow_embedding
When false, the HTTP header X-Frame-Options: deny will be set in Grafana HTTP responses which will instruct browsers
to not allow rendering Grafana in a <frame>, <iframe>, <embed> or <object>.
The main goal is to mitigate the risk of Clickjacking. Default is false.

tips

隐藏左侧菜单和增加时间范围

  • ?kiosk=tv 隐藏左侧的菜单
  • ?from=now-1h&to=now 显示最近一小时的内容

免登陆访问 dashboard

结论

暂时不支持设定指定的 dashboard 为 public,即:免认证访问。如果开启了只读权限,则所有人皆可以访问

相关调研

1、《Making selected dashboards public》

There is no way to do this and there is a big reason why.
If you make one dashboard public you will have to make your data source public
(ie anyone can query against it).
So any possible query for that data source can be issued not just the queries used in the dashboard you made public.

根据初步的调研,得到的答复是不能指定 dashboard 开放 public 权限。同时,官方的 issue 里也有关于此问题的回复

2、《[FeatureRequest] Dashboards: Add real time share instead of snapshot》

目前依旧是处于 Open 状态。

折衷方案

《How to make one live dashboard public》