你可以使用内置文件域(file realm)管理和验证用户。 使用文件域,用户在集群中每个节点上的本地文件中定义。
重要:作为集群的管理员,你有责任确保在集群中的每个节点上定义相同的用户。 Elastic Stack 安全功能不提供任何机制来保证这一点。 你还应该知道,你不能通过 user APIs 在文件域中添加或管理用户,也不能在 Management/Security/Users 页面上的 Kibana 中添加或管理它们。

文件域作为回退(fallback)或恢复(recovery)域非常有用。 例如,在集群无响应或安全索引不可用的情况下,或者当你忘记管理用户的密码时。 在这种情况下,文件域是一种方便的出路 — 你可以在文件领域中定义一个新的管理员用户,并使用它来登录和重置所有其他用户的凭据。
重要:当你在 elasticsearch.yml 中配置域时,只有指定的域用于身份验证。 要使用文件域,你必须明确地将其包含在域链中。 虽然可以定义一些其他域的多个实例,但你只能为每个节点定义一个文件领域。
文件域(file realm)默认已经添加到域链中。 你不需要显式配置文件域。
文件领域的所有用户数据都存储在集群中每个节点上的两个文件中:users 和 users_roles。 这两个文件都位于 ES_PATH_CONF 中,并在启动时读取。
$ pwd
/Users/liuxg/elastic/elasticsearch-8.5.2
$ ls config/
certs log4j2.properties
elasticsearch-plugins.example.yml role_mapping.yml
elasticsearch.keystore roles.yml
elasticsearch.yml users
jvm.options users_roles
jvm.options.d
我们在 config 下的 user_roles 里配置所需要的 roles,比如:
config/roles.yml
admins:
cluster:
- all
indices:
- names:
- "*"
privileges:
- all
devs:
cluster:
- manage
indices:
- names:
- "*"
privileges:
- write
- delete
- create_index
$ pwd
/Users/liuxg/elastic/elasticsearch-8.5.2
$ cat config/roles.yml
# The default roles file is empty as the preferred method of defining roles is
# through the API/UI. File based roles are useful in error scenarios when the
# API based roles may not be available.
admins:
cluster:
- all
indices:
- names:
- "*"
privileges:
- all
devs:
cluster:
- manage
indices:
- names:
- "*"
privileges:
- write
- delete
- create_index
如上所示,我们在 roles.yml 里创建了两个 roles: admins 及 devs。这两个 roles 有不同的权限。admins 是超级用户的权限,而 devs role 具有 write, delete 及 create_index 的权限。
配置完后,我们重新 Elasticsearch。就像文章开头说的那样,我们通过这样的方法创建的 roles 并不能在 Management/Security/Role 中看到:

接下来,我们就要使用 elasticsearch-users 这个工具来创建用户。我们使用如下的命令来创建一个用户 liuxg 及其密码 password。它所定义的 roles 为 networking 及 monitoring:
bin/elasticsearch-users useradd liuxg -p password -r network,monitoring
$ pwd
/Users/liuxg/elastic/elasticsearch-8.5.2
$ bin/elasticsearch-users useradd liuxg -p password -r network,monitoring
Warning: The following roles [monitoring,network] are not in the [/Users/liuxg/elastic/elasticsearch-8.5.2/config/roles.yml] file. Make sure the names are correct. If the names are correct and the roles were created using the API please disregard this message. Nonetheless the user will still be associated with all specified roles
Known roles: [apm_system, watcher_admin, viewer, logstash_system, rollup_user, kibana_user, beats_admin, remote_monitoring_agent, rollup_admin, snapshot_user, data_frame_transforms_admin, devs, monitoring_user, enrich_user, kibana_admin, logstash_admin, editor, data_frame_transforms_user, machine_learning_user, machine_learning_admin, watcher_user, apm_user, beats_system, transform_user, reporting_user, kibana_system, transform_admin, remote_monitoring_collector, transport_client, admins, superuser, ingest_admin]
如上所示,它给出了一些警告:monitoring 及 network 并没有在 roles.yml 里被定义。它还列出了可以被使用的 roles 的名称:

尽管如此,它只是一个警告。我接着查看如下的文件:
$ pwd
/Users/liuxg/elastic/elasticsearch-8.5.2
$ cat config/users
liuxg:$2a$10$VJQzQftnxSwvdaxfuLGLx.lX4VGuIfLHV.R38HBySUUr1KJL2hrgW
$ cat config/users
liuxg:$2a$10$VJQzQftnxSwvdaxfuLGLx.lX4VGuIfLHV.R38HBySUUr1KJL2hrgW
我们可以看到上面的内容。liuxg 就是用户名,而后面是用掩码表示的密码。我们再查看 users_roles 这个文件:
cat config/users_roles
$ cat config/users_roles
monitoring:liuxg
network:liuxg
它显示了各个角色(role)对应的用户。
我们现在用刚创建的用户 liuxg:password 来访问 Elasticsearch:
curl -k -u liuxg:password https://localhost:9200
$ curl -k -u liuxg:password https://localhost:9200 | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 541 100 541 0 0 5517 0 --:--:-- --:--:-- --:--:-- 5755
{
"error": {
"root_cause": [
{
"type": "security_exception",
"reason": "action [cluster:monitor/main] is unauthorized for user [liuxg] with effective roles [] (assigned roles [monitoring,network] were not found), this action is granted by the cluster privileges [monitor,manage,all]"
}
],
"type": "security_exception",
"reason": "action [cluster:monitor/main] is unauthorized for user [liuxg] with effective roles [] (assigned roles [monitoring,network] were not found), this action is granted by the cluster privileges [monitor,manage,all]"
},
"status": 403
}
显然,我们不能进行登录。这是因为用户 liuxg 还没有相应的权限。
我们接下来使用编辑器来编辑 config/users_roles 文件,使其成为:
config/users_roles
$ pwd
/Users/liuxg/elastic/elasticsearch-8.5.2
$ cat config/users_roles
monitoring:liuxg
network:liuxg
admins:liuxg
在上面,我们为 liuxg 这个用户添加了之前我们在 roles.yml 文件中定义的 admins 权限。这个 admins 是超级用户的权限。我们再次发送请求:
$ curl -k -u liuxg:password https://localhost:9200 | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 535 100 535 0 0 27225 0 --:--:-- --:--:-- --:--:-- 35666
{
"name": "liuxgm.local",
"cluster_name": "elasticsearch",
"cluster_uuid": "NvSlRkrSTaO33lAKdzNcqQ",
"version": {
"number": "8.5.2",
"build_flavor": "default",
"build_type": "tar",
"build_hash": "a846182fa16b4ebfcc89aa3c11a11fd5adf3de04",
"build_date": "2022-11-17T18:56:17.538630285Z",
"build_snapshot": false,
"lucene_version": "9.4.1",
"minimum_wire_compatibility_version": "7.17.0",
"minimum_index_compatibility_version": "7.0.0"
},
"tagline": "You Know, for Search"
}
这次显然我们的访问是成功的。我们的集群有救了。我们为它设置了一个崭新的账号。
我们还可以使用如下的命令来列出来在当前节点里的文件域中的用户:
bin/elasticsearch-users list
$ bin/elasticsearch-users list
liuxg : monitoring*,network*,admins
[*] Role is not in the [/Users/liuxg/elastic/elasticsearch-8.5.2/config/roles.yml] file. If the role has been created using the API, please disregard this message.
我们可以使用如下的命令来重新设置用户的密码:
bin/elasticsearch-users passwd liuxg
上面的命令将为 liuxg 用户重置密码:
$ bin/elasticsearch-users passwd liuxg
Enter new password:
Retype new password:
在上面,我们为 liuxg 用户的密码重置为 123456。我们再次使用如下的命令来进行验证:
$ curl -k -u liuxg:123456 https://localhost:9200 | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 535 100 535 0 0 5533 0 --:--:-- --:--:-- --:--:-- 5815
{
"name": "liuxgm.local",
"cluster_name": "elasticsearch",
"cluster_uuid": "NvSlRkrSTaO33lAKdzNcqQ",
"version": {
"number": "8.5.2",
"build_flavor": "default",
"build_type": "tar",
"build_hash": "a846182fa16b4ebfcc89aa3c11a11fd5adf3de04",
"build_date": "2022-11-17T18:56:17.538630285Z",
"build_snapshot": false,
"lucene_version": "9.4.1",
"minimum_wire_compatibility_version": "7.17.0",
"minimum_index_compatibility_version": "7.0.0"
},
"tagline": "You Know, for Search"
}
很显然,密码的修改是成功的。
我们甚至可以使用如下的命令来移除不需要的 roles:
bin/elasticsearch-users roles liuxg -r network,monitoring -a user
上面的命令为 liuxg 用户移除 network 及 monitoring 角色,并添加 user 角色。
执行上面的命令后,我们重新检查用户的角色:
$ bin/elasticsearch-users list
liuxg : user*,admins
显然之前的 network 及 monitoring 已经被移除了。
我们还可以使用如下的命令来删除一个用户:
bin/elasticsearch-users userdel liuxg
上面的命令将删除 liuxg 用户。我们再次使用 list 命令来查看:
$ bin/elasticsearch-users list
No users found 我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
我的目标是转换表单输入,例如“100兆字节”或“1GB”,并将其转换为我可以存储在数据库中的文件大小(以千字节为单位)。目前,我有这个:defquota_convert@regex=/([0-9]+)(.*)s/@sizes=%w{kilobytemegabytegigabyte}m=self.quota.match(@regex)if@sizes.include?m[2]eval("self.quota=#{m[1]}.#{m[2]}")endend这有效,但前提是输入是倍数(“gigabytes”,而不是“gigabyte”)并且由于使用了eval看起来疯狂不安全。所以,功能正常,
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
好的,所以我的目标是轻松地将一些数据保存到磁盘以备后用。您如何简单地写入然后读取一个对象?所以如果我有一个简单的类classCattr_accessor:a,:bdefinitialize(a,b)@a,@b=a,bendend所以如果我从中非常快地制作一个objobj=C.new("foo","bar")#justgaveitsomerandomvalues然后我可以把它变成一个kindaidstring=obj.to_s#whichreturns""我终于可以将此字符串打印到文件或其他内容中。我的问题是,我该如何再次将这个id变回一个对象?我知道我可以自己挑选信息并制作一个接受该信
我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A
我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只