美文网首页
ES LDAP 集成

ES LDAP 集成

作者: 华阳_3bcf | 来源:发表于2020-11-26 15:35 被阅读0次

测试环境:

OS: CentOS Linux release 7.6.1810 (Core)

ES version:7.9.2

前期准备

ES 安装

从官网下载linux源码包 https://www.elastic.co/downloads/elasticsearch

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.2-linux-x86_64.tar.gz
tar -xzvf elasticsearch-7.9.2-linux-x86_64.tar.gz
cd elasticsearch-7.9.2
./bin/elasticsearch

启用安全功能

使用ES自带工具来实现。Encrypting communications in Elasticsearch

# cd ES-HOME-DIR
bin/elasticsearch-certutil ca
bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
mv elastic-certificates.p12 config
vi config/elasticsearch.yml

针对证书,在配置文件中做修改。

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.verification_mode to certificate: certificate
xpack.security.http.ssl.keystore.path: elastic-certificates.p12

设置密码

通过设置访问密码,这是elastic用户和其他一些系统内置用户的密码

bin/elasticsearch-setup-passwords auto

把密码保存下来。

验证服务

$ curl https://127.0.0.1:9200/_cat/health -k -u elastic:KofFTZGdqZ8QggP3kLJw
1606371324 06:15:24 roy-es2 green 1 1 7 7 0 0 0 0 - 100.0%

申请临时证书

这是LDAP认证需要。

Starts a 30-day trial.

curl -X POST "https://localhost:9200/_license/start_trial?acknowledge=true" -k -u elastic:KofFTZGdqZ8QggP3kLJw

配置LDAP认证

修改配置文件

目前,X-Pack集成LDAP认证支持通过以下两种配置方式:

  • 用户搜索模式。
  • 带有用户DNs特定模板的模式。

其中,用户搜索模式是最常见的操作方式。在此模式中,具有搜索LDAP目录权限的特定用户,根据X-Pack提供的用户名和LDAP属性,搜索进行身份验证的用户的DN。一旦找到,X-Pack将使用找到的DN和提供的密码,尝试绑定到LDAP服务器来验证用户,详情请参见Configure an LDAP realm

以下为LDAP管理DN的映射方式,需要在Elasticsearch的YML文件中添加如下配置。

xpack:
  security:
    authc:
      realms:
        ldap:
          ldap1:
            order: 0
            url: "ldap://10.0.1.5"
            #url: "ldaps://10.0.1.5:636"
            bind_dn: "cn=Manager, dc=roywork, dc=com"  #管理员dn
            bind_password: 123456                      #管理员密码
            user_search:
              base_dn: "dc=roywork,dc=com"            #用户搜索范围
              filter: "(cn={0})"
            group_search:
              base_dn: "dc=roywork,dc=com"
            files:
              role_mapping: "/es/elasticsearch-7.9.2/config/role_mapping.yml" #角色绑定配置文件
            unmapped_groups_as_roles: false
参数 说明
type 设置域。此处必须设置为ldap
url 指定LDAP服务器URL及端口。ldap协议表示使用普通连接,端口为389;ldaps表示使用SSL安全连接,端口为636。
bind_dn 用于绑定到LDAP并执行搜索的用户的DN,仅适用于用户搜索模式。
bind_password 用于绑定到LDAP目录的用户的密码。
user_search.base_dn 用户搜索的容器DN。
group_search.base_dn 用于搜索用户具有成员资格的容器DN。当此参数不存在时,Elasticsearch将搜索user_group_attribute指定的属性,来确定成员身份。
unmapped_groups_as_roles 默认false。如果设置为true,则任何未映射的LDAP组的名称都将用作角色名称分配给用户。

LDAP 的组/用户 与 ES roles 映射

文件形式

role_mapping.yml,可配置可不配,就放这里参考下,一般通过api配置映射关系。因为通过文件的形式需要每个node都存放一份。

superuser:
  - "cn=Manager,dc=roywork,dc=com"

API方式

Map LDAP groups to roles.

The ldap realm enables you to map LDAP users to roles via their LDAP groups, or other metadata. This role mapping can be configured via the add role mapping API or by using a file stored on each node.

使用方式

maps the LDAP admins group to both the monitoring and user roles

PUT /_security/role_mapping/admins
{
  "roles" : [ "monitoring" , "user" ],
  "rules" : { "field" : {
    "groups" : "cn=admins,dc=example,dc=com" 
  } },
  "enabled": true
}

实际使用例子

$ curl -X POST "https://localhost:9200/_xpack/security/role_mapping/users" -k -u elastic:KofFTZGdqZ8QggP3kLJw -H 'Content-Type: application/json' -d'
{
  "roles": [ "superuser" ],
  "enabled": true,
  "rules": {
    "field" : { "dn" : "*,ou=People,dc=roywork,dc=com" }              
  }
}
'

验证

$ curl "https://127.0.0.1:9200/_xpack/security/role_mapping?pretty" -k -u elastic:KofFTZGdqZ8QggP3kLJw
{
  "users" : {
    "enabled" : true,
    "roles" : [
      "superuser"
    ],
    "rules" : {
      "field" : {
        "dn" : "*,ou=People,dc=roywork,dc=com"
      }
    },
    "metadata" : { }
  }
}

测试

用LDAP 中的用户去测试连接

$ curl https://127.0.0.1:9200/_cat?pretty -k -u ldapuser2:123456
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
....

在ldap添加一个新用户,结果同上,说明LDAP集成已经成功了。

参考

ElasticSearch结合LDAP实现权限、用户管控

elasticsearch实现与ldap对接

LDAP user authentication (官网)

相关文章

  • ES LDAP 集成

    测试环境: OS: CentOS Linux release 7.6.1810 (Core) ES versio...

  • 快速搭建 LDAP 服务器与Hive集成

    快速搭建 LDAP 服务器与Hive集成 1 前言 LDAP (Lightweight Directory Acc...

  • Zeppelin 集成 LDAP(FreeIPA)

    前言 本篇主要介绍Zeppelin集成LDAP认证的方法。 LDAP服务配置我们采用FreeIPA。FreeIPA...

  • docker-compose编排YApi

    克隆线上的仓库 docker-compose.yml 集成了ldap,如果不需要可以注释掉ldap选项参数。

  • 面试工作流!Activiti框架中LDAP组件详解,实现对工作流

    Activiti集成LDAP简介 企业在LDAP系统中保存了用户和群组信息,Activiti提供了一种解决方案,通...

  • hive集成ldap

    隶属于文章系列:大数据安全实战 https://www.jianshu.com/p/76627fd8399c

  • hdfs集成ldap

    隶属于文章系列:大数据安全实战 https://www.jianshu.com/p/76627fd8399c 修改...

  • Jenkins集成LDAP

    一、 准备工作: 1、安装两个插件 如果你安装好了Role-based Authorization Strateg...

  • confluence集成LDAP

    一、confluence的权限管理在集成前,我们必须得知道confluence自身的权限管理是如何做的。用户组对应...

  • GitLab集成LDAP

    目录一、下载并安装GitLab二、重置超级管理员的密码三、开启LDAP四、测试五、LDAP详细配置说明六、设置Gi...

网友评论

      本文标题:ES LDAP 集成

      本文链接:https://www.haomeiwen.com/subject/nbtziktx.html