Skip to content

Instantly share code, notes, and snippets.

@MarshalW
Last active April 7, 2023 03:18
Show Gist options
  • Save MarshalW/1c625fe23c8da9d70ebf69145724fd14 to your computer and use it in GitHub Desktop.
Save MarshalW/1c625fe23c8da9d70ebf69145724fd14 to your computer and use it in GitHub Desktop.
kibana dashboard 嵌套到web页面

kibana dashboard 嵌套到 web 页面

以往的做法很麻烦,需要配置proxy,比如nginx,实现间接的匿名访问。

从 kibana v7.12.0 开始,可以配置匿名访问,通过 public url的方式实现不必登录访问 dashboard

配置 elasticsearch 的匿名访问

目前看这一步不是必须的,先记录下来。

配置 elasticsearch (v7.12.0) 的 config.yml文件:

..
xpack.security.authc:
  anonymous: 
    roles: read-my-index, ..
  • 不必设置username,elasticsearch有默认的用户名
  • 提前创建 role,比如 read-my-index, 对 my-index 有只读权限

重启 elasticsearch,这样做的目的是,可以匿名访问elasticsearch REST api,比如:

curl -X GET -k -s "https://elasticsearch:9200/my-index/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "size": 0
}
'

设置 kibana 匿名访问

首先要创建一个用户,用于匿名访问,比如 zhangsan,关联的 role 为 read-my-index

需要 read-my-index 设置:

  • 对指定的index partten的read权限
  • 对 kibana 的权限,选择要访问指定的 space,以及对应的 dashboard(只需要这个权限)

设置 kibana 的 config.yml:

..
xpack.security.authc.providers:
  basic.basic1:
    order: 0
  anonymous.anonymous1:
    order: 1
    credentials:
      username: "zhangsan"
      password: "password"

然后重启 kibana, 之后就可以:

  • web 登录 kibana 的时候,界面不再是登录,而是选择登录或者 continue as guest,选择后者就会自动以 zhangsan 用户作为匿名用户登录
  • 在显示 dashboard 的界面,点击 share 时弹出的对话框中选择 embed code 有了 public url 选项,选中后 copy iFrame code,得到的code就会带匿名配置内容,之前的v7.11.x其实已经支持了,但需要手动增加
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment