Search Guard1.0 增加用户

Search Guard 增加用户

https://docs.search-guard.com/latest/first-steps-user-configuration

看了官方文档,才看见有第一步,这些是配置用户、角色等配置。上面我是按照我的进度去看的,第一次,不是很准确。等这些弄完了,我在出一版实践的博客。

本文主要内容:

  • 内部用户数据库

  • sg_internal_users.yml中增加用户

  • 生成hash密码

  • 增加更多用户

  • 对于集群更新这些变化

1.内部用户数据库

Search Guard可以使用外部身份验证系统(如LDAP、OpenID、SAML或者Kerberos)来管理用户。作为替代方案,你也可以使用内部用户数据库来管理用户。

内部用户数据库是直接在Elasticsearch中保村用户及其凭证。在内部用户数据库为了管理用户,你有三个选项:

  • 1.在sg_intern_users.yml中配置用户、hash密码和后端角色,且在tools目录中使用***sgadmin***上传这个配置到你的集群(社区)
  • 2.使用intern users REST API --(企业)
  • 3.使用Kibana内部用户configuration GUI --(企业)

由于是社区环境,自己搭建的,先介绍第一种方法。

2. sg_intern_users.yml配置

在这个文件中,定义了所有的Search Guard用户,你可以找到一个例子。它所在的路径:

<ES installation directory>/plugins/search-guard-7/sgconfig/sg_internal_users.yml

2.1 用户格式

下面是用户格式

<username>:

  hash: <hashed password>

  backend_roles:

    - <rolename>

    - <rolename>


若我们想配置一个名为jode的用户,且对于一个索引拥有只读权限。

我们也想对这个用户曾加一个后端角色hr_department。在此刻,思考在不同群组中后端角色作为增加用户的一种方法。像LDAP、Active Directory组。我们在分配所有的用户到hr_department角色作为一个Search Guard角色之后使用他们。

因此在sg_internal_users.yml中基本结构如下:

jdoe:

  hash: <hashed password>

  backend_roles:

    - hr_department

3. 生成hash密码

由于我们不想在任何地方保存明文密码,在增加它到这个配置之前,用户的密码必须用户hash算法加密。

Search Guard 使用一种BCrypt hash算法加密密码,因此你可以使用 any tool that is capable of producing a BCrypt hash.

<ES installation directory>/plugins/search-guard-7/tools/hash.sh


可以使用如下命令生成hash密码

<ES installation directory>/plugins/search-guard-7/tools/hash.sh -p <cleartext password>

生成hash密码之后,把它放到配置文件中,即sg_internal_users.yml中

jdoe:

  hash: $2y$12$AwwN1fn0HDEw/LBCwWU0y.Ys6PoKBL5pR.WTYAIV92ld7tA8kozqa

  backend_roles:

    - hr_department

Notes

因为使用BCrypt算法,你实际的hash值可能和以上文章提供的不同。

4.增加更多的用户

在提供的例子中,增加其他用户也是hr_department组的成员,另外的一个用户是devops成员。我们将在先一步操作中创建Search Guard角色给这些用户,配置如下:

jdoe:

  hash: $2y$12$AwwN1fn0HDEw/LBCwWU0y.Ys6PoKBL5pR.WTYAIV92ld7tA8kozqa

  backend_roles:

    - hr_department



psmith:

  hash: $2y$12$YOVZhJ.gbZOAoGyd9YGNMuw7rWYTfB73n8OGBLtsrihMkW5rg5D1G

  backend_roles:

    - hr_department



cmaddock:

  hash: $2y$12$3UFikPXIZLoHcsDGD0hyqOvxjytdXeRkefIF1M58jA5oueSDKthzu

  backend_roles:

    - devops


为了使用简单,对于这些用户这里的密码我们使用相同的。

5. 上传这些改变给你的集群

为了激活这个变化的配置,我们需要用户tool目录的sgadmin.sh命令,去上传配置到Search Guard配置索引。

如果你是按照本文的方法安装且启动Search Guard,你将会找到一个已经配置好所需参数的sgadmin.sh脚本在tools目录。进入此目录。

cd <ES installation directory>/plugins/search-guard-7/tools/


且执行命令

./sgadmin_demo.sh

这将会上传所有的配置到如下目录

<ES installation directory>/plugins/search-guard-7/sgconfig/

如果一切都如预期一样,你可以看见如下的输出:

Will update 'sg/config' with <ES installation directory>/plugins/search-guard-6/sgconfig/sg_config.yml 

   SUCC: Configuration for 'config' created or updated

Will update 'sg/roles' with <ES installation directory>/plugins/search-guard-6/sgconfig/sg_roles.yml 

   SUCC: Configuration for 'roles' created or updated

Will update 'sg/rolesmapping' with <ES installation directory>/plugins/search-guard-6/sgconfig/sg_roles_mapping.yml 

   SUCC: Configuration for 'rolesmapping' created or updated

Will update 'sg/internalusers' with <ES installation directory>/plugins/search-guard-6/sgconfig/sg_internal_users.yml 

   SUCC: Configuration for 'internalusers' created or updated

Will update 'sg/actiongroups' with <ES installation directory>plugins/search-guard-6/sgconfig/sg_action_groups.yml 

   SUCC: Configuration for 'actiongroups' created or updated

Done with success

这些配置改变是立即生效,不需要重启集群。

6.额外的资源

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值