你可以使用内置文件域(file realm)管理和验证用户。 使用文件域,用户在集群中每个节点上的本地文件中定义。

重要:作为集群的管理员,你有责任确保在集群中的每个节点上定义相同的用户。 Elastic Stack 安全功能不提供任何机制来保证这一点。 你还应该知道,你不能通过 user APIs 在文件域中添加或管理用户,也不能在 Management/Security/Users 页面上的 Kibana 中添加或管理它们。

文件域作为回退(fallback)或恢复(recovery)域非常有用。 例如,在集群无响应或安全索引不可用的情况下,或者当你忘记管理用户的密码时。 在这种情况下,文件域是一种方便的出路 — 你可以在文件领域中定义一个新的管理员用户,并使用它来登录和重置所有其他用户的凭据。

重要:当你在 elasticsearch.yml 中配置域时,只有指定的域用于身份验证。 要使用文件域,你必须明确地将其包含在域链中。 虽然可以定义一些其他域的多个实例,但你只能为每个节点定义一个文件领域。

文件域(file realm)默认已经添加到域链中。 你不需要显式配置文件域

文件领域的所有用户数据都存储在集群中每个节点上的两个文件中:users 和 users_roles。 这两个文件都位于 ES_PATH_CONF 中,并在启动时读取。

$ pwd
/Users/liuxg/elastic/elasticsearch-8.5.2
$ ls config/
certs                             log4j2.properties
elasticsearch-plugins.example.yml role_mapping.yml
elasticsearch.keystore            roles.yml
elasticsearch.yml                 users
jvm.options                       users_roles
jvm.options.d

配置

我们在 config 下的 user_roles 里配置所需要的 roles,比如:

config/roles.yml

admins:cluster:- allindices:- names:- "*"privileges:- alldevs:cluster:- manageindices:- names:- "*"privileges:- write- delete- create_index
$ pwd
/Users/liuxg/elastic/elasticsearch-8.5.2
$ cat config/roles.yml
# The default roles file is empty as the preferred method of defining roles is
# through the API/UI. File based roles are useful in error scenarios when the
# API based roles may not be available.
admins:cluster:- allindices:- names:- "*"privileges:- alldevs:cluster:- manageindices:- names:- "*"privileges:- write- delete- create_index

如上所示,我们在 roles.yml 里创建了两个 roles: admins 及 devs。这两个 roles 有不同的权限。admins 是超级用户的权限,而 devs role 具有 write, delete 及 create_index 的权限。

配置完后,我们重新 Elasticsearch。就像文章开头说的那样,我们通过这样的方法创建的 roles 并不能在 Management/Security/Role 中看到:

创建用户

接下来,我们就要使用 elasticsearch-users 这个工具来创建用户。我们使用如下的命令来创建一个用户 liuxg 及其密码 password。它所定义的 roles 为 networking 及 monitoring:

bin/elasticsearch-users useradd liuxg -p password -r network,monitoring
$ pwd
/Users/liuxg/elastic/elasticsearch-8.5.2
$ bin/elasticsearch-users useradd liuxg -p password -r network,monitoring
Warning: The following roles [monitoring,network] are not in the [/Users/liuxg/elastic/elasticsearch-8.5.2/config/roles.yml] file. Make sure the names are correct. If the names are correct and the roles were created using the API please disregard this message. Nonetheless the user will still be associated with all specified roles
Known roles: [apm_system, watcher_admin, viewer, logstash_system, rollup_user, kibana_user, beats_admin, remote_monitoring_agent, rollup_admin, snapshot_user, data_frame_transforms_admin, devs, monitoring_user, enrich_user, kibana_admin, logstash_admin, editor, data_frame_transforms_user, machine_learning_user, machine_learning_admin, watcher_user, apm_user, beats_system, transform_user, reporting_user, kibana_system, transform_admin, remote_monitoring_collector, transport_client, admins, superuser, ingest_admin]

如上所示,它给出了一些警告:monitoring 及 network 并没有在 roles.yml 里被定义。它还列出了可以被使用的 roles 的名称:

尽管如此,它只是一个警告。我接着查看如下的文件:

$ pwd
/Users/liuxg/elastic/elasticsearch-8.5.2
$ cat config/users
liuxg:$2a$10$VJQzQftnxSwvdaxfuLGLx.lX4VGuIfLHV.R38HBySUUr1KJL2hrgW
$ cat config/users
liuxg:$2a$10$VJQzQftnxSwvdaxfuLGLx.lX4VGuIfLHV.R38HBySUUr1KJL2hrgW

我们可以看到上面的内容。liuxg 就是用户名,而后面是用掩码表示的密码。我们再查看 users_roles 这个文件:

cat config/users_roles 
$ cat config/users_roles
monitoring:liuxg
network:liuxg

它显示了各个角色(role)对应的用户。

我们现在用刚创建的用户 liuxg:password 来访问 Elasticsearch:

curl -k -u liuxg:password https://localhost:9200
$ curl -k -u liuxg:password https://localhost:9200 | jq% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100   541  100   541    0     0   5517      0 --:--:-- --:--:-- --:--:--  5755
{"error": {"root_cause": [{"type": "security_exception","reason": "action [cluster:monitor/main] is unauthorized for user [liuxg] with effective roles [] (assigned roles [monitoring,network] were not found), this action is granted by the cluster privileges [monitor,manage,all]"}],"type": "security_exception","reason": "action [cluster:monitor/main] is unauthorized for user [liuxg] with effective roles [] (assigned roles [monitoring,network] were not found), this action is granted by the cluster privileges [monitor,manage,all]"},"status": 403
}

显然,我们不能进行登录。这是因为用户 liuxg 还没有相应的权限。

我们接下来使用编辑器来编辑 config/users_roles 文件,使其成为:

config/users_roles

$ pwd
/Users/liuxg/elastic/elasticsearch-8.5.2
$ cat config/users_roles
monitoring:liuxg
network:liuxg
admins:liuxg

在上面,我们为 liuxg 这个用户添加了之前我们在 roles.yml 文件中定义的 admins 权限。这个 admins 是超级用户的权限。我们再次发送请求:

$ curl -k -u liuxg:password https://localhost:9200 | jq% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100   535  100   535    0     0  27225      0 --:--:-- --:--:-- --:--:-- 35666
{"name": "liuxgm.local","cluster_name": "elasticsearch","cluster_uuid": "NvSlRkrSTaO33lAKdzNcqQ","version": {"number": "8.5.2","build_flavor": "default","build_type": "tar","build_hash": "a846182fa16b4ebfcc89aa3c11a11fd5adf3de04","build_date": "2022-11-17T18:56:17.538630285Z","build_snapshot": false,"lucene_version": "9.4.1","minimum_wire_compatibility_version": "7.17.0","minimum_index_compatibility_version": "7.0.0"},"tagline": "You Know, for Search"
}

这次显然我们的访问是成功的。我们的集群有救了。我们为它设置了一个崭新的账号。

我们还可以使用如下的命令来列出来在当前节点里的文件域中的用户:

bin/elasticsearch-users list
$ bin/elasticsearch-users list
liuxg          : monitoring*,network*,admins[*]   Role is not in the [/Users/liuxg/elastic/elasticsearch-8.5.2/config/roles.yml] file. If the role has been created using the API, please disregard this message.

我们可以使用如下的命令来重新设置用户的密码:

bin/elasticsearch-users passwd liuxg

上面的命令将为 liuxg 用户重置密码:

$ bin/elasticsearch-users passwd liuxg
Enter new password:
Retype new password: 

在上面,我们为 liuxg 用户的密码重置为 123456。我们再次使用如下的命令来进行验证:

$ curl -k -u liuxg:123456 https://localhost:9200 | jq% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100   535  100   535    0     0   5533      0 --:--:-- --:--:-- --:--:--  5815
{"name": "liuxgm.local","cluster_name": "elasticsearch","cluster_uuid": "NvSlRkrSTaO33lAKdzNcqQ","version": {"number": "8.5.2","build_flavor": "default","build_type": "tar","build_hash": "a846182fa16b4ebfcc89aa3c11a11fd5adf3de04","build_date": "2022-11-17T18:56:17.538630285Z","build_snapshot": false,"lucene_version": "9.4.1","minimum_wire_compatibility_version": "7.17.0","minimum_index_compatibility_version": "7.0.0"},"tagline": "You Know, for Search"
}

很显然,密码的修改是成功的。

我们甚至可以使用如下的命令来移除不需要的 roles:

bin/elasticsearch-users roles liuxg -r network,monitoring -a user

上面的命令为 liuxg 用户移除 network 及 monitoring 角色,并添加 user 角色。

执行上面的命令后,我们重新检查用户的角色:

$ bin/elasticsearch-users list
liuxg          : user*,admins

显然之前的 network 及 monitoring 已经被移除了。

我们还可以使用如下的命令来删除一个用户:

bin/elasticsearch-users userdel liuxg

上面的命令将删除 liuxg 用户。我们再次使用 list 命令来查看:

$ bin/elasticsearch-users list
No users found

Elasticsearch:基于文件的用户认证相关推荐

  1. linux ftp 团队认证,linux下ftp和ftps以及ftp基于mysql虚拟用户认证服务器的搭建

    linux下ftp和ftps以及ftp基于mysql虚拟用户认证服务器的搭建 1.FTP协议:有命令和数据连接两种 命令连接,控制连接:21/tcp 数据连接: 主动模式,运行在20/tcp端口 和 ...

  2. linux ftp mysql_linux下ftp和ftps以及ftp基于mysql虚拟用户认证服务器的搭建

    命令连接,控制连接:21/tcp 数据连接: 主动模式,运行在20/tcp端口 和 被动模式,运行在随机端口 数据传输模式(自动模式):有二进制(mp3,jpg等)和文本(html)两种传输模式 ft ...

  3. 从入门到入土:[linux实践]-pam|编写基于libpam的用户认证程序|编写基于PAM认证的应用程序|详细说明|实验步骤|实验截图

    写在前面: 此博客仅用于记录个人学习进度,学识浅薄,若有错误观点欢迎评论区指出.欢迎各位前来交流.(部分材料来源网络,若有侵权,立即删除) 编写基于libpam的用户认证程序|编写基于PAM认证的应用 ...

  4. python 用户认证_python基于mysql的用户认证

    首先,创建mysql用户users表 1 2 3 4 5 create table users ( id int NOT NULL primary key auto_increment, userna ...

  5. elasticsearch 基于文件搜索

    java部分代码 @Override     public void addFileForEs(String index, String type, String path,String downlo ...

  6. linux认证授权系统,linux高级操作系统用户认证与授权-20210323002921.doc-原创力文档...

    HYPERLINK "/" 长沙理工大学 <Linux高级操作系统>课程设计报告 基于Linux的用户认证与授权研究 廖正磊 学 院 计算机与通信工程 专业 计算机科学 ...

  7. apache添加ssl协议实现用户认证

    apache添加ssl协议实现用户认证 目标 1对服务器的访问由http改为https, 2仅有证书的客户端可以访问服务器, 3.通过服务器端的配置,可以停用某个客户端的证书. 一 Apache服务器 ...

  8. linux的Nginx安装、默认虚拟主机、用户认证、域名重定向配置介绍

    Nginx介绍 Nginx官网(http://nginx.org),最新版1.13,最新稳定版1.12 Nginx应用场景:web服务.反向代理.负载均衡 Nginx著名分支,淘宝基于Nginx开发的 ...

  9. SpringtBoot+SpringSecurity+Jwt+MyBatis整合实现用户认证以及权限控制

    文章目录 前言 数据库表结构 项目结构图 核心配置类SecurityConfig 实体类 工具类 用户登录认证 Token令牌验证 获取用户权限 用户权限验证 Service层实现类 统一响应类 Co ...

最新文章

  1. 抢购系统架构设计原理参考文档
  2. GDALWarp设置GDALWarpOptions::dfWarpMemoryLimit过大时处理失败
  3. Xcode中导入.a静态库后报错添加-force_load或-all_load
  4. 【修改版】10行代码爬取A股上市公司信息
  5. c语言产生cl.exe错误,vc++6.0执行cl.exe时出错
  6. fatal error C1083: 无法打开预编译头文件:“Debug\opencv.pch”: No such file or directory
  7. oracle加大内存对大表,在ORACLE里如果遇到特别大的表,可以使用分区的表来改变其应用程序的性能...
  8. div隐藏select显示的解决办法(就死select挡住了div) 不是网上找到的那五种
  9. 阿里正在研发无人卡车;《王者荣耀》皮肤个性动作涉嫌抄袭致歉;​苹果泄露女生私密照赔偿数百万美元|极客头条...
  10. 毕业设计项目,微博语料情感分析,文本分类
  11. 关于mysql_free_result和mysql_close的解惑
  12. Ubuntu16.04LTS +Qt+boost1.66编译错误:consuming_buffers.hpp: parse error in template argument list...
  13. spyder selenium配置
  14. 【PAT】L1-050. 倒数第N个字符串【C语言实现】
  15. 贝叶斯模型构建分类器的设计与实现
  16. 移动互联网时代,怎样打造一款新闻资讯类产品?
  17. Cortex-A 系列处理器
  18. 小程序开发(适合初学者)
  19. VS2005使用体验
  20. 服务器除雪信息报道,各单位铲冰除雪畅通油区道路,保障生产正常运行

热门文章

  1. 张奕卉|可信区块链溯源:因为透明,所以可信
  2. SwiftUI 动画大全之 五彩纸屑特效含三角形、五星、钻石与自定义图像 (教程含源码)
  3. Android从1.0到11版本特性
  4. 智能监控平台Android客户端
  5. reac组件,Component 与 PureComponent
  6. SQL SERVER 2012 无法附加数据库,在附加数据库界面显示不了待附加的MDB文件
  7. go time Format 格式化时间的使用
  8. 关于Unity RaycastHit2D 的使用心得
  9. SQL数据库中数据类型ntext和text的区别
  10. 如何把爱情公寓5引入到我的html