LDAP 认证系列(二):Easysearch LDAP 认证

在数据驱动的现代企业中,如何确保搜索服务既高效安全?当用户需要快速检索海量文档、日志或业务数据时,如何避免繁琐的账号管理,同时严格管控访问权限?Easysearch 通过原生支持 LDAP(轻量级目录访问协议)认证,为企业提供了一套开箱即用的解决方案——既能复用现有的企业身份体系,又能保障搜索服务的安全性与便捷性。

配置身份验证

Easysearch 的安全功能提供内置的认证领域,如 native 、 LDAP 、 active_directory 、 pki 、 file 、 saml 和 oidc 。我们编辑 config/security/config.yml 文件,配置认证设置。

---
_meta:
  type: "config"
  config_version: 2

config:
  dynamic:
    http:
      anonymous_auth_enabled: false
    authc:
      basic_internal_auth:
        order: 0
        description: "HTTP basic authentication using the internal user database"
        http_enabled: true
        transport_enabled: true
        http_authenticator:
          type: basic
          challenge: false
        authentication_backend:
          type: internal
      ldap_auth:
        order: 1
        description: "Authenticate using LDAP"
        http_enabled: true
        transport_enabled: true
        http_authenticator:
          type: basic
          challenge: false
        authentication_backend:
          type: ldap
          config:
            enable_ssl: false
            enable_start_tls: false
            enable_ssl_client_auth: false
            verify_hostnames: true
            hosts:
            - localhost:1389
            bind_dn: cn=readonly,dc=example,dc=org
            password: changethistoo
            userbase: ou=People,dc=example,dc=org
            usersearch: (cn={0})
            username_attribute: cn

    authz:
      ldap_roles:
        description: "Authorize using LDAP"
        http_enabled: true
        transport_enabled: true
        authorization_backend:
          type: ldap
          config:
            enable_ssl: false
            enable_start_tls: false
            enable_ssl_client_auth: false
            verify_hostnames: true
            hosts:
            - localhost:1389
            bind_dn: cn=readonly,dc=example,dc=org
            password: changethistoo
            userbase: ou=People,dc=example,dc=org
            usersearch: (cn={0})
            username_attribute: cn
            skip_users:
              - admin
            rolebase: ou=Group,dc=example,dc=org
            rolesearch: (uniqueMember={0})
            userroleattribute: null
            userrolename: disabled
            rolename: cn
            resolve_nested_roles: false

该文件配置了两种认证方式:基础内部认证(basic_internal_auth)和 LDAP认证(ldap_auth),以及 LDAP授权(authz)。

工作流程

  1. 客户端发送请求到 Easysearch
  2. 安全插件按 order 顺序尝试认证方式:
    1. 先尝试内部认证(basic_internal_auth)
    2. 失败后尝试 LDAP 认证(ldap_auth)
  1. 认证成功后,进行授权检查:
    1. 如果是 skip_users 列表中的用户(如admin),跳过 LDAP 授权
    2. 其他用户在 LDAP 中查询所属角色/组
  1. 根据角色/组权限决定是否允许访问

生产建议

  1. 生产环境应启用 SSL/TLS(enable_ssl: true)
  2. 修改默认密码(changethistoo)
  3. 限制 skip_users 列表中的用户数量
  4. 定期审计 LDAP 中的角色分配LDAP认证(ldap_auth)

配置角色映射

我们可以通过 config/security/role_mapping.yml 文件或 API 方式配置角色映射,推荐 API 方式

配置角色映射前,尝试用 yangf 或 readonly 用户访问 Easysearch 集群,都报没有权限。

我们通过 INFINI Console 的开发工具,配置角色映射。

PUT _security/role_mapping/superuser
{
  "external_roles" : [ "administrator","admin" ]
}


PUT _security/role_mapping/readall
{
  "external_roles" : [ "readonly" ]
}

通过上面的映射,我们将 LDAP 的 administrator 组映射到了 Easysearch 的 superuser 角色,将 readonly 组映射到了 readall 角色。

再次尝试访问,成功查询到数据。

yangf 用户是 superuser 角色可以写入数据。

readonly 用户是 readall 角色,只能读取数据,写入报错。

注意事项

任何对权限配置文件的修改: 如 user.yml, role.yml, role_mapping.yml 修改后必须以管理员身份删除 .security 索引,然后重启服务才能生效。

删除命令:

curl -XDELETE -k –cert admin.crt –key admin.key ‘https://localhost:9200/.security’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值