修改 YAML 文件
安全安装提供了一些 YAML 配置文件,用于存储定义安全插件管理集群内用户、角色和活动方式的必要设置。这些设置包括身份验证后端配置以及允许的端点和 HTTP 请求列表。
在运行 securityadmin.sh
将设置加载到 .opendistro_security
索引之前,请对 YAML 文件进行初始配置。这些文件可以在 config/opensearch-security
目录中找到。备份这些文件也是一个好习惯,以便您可以将它们用于其他集群。
我们推荐使用 YAML 文件的方法是首先配置保留和隐藏资源,例如 admin
和 kibanaserver
用户。之后,您可以使用 OpenSearch Dashboards 或 REST API 创建其他用户、角色、映射、操作组和租户。
action_groups.yml
此文件包含您的安全配置所需的任何角色映射。您可以在 <OPENSEARCH_HOME>/config/opensearch-security/roles_mapping.yml
中找到 role_mapping.yml
文件。
除了一些元数据,默认文件是空的,因为安全插件自动添加了一些静态操作组。这些静态操作组涵盖了广泛的使用场景,是开始使用该插件的好方法。
---
my-action-group:
reserved: false
hidden: false
allowed_actions:
- "indices:data/write/index*"
- "indices:data/write/update*"
- "indices:admin/mapping/put"
- "indices:data/write/bulk*"
- "read"
- "write"
static: false
_meta:
type: "actiongroups"
config_version: 2
allowlist.yml
您可以使用 allowlist.yml
将任何端点和 HTTP 请求添加到允许的端点和请求列表中。如果启用,除超级管理员外的所有用户都只被允许访问指定的端点和 HTTP 请求,与该端点关联的所有其他 HTTP 请求都将被拒绝。例如,如果将 GET _cluster/settings
添加到允许列表中,用户就不能向 _cluster/settings
提交 PUT 请求来更新集群设置。
您可以在 <OPENSEARCH_HOME>/config/opensearch-security/allowlist.yml
中找到 allowlist.yml
文件。
请注意,尽管您可以通过这种方式配置对端点的访问,但在大多数情况下,最好还是使用安全插件的用户和角色来配置权限,它们具有更细粒度的设置。
---
_meta:
type: "allowlist"
config_version: 2
# Description:
# enabled - feature flag.
# if enabled is false, all endpoints are accessible.
# if enabled is true, all users except the SuperAdmin can only submit the allowed requests to the specified endpoints.
# SuperAdmin can access all APIs.
# SuperAdmin is defined by the SuperAdmin certificate, which is configured with the opensearch.yml setting plugins.security.authcz.admin_dn:
# Refer to the example setting in opensearch.yml to learn more about configuring SuperAdmin.
#
# requests - map of allow listed endpoints and HTTP requests
#this name must be config
config:
enabled: true
requests:
/_cluster/settings:
- GET
/_cat/nodes:
- GET
要启用对集群设置的 PUT 请求,请在 /_cluster/settings
下的允许操作列表中添加 PUT。
requests:
/_cluster/settings:
- GET
- PUT
您还可以将自定义索引添加到允许列表中。allowlist.yml
不支持通配符,因此您必须手动指定所有要添加的索引。
requests: # Only allow GET requests to /sample-index1/_doc/1 and /sample-index2/_doc/1
/sample-index1/_doc/1:
- GET
/sample-index2/_doc/1:
- GET
internal_users.yml
此文件包含您要添加到安全插件内部用户数据库中的任何初始用户。您可以在 <OPENSEARCH_HOME>/config/opensearch-security/internal_users.yml
中找到此文件。
文件格式要求使用哈希密码。要生成密码,请运行 plugins/opensearch-security/tools/hash.sh -p <new-password>
。如果您决定保留任何演示用户,请更改他们的密码并重新运行 securityadmin.sh 以应用新密码。
---
# This is the internal user database
# The hash value is a bcrypt hash and can be generated with plugin/tools/hash.sh
_meta:
type: "internalusers"
config_version: 2
# Define your internal users here
new-user:
hash: "$2y$12$88IFVl6IfIwCFh5aQYfOmuXVL9j2hz/GusQb35o.4sdTDAEMTOD.K"
reserved: false
hidden: false
opendistro_security_roles:
- "specify-some-security-role-here"
backend_roles:
- "specify-some-backend-role-here"
attributes:
attribute1: "value1"
static: false
## Demo users
admin:
hash: "$2a$12$VcCDgh2NDk07JGN0rjGbM.Ad41qVR/YFJcgHp0UGns5JDymv..TOG"
reserved: true
backend_roles:
- "admin"
description: "Demo admin user"
kibanaserver:
hash: "$2a$12$4AcgAt3xwOWadA5s5blL6ev39OXDNhmOesEoo33eZtrq2N0YrU3H."
reserved: true
description: "Demo user for the OpenSearch Dashboards server"
kibanaro:
hash: "$2a$12$JJSXNfTowz7Uu5ttXfeYpeYE0arACvcwlPBStB1F.MI7f0U9Z4DGC"
reserved: false
backend_roles:
- "kibanauser"
- "readall"
attributes:
attribute1: "value1"
attribute2: "value2"
attribute3: "value3"
description: "Demo read-only user for OpenSearch dashboards"
logstash:
hash: "$2a$12$u1ShR4l4uBS3Uv59Pa2y5.1uQuZBrZtmNfqB3iM/.jL0XoV9sghS2"
reserved: false
backend_roles:
- "logstash"
description: "Demo logstash user"
readall:
hash: "$2a$12$ae4ycwzwvLtZxwZ82RmiEunBbIPiAmGZduBAjKN0TXdwQFtCwARz2"
reserved: false
backend_roles:
- "readall"
description: "Demo readall user"
snapshotrestore:
hash: "$2y$12$DpwmetHKwgYnorbgdvORCenv4NAK8cPUg8AI6pxLCuWf/ALc0.v7W"
reserved: false
backend_roles:
- "snapshotrestore"
description: "Demo snapshotrestore user"
nodes_dn.yml
nodes_dn.yml
允许您将证书的专有名称 (DN) 添加到允许列表中,以实现任意数量节点或集群之间的通信。例如,其允许列表中包含 DN CN=node1.example.com
的节点将接受使用该 DN 的任何其他节点或证书的通信。
DN 会被索引到系统索引中,只有超级管理员或拥有传输层安全 (TLS) 证书的管理员才能访问。如果您想通过编程方式将 DN 添加到允许列表中,请使用 REST API。
---
_meta:
type: "nodesdn"
config_version: 2
# Define nodesdn mapping name and corresponding values
# cluster1:
# nodes_dn:
# - CN=*.example.com
roles_mapping.yml
---
manage_snapshots:
reserved: true
hidden: false
backend_roles:
- "snapshotrestore"
hosts: []
users: []
and_backend_roles: []
logstash:
reserved: false
hidden: false
backend_roles:
- "logstash"
hosts: []
users: []
and_backend_roles: []
own_index:
reserved: false
hidden: false
backend_roles: []
hosts: []
users:
- "*"
and_backend_roles: []
description: "Allow full access to an index named like the username"
kibana_user:
reserved: false
hidden: false
backend_roles:
- "kibanauser"
hosts: []
users: []
and_backend_roles: []
description: "Maps kibanauser to kibana_user"
complex-role:
reserved: false
hidden: false
backend_roles:
- "ldap-analyst"
hosts: []
users:
- "new-user"
and_backend_roles: []
_meta:
type: "rolesmapping"
config_version: 2
all_access:
reserved: true
hidden: false
backend_roles:
- "admin"
hosts: []
users: []
and_backend_roles: []
description: "Maps admin to all_access"
readall:
reserved: true
hidden: false
backend_roles:
- "readall"
hosts: []
users: []
and_backend_roles: []
kibana_server:
reserved: true
hidden: false
backend_roles: []
hosts: []
users:
- "kibanaserver"
and_backend_roles: []
roles.yml
此文件包含您要添加到安全插件中的任何初始角色。默认情况下,此文件包含预定义角色,这些角色授予对 OpenSearch 默认发行版中插件的使用权限。安全插件还将自动添加一些静态角色。
---
complex-role:
reserved: false
hidden: false
cluster_permissions:
- "read"
- "cluster:monitor/nodes/stats"
- "cluster:monitor/task/get"
index_permissions:
- index_patterns:
- "opensearch_dashboards_sample_data_*"
dls: "{\"match\": {\"FlightDelay\": true}}"
fls:
- "~FlightNum"
masked_fields:
- "Carrier"
allowed_actions:
- "read"
tenant_permissions:
- tenant_patterns:
- "analyst_*"
allowed_actions:
- "kibana_all_write"
static: false
_meta:
type: "roles"
config_version: 2
tenants.yml
您可以使用此文件指定并向您的 OpenSearch 集群添加任意数量的 OpenSearch Dashboards 租户。有关租户的更多信息,请参阅OpenSearch Dashboards 多租户。
与所有其他 YAML 文件一样,我们建议您使用 tenants.yml
添加集群中必须有的任何租户,然后如果您需要进一步配置或创建任何其他租户,请使用 OpenSearch Dashboards 或 REST API。
---
_meta:
type: "tenants"
config_version: 2
admin_tenant:
reserved: false
description: "Demo tenant for admin user"
opensearch.yml
除了许多 OpenSearch 设置外,opensearch.yml
文件还包含 TLS 证书及其属性的路径,例如专有名称和受信任的证书颁发机构。您可以在 <OPENSEARCH_HOME>/config/
中找到此文件。
plugins.security.ssl.transport.pemcert_filepath: esnode.pem
plugins.security.ssl.transport.pemkey_filepath: esnode-key.pem
plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pem
plugins.security.ssl.transport.enforce_hostname_verification: false
plugins.security.ssl.http.enabled: true
plugins.security.ssl.http.pemcert_filepath: esnode.pem
plugins.security.ssl.http.pemkey_filepath: esnode-key.pem
plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem
plugins.security.allow_unsafe_democertificates: true
plugins.security.allow_default_init_securityindex: true
plugins.security.authcz.admin_dn:
- CN=kirk,OU=client,O=client,L=test, C=de
plugins.security.audit.type: internal_opensearch
plugins.security.enable_snapshot_restore_privilege: true
plugins.security.check_snapshot_restore_write_privileges: true
plugins.security.cache.ttl_minutes: 60
plugins.security.restapi.roles_enabled: ["all_access", "security_rest_api_access"]
plugins.security.system_indices.enabled: true
plugins.security.system_indices.indices: [".opendistro-alerting-config", ".opendistro-alerting-alert*", ".opendistro-anomaly-results*", ".opendistro-anomaly-detector*", ".opendistro-anomaly-checkpoints", ".opendistro-anomaly-detection-state", ".opendistro-reports-*", ".opendistro-notifications-*", ".opendistro-notebooks", ".opendistro-asynchronous-search-response*"]
node.max_local_storage_nodes: 3
有关 opensearch.yml
安全插件设置的完整列表,请参阅安全设置。
优化您的配置
当 plugins.security.allow_default_init_securityindex
设置为 true
时,如果 OpenSearch 启动时创建安全索引失败,则安全插件将设置为其默认安全设置。默认安全设置存储在 opensearch-project/security/config
目录中的 YAML 文件中。默认情况下,此设置是 false
。
plugins.security.allow_default_init_securityindex: true
安全插件存在一个身份验证缓存,通过临时存储从后端返回的用户对象来帮助加快身份验证,从而使安全插件无需重复请求这些对象。要确定缓存超时所需的时间,您可以使用 plugins.security.cache.ttl_minutes
属性设置一个以分钟为单位的值。默认值为 60
。您可以通过将值设置为 0
来禁用缓存。
plugins.security.cache.ttl_minutes: 60
启用用户访问系统索引
将系统索引权限映射到用户,允许该用户修改权限名称中指定的系统索引(唯一例外是安全插件的系统索引)。plugins.security.system_indices.permission.enabled
设置为管理员提供了一种方法,使此权限可用于或隐藏于角色映射。
当设置为 true
时,此功能将启用,并且具有修改角色权限的用户可以创建包含授予系统索引访问权限的角色
plugins.security.system_indices.permission.enabled: true
当设置为 false
时,该权限被禁用,只有持有管理员证书的管理员才能对系统索引进行更改。默认情况下,在新集群中,该权限设置为 false
。
要了解有关系统索引权限的更多信息,请参阅 系统索引权限。
密码设置
如果您希望对用户密码进行验证,请在此文件中指定一个正则表达式 (regex)。您还可以包含一个错误消息,在密码未通过验证时加载。以下示例演示了如何包含一个正则表达式,以便 OpenSearch 要求新密码至少为八个字符,并且至少包含一个大写字母、一个小写字母、一个数字和一个特殊字符。
请注意,OpenSearch 仅验证通过 OpenSearch Dashboards 或 REST API 创建的用户和密码。
plugins.security.restapi.password_validation_regex: '(?=.*[A-Z])(?=.*[^a-zA-Z\d])(?=.*[0-9])(?=.*[a-z]).{8,}'
plugins.security.restapi.password_validation_error_message: "Password must be minimum 8 characters long and must contain at least one uppercase letter, one lowercase letter, one digit, and one special character."
此外,基于分数的密码强度评估器允许您在创建新的内部用户或更新用户密码时设置密码强度阈值。此功能利用 zxcvbn 库来应用一项策略,该策略强调密码的复杂性,而不是其满足传统标准(如大写字母、数字和特殊字符)的能力。
有关定义用户的信息,请参阅 定义用户。
此功能与指定为保留的用户不兼容。有关保留资源的信息,请参阅 保留和隐藏资源。
基于分数的密码强度需要两个设置来配置此功能。下表描述了这两个设置。
设置 | 描述 |
---|---|
plugins.security.restapi.password_min_length | 设置密码长度的最小字符数。默认值为 8 。这也是最小值。 |
plugins.security.restapi.password_score_based_validation_strength | 设置一个阈值以确定密码是强还是弱。有四个值代表阈值复杂性的递增。fair –一个非常“容易猜测”的密码:提供抵御受限在线攻击的保护。good –一个有些容易猜测的密码:提供抵御不受限在线攻击的保护。strong –一个安全地“难以猜测”的密码:提供对离线、慢哈希场景的适度保护。very_strong –一个非常难以猜测的密码:提供对离线、慢哈希场景的强大保护。 |
以下示例显示了为 opensearch.yml
文件配置的设置,并启用了密码长度至少为 10 个字符且阈值要求最高强度的功能
plugins.security.restapi.password_min_length: 10
plugins.security.restapi.password_score_based_validation_strength: very_strong
当您尝试创建密码未达到指定阈值的用户时,系统会生成“弱密码”警告,表明需要修改密码才能保存该用户。
以下示例显示了密码较弱时,创建用户 API 的响应
{
"status": "error",
"reason": "Weak password"
}