在数据驱动的现代企业中,如何确保搜索服务既高效又安全?当用户需要快速检索海量文档、日志或业务数据时,如何避免繁琐的账号管理,同时严格管控访问权限?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)。
工作流程
- 客户端发送请求到 Easysearch
- 安全插件按 order 顺序尝试认证方式:
-
- 先尝试内部认证(basic_internal_auth)
- 失败后尝试 LDAP 认证(ldap_auth)
- 认证成功后,进行授权检查:
-
- 如果是 skip_users 列表中的用户(如admin),跳过 LDAP 授权
- 其他用户在 LDAP 中查询所属角色/组
- 根据角色/组权限决定是否允许访问
生产建议
- 生产环境应启用 SSL/TLS(enable_ssl: true)
- 修改默认密码(changethistoo)
- 限制 skip_users 列表中的用户数量
- 定期审计 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’