权限管理
所有文档
menu

Elasticsearch BES

权限管理

产品详情自助选购

权限管理包括两个层面的控制:

  • URI级别的权限控制:控制特定用户可以访问哪些URI

    场景说明:管理员可以让某个用户有管理集群动态配置参数的权限,需要将 /_cluster/setting 写(POST)权限授权给这个用户

  • index级别的权限控制:控制特定用户对index的读写操作权限

    场景说明:禁止某些用户访问特定index或读写权限分配给不同的用户进行操作,使得不同的用户获得对index不同的操作权限

创建用户

curl -u username:password -XPOST -H "Content-Type: application/json" 'host:port/_user/create' -d '
{
	"username" : "test",
	"password" : "test123",
	"ip_whitelist": ["x.x.x.x"],
	"get_path" : ["/test*", "/*/_bulk", "/*/_search"],
	"put_path" : ["/test*"],
	"post_path" : ["/test*"],
	"del_path" : ["/test*"],
	"head_path" : ["/test*"],
	"read_index": ["test*", "online-"],
	"write_index": ["test*"]
}'
参数 意义
username 用户名,支持字母(a-z及A-Z)、数字(0-9),长度小于20个字符
password 用户密码,支持字母(a-z及A-Z)、数字(0-9),长度6-20个字符
ip_whitelist 访问白名单
{HTTP_METHOD}_path 对不同HTTP类型的请求的权限控制,{HTTP_METHOD}为put、post、get、delete、head
read_index 拥有读权限的index列表
write_index 拥有写权限的index列表

注意:

  1. 只有superuser可以执行create user的指令,其他用户在任何情况下都不能执行
  2. {HTTP_METHOD}_path、read_index、write_index中的内容支持通配符匹配和前缀匹配

通配符支持 * 和 ? ,*代表任意个字符,?代表一个字符

例子 说明
*st 匹配test、tst,不能匹配 tweet
*st 匹配test、tst,不能匹配 tweet
a?d 匹配abd,acd, 不能匹配 abcd
a??d 匹配abcd,acad, 不能匹配 abd
/*/test 匹配 /abc/test,/abc/ddd/test 不能匹配 /abc/cde
* 匹配所有字符串
/* 匹配所有以/开头的URI
/*/_settings 匹配所有以_settings结尾的URI

如果只想赋予user某个index的权限,只需要设置read_index、write_index以及将get_path设置为"/"即可,示例如下:

 curl -u username:password -XPOST -H "Content-Type: application/json" 'host:port/_user/create' -d '
{
	"username" : "test",
	"password" : "test123",
	"ip_whitelist": ["x.x.x.x"],
	"get_path" : ["/"]
	"read_index": ["test*"],
	"write_index": ["test*"]
}'

修改用户

curl -u username:password -XPOST -H "Content-Type: application/json" 'host:port/_user/alter' -d '
{
	"username" : "test",
	"password" : "test321",
	"get_path" : ["/test*", "/_cat/health"],
	"read_index": ["test*"]
}'
  1. 修改用户的访问权限,同时也可以修改用户的密码
  2. 覆盖方式:出现的字段将会覆盖原有内容,未出现的字段会保留
  3. 只有root和superuser可以执行这个API

删除用户

curl -u username:password -XPOST -H "Content-Type: application/json" 'host:port/_user/delete' -d '
{
	"username" : "test"
}'

查看用户

curl -u username:password -XPOST 'host:port/_user/show’
{
  "size" : 20
}
  1. 该API需要在创建普通用户时加入其权限路径,这样普通用户才可查看自己的用户信息
  2. 如果执行该API的是root或者superuser,显示所有的用户
  3. size表示返回的用户数,默认返回10

重置密码

curl -u username:password -XPOST 'host:port/_user/resetpasswd’
{
	"password" : "test123"
}
  1. 该API需要在创建普通用户时加入其权限路径,这样普通用户才可修改自己的密码
  2. 管理员修改普通用户密码时请使用更新用户的API

使用示例

创建可使用kibana的只读用户

curl -u username:password -XPOST -H "Content-Type: application/json" 'host:port/_user/create' -d '
{
	"username" : "xxxxxx",
	"password" : "xxxxxx",
	"ip_whitelist": ["x.x.x.x"]
	"get_path" : ["/"],
	"put_path" : ["/"],
	"post_path" : ["/"],
	"del_path" : ["/"],
	"head_path" : ["/"],
	"read_index": ["test*",".kibana"],
	"write_index": [".kibana"]
}'

kibana会向ES发送一些状态检查、存储图表信息等请求,所以请求权限需要提供所有权限;如果希望创建的用户只拥有只读权限,可以在write_index中只添加.kibana,在read_index中增加用户希望读取的索引。

上一篇
配置变更
下一篇
基于BOS的快照与恢复