Search Guard 1.3 测试配置
测试配置
在上面三个小节Search Guard 1.0、 1.1、1.2中,我们配置了用户和角色。现在来测试一下这些配置是否成功。
本文:
-
检查配置的用户
-
访问Elasticsearch
在检查之前,我们看下需要的配置:
-
在
sg_internal_users.yml中创建用户 -
在
sg_roles.yml中创建角色 -
在
sg_roles_mapping.yml创建一个映射去连接用户和Search Guard的角色对应
检查配置的用户
作为第一步,我们想去检查我们配置的的用户是否在且映射到正确的Search Guard角色。
Search Guard 提供了一个HTTP去检查一个用户的属性。
https://<node name>:<http port>/_searchguard/authinfo?pretty
为了获取用户信息,我们需要提供用户名和密码。通过这个连接这个端点检查jode用户的属性:
curl -k -u jdoe:jdoe -XGET "https://sgssl-0.example.com:9200/_searchguard/authinfo?pretty"
这个返回内容:
{
"user" : "User [name=jdoe, backend_roles=[hr_department], requestedTenant=null]",
"user_name" : "jdoe",
...
"backend_roles" : [
"hr_department"
],
"sg_roles" : [
"sg_human_resources"
],
...
}
在返回的JSON中,可以看到创建的用户和被分配到正确的Search Guard角色:
"user_name":"jdoe"
这是在sg_internal_users.yml配置的用户。
"backend_roles":[“hr_department”]
这是在sg_internal_users.yml中用户jdoe分配的后端角色。
"sg_roles":[“sg_human_resources”]
这个是为了用户jdoe分配Search Guard的角色。这意外这映射对于此用户Search Guard被期望的那样工作。
访问Elasticsearch
现在,我们要确信我们的用户jdoe是正确映射到Search Guard角色sg_human_resources。在Elasticsearch中可以试着访问一些数据。
这个定义的角色比如:
sg_human_resources:
cluster_permissions:
- "SGS_CLUSTER_COMPOSITE_OPS"
index_permissions:
- index_patterns:
- "humanresources"
allowed_actions:
- "SGS_READ"
我们期望用户jdoe可以读取索引humanresources的数据,但不能访问其他任何数据。
首先,我们试着访问索引humanresources的数据。
curl -k -u jdoe:jdoe -XGET "https://IP:9200/humanresources/_search?pretty"
正如预期一样,访问是被允许的,且从这个索引返回了数据。
{
"took" : 216,
"timed_out" : false,
"_shards" : {
...
},
"hits" : {
"total" : {
...
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "humanresources",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"FirstName" : "CHASE",
"LastName" : "CRUDO",
"Designation" : "President",
}
},
...
如果我们试着访问索引devops的数据,正如预期一样访问是被拒绝的。
curl -k -u jdoe:jdoe -XGET "https://sgssl-0.example.com:9200/devops/_search?pretty"
{
"error" : {
"root_cause" : [
{
"type" : "security_exception",
"reason" : "no permissions for [indices:data/read/search] and User [name=jdoe, roles=[hr_department], requestedTenant=null]"
}
],
"type" : "security_exception",
"reason" : "no permissions for [indices:data/read/search] and User [name=jdoe, roles=[hr_department], requestedTenant=null]"
},
"status" : 403
}
额外的资源
下面是单词:
troubleshooting:*英 /ˈtrʌblʃuːtɪŋ/ *
v 检修;当调解人
n 解决纷争,发现并修理故障

浙公网安备 33010602011771号