当前位置:网站首页>【ES实战】ES上的native realm安全方式使用
【ES实战】ES上的native realm安全方式使用
2022-07-05 05:16:00 【顧棟】
ES6.7版本安全与审计
文章目录
匿名访问(安全灰度过度)
在elasticsearch.yml文件中增加配置项。代表匿名用户拥有超级用户的权限。
xpack.security.authc.anonymous.roles: superuser
调整集群配置(源码的二次开发),支持动态开启和关闭匿名访问。
PUT /_cluster/settings
{
"persistent":{
"xpack.security.authc.anonymous.enabled":"true"
}
}
采用原生的realm方式进行账号权限认证
配置native realm
native其实是默认的,开启了安全特性之后就是启用状态。可以在elasticsearch.yml文件中通过配置项进行自定义调整,调整了配置需要进行重启生效。
security:
authc:
realms:
native1:
type: native
order: 0
配置项说明
| 属性名称 | 说明 | |
|---|---|---|
| type | 必填项。权限认证管理类型 | |
| order | realms链中realm的优先级。Defaults to Integer.MAX_VALUE. | |
| enabled | I指示是否启用realm。Defaults to true. | |
| cache.ttl | 缓存用户条目的生存时间。 Defaults to 20m. | |
| cache.max_users | 在任何给定时间可以存在于缓存中的最大用户条目数。 Defaults to 100,000. | |
| cache.hash_algo | 用于内存中缓存的用户凭据的散列算法。Defaults to ssha256. | |
| authentication.enabled | 如果设置为 false,则禁用此realm中的身份验证支持,使其仅支持用户查找。Defaults to true. |
管理使用API
详细参考官网文档security-api
创建/修改角色
权限说明参考:权限部分
POST _xpack/security/role/{
rolename}
{
"cluster": ["all"],
"indices": [{
"names": ["*"],"privileges": ["all"]}]
}
查看指定角色
GET _xpack/security/role/{
rolename}
查看all角色
GET _xpack/security/role
删除角色
DELETE _xpack/security/role/{
rolename}
创建/修改用户
POST _xpack/security/user/jacknich
{
"password" : "[email protected]",
"roles" : [ "admin", "other_role1" ],
"full_name" : "Jack Nicholson",
"email" : "[email protected]",
}
查询用户
GET _xpack/security/user/{
username}
修改密码
POST _xpack/security/user/{
username}/_password
{
"password" : "s3cr3t"
}
禁用用户
PUT _xpack/security/user/{
username}/_disable
启用用户
PUT /_xpack/security/user/{
username}/_enable
权限验证
GET _xpack/security/user/_has_privileges
{
"cluster": [ "monitor", "manage" ],
"index" : [
{
"names": [ "suppliers", "products" ],
"privileges": [ "read" ]
},
{
"names": [ "inventory" ],
"privileges" : [ "read", "write" ]
}
],
"application": [
{
"application": "inventory_manager",
"privileges" : [ "read", "data:write/inventory" ],
"resources" : [ "product/1852563" ]
}
]
}
注意点
- 先创建角色,主要使用
cluster和indices - 用户和角色 不支持局部修改,修改的时候需要在请求体上带上全部的配置
- 单独删除角色,不会删除用户中的角色属性。应当先清除用户中的角色名,防止之后新建重名的角色,导致越权问题。
审计安全日志
您可以启用审核以跟踪与安全相关的事件,例如身份验证失败和拒绝连接。 记录这些事件使您能够监控集群中的可疑活动,并在发生攻击时提供证据。
审计日志默认是关闭的,需要在elasticsearch.yml文件中通过设置 xpack.security.audit.enabled to true进行开启。
原本有两个审计日志的输出方式,但是目前已经废弃了写入索引的方式。直接写入日志文件。
默认情况下,启用审计时仅使用 logfile 输出,隐式输出到 <clustername>_audit.log 和 <clustername>_access.log。
审计事件类型
| 事件类型名 | 说明 |
|---|---|
anonymous_access_denied | 当请求因缺少身份验证令牌而被拒绝时记录。 |
authentication_success | 当用户成功验证时记录。 |
authentication_failed | 当身份验证令牌无法与已知用户匹配时记录。 |
realm_authentication_failed | 记录每个未能提供有效身份验证令牌的领域。 <realm> 表示领域类型。 |
access_denied | 当经过身份验证的用户尝试执行他们没有必要的 权限 来执行的操作时记录。 |
access_granted | 当经过身份验证的用户尝试执行他们具有执行所需权限的操作时记录。 当包含 system_access_granted 事件时,还会记录所有系统(内部)操作。 默认设置不记录系统操作以避免日志混乱。 |
run_as_granted | 当经过身份验证的用户尝试 run as 另一个他们有必要权限的用户时记录 . |
run_as_denied | 当经过身份验证的用户尝试 [run as] 另一个用户操作时记录,他们没有必要的 [privilege] 可以这样做。 |
tampered_request | 当安全功能检测到请求已被篡改时记录。 当滚动 ID 被认为已被篡改时,通常与“搜索/滚动”请求相关。 |
connection_granted | 当传入 TCP 连接通过特定配置文件的 IP 过滤器 时记录。 |
connection_denied | 当传入的 TCP 连接未通过特定配置文件的 IP 过滤器 时记录。 |
审计事件属性(公共)
在 6.5.0 中,有一个新的日志文件审计输出格式。 这种格式还为审计事件属性带来了一些变化。 新格式输出到 <clustername>_audit.log文件。 审计条目被格式化为平面 JSON 文档(也就是说,没有嵌套对象),每行一个。 因此,属性名称是 JSON 键,它们遵循点分名称语法。 不输出任何缺少值 (null) 的属性。 以下列表显示了所有审计事件共有的属性。 它们的名称和值类似于已弃用的日志文件或索引输出格式中的名称和值。 但是,预计这些格式将在 6.x 版本期间独立发展,因此建议遵循您正在使用的格式的属性描述。
| 属性名 | 说明 |
|---|---|
@timestamp | 事件发生的时间,采用 ISO9601 格式。 |
node.name | 节点的名称。 这可以在 elasticsearch.yml 配置文件中更改。 |
node.id | 节点标识。 这是自动生成的,并且在整个集群重新启动时保持不变。 |
host.ip | 节点的绑定IP地址,节点可以与之通信。 |
host.name | 未解析节点的主机名。 |
origin.address | 与此事件关联的请求的源 IP 地址。 这可能是远程客户端的地址、另一个集群节点的地址或本地节点的绑定地址(如果请求源自本地)。 除非远程客户端直接连接到集群,否则客户端地址实际上将是集群前面的第一个 OSI 第 3 层代理的地址。 |
origin.type | 与此事件关联的请求的来源类型:rest(请求源自 REST API 请求)、transport(在传输通道上接收到请求)或local_node(本地节点发出请求)。 |
event.type | 生成事件的内部处理层:rest、transport 或 ip_filter。 这与 origin.type 不同,因为来自 REST API 的请求被转换为许多传输消息,生成带有 origin.type: rest 和 event.type: transport 的审计事件。 |
event.action | 发生的事件类型: anonymous_access_denied, authentication_failed, authentication_success, realm_authentication_failed, access_denied, access_granted, connection_denied, connection_granted, tampered_request, run_as_denied, or run_as_granted. |
opaque_id | 与此事件关联的请求的X-Opaque-IdHTTP 标头(如果存在)的值。 客户端可以自由使用此标头来标记 API 调用,因为它在 Elasticsearch 中没有语义。 |
x_forwarded_for | 与审计事件关联的请求的X-Forwarded-ForHTTP 请求标头(如果存在)的逐字记录值。 此标头通常由代理在转发请求时添加,值是代理客户端的地址。 当请求跨越多个代理时,标头是一个逗号分隔的列表,最后一个值是倒数第二个代理服务器的地址(最后一个代理服务器的地址由origin.address字段指定)。 |
审核 REST 事件类型的事件属性
The events with event.type equal to rest have one of the following event.action attribute values: authentication_success, anonymous_access_denied, authentication_failed, realm_authentication_failed, tampered_request or run_as_denied.
| 属性名 | 说明 |
|---|---|
| url.path | 与此事件关联的 REST 请求的 URL 的路径部分(端口和查询字符串之间)。 这是 URL 编码的。 |
| url.query | 与此事件关联的 REST 请求的 URL 的查询部分(“?”之后,如果存在)。 这是 URL 编码的。 |
| request.method | 与此事件关联的 REST 请求的 HTTP 方法。 它是 GET、POST、PUT、DELETE、OPTIONS、HEAD、PATCH、TRACE 和 CONNECT 之一。 |
| request.body | 与此事件关联的 REST 请求的完整内容(如果启用)。 这包含查询正文。 正文根据 JSON RFC 4627 进行转义。 |
审核 TRASNPORT 事件类型的事件属性
The events with event.type equal to transport have one of the following event.action attribute values: authentication_success, anonymous_access_denied, authentication_failed, realm_authentication_failed, access_granted, access_denied, run_as_granted, run_as_denied, or tampered_request.
| 属性名 | 说明 |
|---|---|
| action | 已执行的传输操作的名称。 这类似于 REST 请求的 URL。 |
| indices | 与此事件关联的请求所属的索引名称数组(如果适用)。 |
request.name | 已执行的请求处理程序的名称。 |
审计 ip_filter 事件类型的事件属性
The events with event.type equal to ip_filter have one of the following event.action attribute values: connection_granted or connection_denied.
| 属性名 | 说明 |
|---|---|
| transport_profile | 请求所针对的传输配置文件。 |
| rule | 拒绝请求的 IP 过滤 规则。 |
特定事件的额外审计事件属性
authentication_success:authentication_failed:user.name未通过身份验证的用户的名称。 如果请求身份验证令牌无效或无法解析,则可能缺少此信息。
realm_authentication_failed:user.name未通过身份验证的用户的名称。
realm拒绝此身份验证的领域的名称。 此事件为链中的每个认证领域生成。
run_as_deniedandrun_as_granted:user.roles用户的角色组。
user.name被授予或拒绝 impersonation 操作的 authenticated 用户的名称。
user.realmauthenticated 用户所属的领域名称。
user.run_as.name授予或拒绝 impersonation 操作的用户的名称。
user.run_as.realmimpersonated 用户所属的领域名称。
access_grantedoraccess_denied:
日志的等级可以动态调整
PUT /_cluster/settings
{
"persistent": {
"logger.org.elasticsearch.xpack.security.audit.logfile.DeprecatedLoggingAuditTrail": "off"
}
}
审计日志事件忽略策略
通过配置项可以在日志中忽略与策略相关的日志
用户
xpack.security.audit.logfile.events.ignore_filters.<policy_name>.users权限认证领域
xpack.security.audit.logfile.events.ignore_filters.<policy_name>.realms角色
xpack.security.audit.logfile.events.ignore_filters.<policy_name>.roles索引
xpack.security.audit.logfile.events.ignore_filters.<policy_name>.indices
示例
xpack.security.audit.logfile.events.ignore_filters:
example1:
users: ["kibana", "admin_user"]
indices: ["app-logs*"]
roles: ["admin", "ops_admin_*"]
审计事件日志包含请求正文
请在 elasticsearch.yml 文件中编辑以下设置:
xpack.security.audit.logfile.events.emit_request_body: true
边栏推荐
猜你喜欢

Unity find the coordinates of a point on the circle

Web APIs DOM节点

【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research

嵌入式数据库开发编程(五)——DQL

Reverse one-way linked list of interview questions

Ue4/ue5 illusory engine, material part (III), material optimization at different distances

小程序直播+電商,想做新零售電商就用它吧!

Embedded database development programming (VI) -- C API

2022年上半年国家教师资格证考试

Unity get component
随机推荐
C4D simple cloth (version above R21)
Django reports an error when connecting to the database. What is the reason
[trans]: spécification osgi
Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
远程升级怕截胡?详解FOTA安全升级
2022/7/1學習總結
嵌入式数据库开发编程(六)——C API
Unity check whether the two objects have obstacles by ray
Bubble sort summary
Unity writes timetables (without UI)
Solon Auth 认证框架使用演示(更简单的认证框架)
UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存
Download and use of font icons
669. Prune binary search tree ●●
Establish cloth effect in 10 seconds
十年不用一次的JVM调用
How much do you know about 3DMAX rendering skills and HDRI light sources? Dry goods sharing
2022年上半年国家教师资格证考试
《动手学深度学习》学习笔记
Listview is added and deleted at the index