Keystone 事件通知

Keystone 提供关于使用数据的通知,以便第三方应用程序可以将这些数据用于计费、监控或配额目的。本文档描述了 Keystone 通知当前的包含和排除项。

Keystone 当前支持两种通知格式:基本通知和云审计数据联合 (CADF) 通知。以下文档介绍了这两种通知格式支持的操作。

通用通知结构

Keystone 生成的通知采用 JSON 格式。外部应用程序可以将它们格式化为 ATOM 格式并将其发布为 feed。目前,所有通知都是即时的,这意味着当特定事件发生时会生成它们。所有通知都遵循特定的顶级格式

{
    "event_type": "identity.<resource_type>.<operation>",
    "message_id": "<message_id>",
    "payload": {},
    "priority": "INFO",
    "publisher_id": "identity.<hostname>",
    "timestamp": "<timestamp>"
}

其中 <resource_type> 是 Keystone 资源,例如用户或项目,而 <operation> 是 Keystone 操作,例如创建、删除。

两种通知格式(基本和 CADF)之间的主要区别在于通知的 payload 部分。

通过 Keystone 配置文件无法配置发送通知的 priority。对于 Keystone 发送的所有通知,此值默认为 INFO。

使用 CADF 进行审计

Keystone 使用 PyCADF 库来发出 CADF 通知,这些事件符合 DMTF CADF 规范。该标准为符合安全、运营和业务流程的审计能力提供支持,并支持用于联合和聚合的标准化和分类的事件数据。

CADF 通知包含关于 resourceactioninitiator 的额外上下文数据。

可以通过在配置文件中将 notification_format 更改为 cadf 来发出 CADF 通知。

CADF 通知的 payload 部分是一个 CADF event,表示为一个 JSON 字典。例如

{
    "typeURI": "http://schemas.dmtf.org/cloud/audit/1.0/event",
    "initiator": {
        "typeURI": "service/security/account/user",
        "host": {
            "agent": "curl/7.22.0(x86_64-pc-linux-gnu)",
            "address": "127.0.0.1"
        },
        "id": "<initiator_id>"
    },
    "target": {
        "typeURI": "<target_uri>",
        "id": "openstack:1c2fc591-facb-4479-a327-520dade1ea15"
    },
    "observer": {
        "typeURI": "service/security",
        "id": "openstack:3d4a50a9-2b59-438b-bf19-c231f9c7625a"
    },
    "eventType": "activity",
    "eventTime": "2014-02-14T01:20:47.932842+00:00",
    "action": "<action>",
    "outcome": "success",
    "id": "openstack:f5352d7b-bee6-4c22-8213-450e7b646e9f",
}

其中定义了以下内容

  • <initiator_id>:执行操作的用户的 ID

  • <target_uri>:CADF 特定的目标 URI(例如:data/security/project)

  • <action>:执行的操作,通常为:<operation><resource_type>

注意

CADF payload 的 eventType 属性与通知的 event_type 属性不同。前者 (eventType) 是一个 CADF 关键字,用于指定正在测量的事件类型,可以是:activitymonitorcontrol。后者 (event_type) 如前所述描述为:identity.<resource_type>.<operation>

此外,根据执行的操作,可能存在额外的键,这些将在下面讨论。

原因

对于以下与 PCI-DSS 相关的事件,将存在特定的 reason 对象

PCI-DSS 部分

reasonCode

reasonType

8.1.6 通过在超过 X 次失败尝试后锁定用户来限制重复访问尝试。

401

超过最大数量 <number> 次登录尝试。

8.2.3 密码必须符合既定标准。

400

密码不符合预期要求:<regex_description>

8.2.4 密码必须每 X 天更改一次。

401

<user> 的密码已过期,必须更改

8.2.5 不要让用户在 X 天内重用上一个密码。

400

更改的密码不能与上一个 <number> 个密码相同。

其他 - 防止在最短年龄 <number> 天之前更改密码。

401

不能在最短年龄 <number> 天之前更改密码

reason 对象将包含以下键

  • reasonType:PCI-DSS 事件的描述

  • reasonCode:事件的 HTTP 响应代码

有关更多信息,请参阅 安全合规性和 PCI-DSS,了解在 Keystone 中配置 PCI-DSS 的信息。

支持的事件

下表显示了资源类型和操作之间的兼容性。

资源类型

支持的操作

typeURI

group

create,update,delete

data/security/group

project

create,update,delete

data/security/project

role

create,update,delete

data/security/role

domain

create,update,delete

data/security/domain

user

create,update,delete

data/security/account/user

trust

create,delete

data/security/trust

region

create,update,delete

data/security/region

endpoint

create,update,delete

data/security/endpoint

服务

create,update,delete

data/security/service

policy

create,update,delete

data/security/policy

role assignment

add,remove

data/security/account/user

authenticate

data/security/account/user

示例通知 - 项目创建

以下是一个在创建项目时发送的通知示例。此示例可用于表中的任何 createupdatedelete 事件。 <action>typeURI 字段将发生变化。

需要注意的是,resource_info 字段的包含,其中包含正在进行操作的 <resource_id>。从而在 CADF 和基本通知格式之间创建了一个通用元素。

{
    "event_type": "identity.project.created",
    "message_id": "0156ee79-b35f-4cef-ac37-d4a85f231c69",
    "payload": {
        "typeURI": "http://schemas.dmtf.org/cloud/audit/1.0/event",
        "initiator": {
            "typeURI": "service/security/account/user",
            "host": {
                "agent": "curl/7.22.0(x86_64-pc-linux-gnu)",
                "address": "127.0.0.1"
            },
            "id": "c9f76d3c31e142af9291de2935bde98a"
        },
        "target": {
            "typeURI": "data/security/project",
            "id": "openstack:1c2fc591-facb-4479-a327-520dade1ea15"
        },
        "observer": {
            "typeURI": "service/security",
            "id": "openstack:3d4a50a9-2b59-438b-bf19-c231f9c7625a"
        },
        "eventType": "activity",
        "eventTime": "2014-02-14T01:20:47.932842+00:00",
        "action": "created.project",
        "outcome": "success",
        "id": "openstack:f5352d7b-bee6-4c22-8213-450e7b646e9f",
        "resource_info": "671da331c47d4e29bb6ea1d270154ec3"
    },
    "priority": "INFO",
    "publisher_id": "identity.host1234",
    "timestamp": "2013-08-29 19:03:45.960280"
}

示例通知 - 身份验证

以下是一个用户使用 Keystone 进行身份验证时发送的通知示例。

请注意,如果用户成功进行身份验证,并且当用户身份验证失败时,将发出此通知。

{
    "event_type": "identity.authenticate",
    "message_id": "1371a590-d5fd-448f-b3bb-a14dead6f4cb",
    "payload": {
        "typeURI": "http://schemas.dmtf.org/cloud/audit/1.0/event",
        "initiator": {
            "typeURI": "service/security/account/user",
            "host": {
                "agent": "curl/7.22.0(x86_64-pc-linux-gnu)",
                "address": "127.0.0.1"
            },
            "id": "c9f76d3c31e142af9291de2935bde98a"
        },
        "target": {
            "typeURI": "service/security/account/user",
            "id": "openstack:1c2fc591-facb-4479-a327-520dade1ea15"
        },
        "observer": {
            "typeURI": "service/security",
            "id": "openstack:3d4a50a9-2b59-438b-bf19-c231f9c7625a"
        },
        "eventType": "activity",
        "eventTime": "2014-02-14T01:20:47.932842+00:00",
        "action": "authenticate",
        "outcome": "success",
        "id": "openstack:f5352d7b-bee6-4c22-8213-450e7b646e9f"
    },
    "priority": "INFO",
    "publisher_id": "identity.host1234",
    "timestamp": "2014-02-14T01:20:47.932842"
}

示例通知 - 联合身份验证

以下是一个用户通过联合身份验证使用 Keystone 进行身份验证时发送的通知示例。

此示例类似于上述示例,但是 payloadinitiator 部分包含一个新的 credential 部分。

{
    "event_type": "identity.authenticate",
    "message_id": "1371a590-d5fd-448f-b3bb-a14dead6f4cb",
    "payload": {
        "typeURI": "http://schemas.dmtf.org/cloud/audit/1.0/event",
        "initiator": {
            "credential": {
                "type": "http://docs.oasis-open.org/security/saml/v2.0",
                "token": "671da331c47d4e29bb6ea1d270154ec3",
                "identity_provider": "ACME",
                "user": "c9f76d3c31e142af9291de2935bde98a",
                "groups": [
                    "developers"
                ]
            },
            "typeURI": "service/security/account/user",
            "host": {
                "agent": "curl/7.22.0(x86_64-pc-linux-gnu)",
                "address": "127.0.0.1"
            },
            "id": "c9f76d3c31e142af9291de2935bde98a"
        },
        "target": {
            "typeURI": "service/security/account/user",
            "id": "openstack:1c2fc591-facb-4479-a327-520dade1ea15"
        },
        "observer": {
            "typeURI": "service/security",
            "id": "openstack:3d4a50a9-2b59-438b-bf19-c231f9c7625a"
        },
        "eventType": "activity",
        "eventTime": "2014-02-14T01:20:47.932842+00:00",
        "action": "authenticate",
        "outcome": "success",
        "id": "openstack:f5352d7b-bee6-4c22-8213-450e7b646e9f"
    },
    "priority": "INFO",
    "publisher_id": "identity.host1234",
    "timestamp": "2014-02-14T01:20:47.932842"
}

示例通知 - 角色分配

以下是一个将角色授予或撤销给项目或域,对于用户或组时发送的通知示例。

重要的是要注意,此类型的通知具有许多新的键,这些键传达必要的信息。请在下面讨论以下内容:payload 中:roleinherited_to_projectprojectdomainusergroup。除 inherited_to_project 之外,每个都将代表资源的唯一标识符。

{
    "event_type": "identity.role_assignment.created",
    "message_id": "a5901371-d5fd-b3bb-448f-a14dead6f4cb",
    "payload": {
        "typeURI": "http://schemas.dmtf.org/cloud/audit/1.0/event",
        "initiator": {
            "typeURI": "service/security/account/user",
            "host": {
                "agent": "curl/7.22.0(x86_64-pc-linux-gnu)",
                "address": "127.0.0.1"
            },
            "id": "c9f76d3c31e142af9291de2935bde98a"
        },
        "target": {
            "typeURI": "service/security/account/user",
            "id": "openstack:1c2fc591-facb-4479-a327-520dade1ea15"
        },
        "observer": {
            "typeURI": "service/security",
            "id": "openstack:3d4a50a9-2b59-438b-bf19-c231f9c7625a"
        },
        "eventType": "activity",
        "eventTime": "2014-08-20T01:20:47.932842+00:00",
        "role": "0e6b990380154a2599ce6b6e91548a68",
        "project": "24bdcff1aab8474895dbaac509793de1",
        "inherited_to_projects": false,
        "group": "c1e22dc67cbd469ea0e33bf428fe597a",
        "action": "created.role_assignment",
        "outcome": "success",
        "id": "openstack:f5352d7b-bee6-4c22-8213-450e7b646e9f"
    },
    "priority": "INFO",
    "publisher_id": "identity.host1234",
    "timestamp": "2014-08-20T01:20:47.932842"
}

示例通知 - 过期密码

以下是一个用户尝试身份验证但密码已过期时发送的通知示例。

在此示例中,payload 包含一个 reason 部分,其中包含 reasonCodereasonType

{
    "priority": "INFO",
    "_unique_id": "222441bdc958423d8af6f28f9c558614",
    "event_type": "identity.authenticate",
    "timestamp": "2016-11-11 18:31:11.290821",
    "publisher_id": "identity.host1234",
    "payload": {
        "typeURI": "http://schemas.dmtf.org/cloud/audit/1.0/event",
        "initiator": {
            "typeURI": "service/security/account/user",
            "host": {
                "address": "127.0.0.1"
            },
            "id": "73a19db6-e26b-5313-a6df-58d297fa652e"
        },
        "target": {
            "typeURI": "service/security/account/user",
            "id": "c23e6cb7-abe0-5e42-b7f7-4c4104ea77b0"
        },
        "observer": {
            "typeURI": "service/security",
            "id": "9bdddeda6a0b451e9e0439646e532afd"
        },
        "eventType": "activity",
        "eventTime": "2016-11-11T18:31:11.156356+0000",
        "reason": {
            "reasonCode": 401,
            "reasonType": "The password is expired and needs to be reset for user: ed1ab0b40f284fb48fea9e25d0d157fc"
        },
        "action": "authenticate",
        "outcome": "failure",
        "id": "78cd795f-5850-532f-9ab1-5adb04e30c0f"
    },
    "message_id": "9a97e9d0-fef1-4852-8e82-bb693358bc46"
}

示例通知 - 无效密码身份验证

以下是一个用户提供无效密码时发送的通知示例。

请注意,payloadactionauthenticate,并且 outcomefailure

{
    "_unique_id": "b218f7fd79494ef2a3ab96af4b13a71b",
    "event_type": "identity.authenticate",
    "message_id": "e23bee7e-0753-4824-885c-e0f86179671f",
    "payload": {
        "action": "authenticate",
        "attachments": [
            {
                "content": "EpDKTqHklwreBBXhXv81jlYkYNfcDYj2XBrKrMGrjac",
                "name": "partial_password_hash",
                "typeURI": "mime:text/plain"
            }
        ],
        "eventTime": "2025-03-27T17:09:37.318590+0000",
        "eventType": "activity",
        "id": "7f160bb3-762c-5dee-93a3-e4c46324a6d8",
        "initiator": {
            "host": {
                "address": "127.0.0.1",
                "agent": "openstacksdk/4.3.0 keystoneauth1/5.9.1 python-requests/2.32.3 CPython/3.12.7"
            },
            "id": "d7bec06f41254509987354d0c0581cdc",
            "request_id": "req-214d0f85-74a4-441b-85b5-c1159341d577",
            "typeURI": "service/security/account/user",
            "user_id": "d7bec06f41254509987354d0c0581cdc",
            "username": "admin"
        },
        "observer": {
            "id": "f11c53400a5247baa2f120ff36c66b8f",
            "typeURI": "service/security"
        },
        "outcome": "failure",
        "target": {
            "id": "5ca93d89-b1fd-5245-9c37-508f0a034289",
            "typeURI": "service/security/account/user"
        },
        "typeURI": "http://schemas.dmtf.org/cloud/audit/1.0/event"
    },
    "priority": "INFO",
    "publisher_id": "identity.host1234",
    "timestamp": "2025-03-27 17:09:37.318895"
}

在此示例中,payload 还包含 attachments 部分,其中包含 partial_password_hash attachment,仅当 security_compliance.report_invalid_password_hash 配置文件选项显式设置为 event 时才会显示。 content 值随后可以进一步分析,以区分密码攻击与例如外部用户自动化未及时更新轮换密码,通过分析哈希值的可变性 - 如果提交的密码发生变化(例如,由于暴力破解或字典攻击),则哈希值会发生变化。请参阅配置选项文档,并在相应的 Keystone 规范 中找到更多详细信息。

基本通知

所有基本通知都包含有限的信息,具体而言,仅包含资源类型、操作和资源 ID。

基本通知的 payload 部分是一个键值对。

{
    "resource_info": <resource_id>
}

其中 <resource_id> 是分配给正在进行 <operation>resource_type 的唯一标识符。

支持的事件

下表显示了资源类型和操作之间的兼容性。

资源类型

支持的操作

group

create,update,delete

project

create,update,delete

role

create,update,delete

domain

create,update,delete

user

create,update,delete

trust

create,delete

region

create,update,delete

endpoint

create,update,delete

服务

create,update,delete

policy

create,update,delete

请注意,trusts 是一个不可变的资源,不支持 update 操作。

示例通知

这是一个为新创建的用户发送通知的示例

{
    "event_type": "identity.user.created",
    "message_id": "0156ee79-b35f-4cef-ac37-d4a85f231c69",
    "payload": {
        "resource_info": "671da331c47d4e29bb6ea1d270154ec3"
    },
    "priority": "INFO",
    "publisher_id": "identity.host1234",
    "timestamp": "2013-08-29 19:03:45.960280"
}

如果操作失败,将不会发送通知,也不会发送任何特殊的错误通知。错误信息通过正常的异常路径处理。

消费者建议

Keystone 发出的最重要的通知之一是项目删除 (event_type = identity.project.deleted)。此事件应指示 OpenStack 的其余部分,应删除与项目关联的所有资源(例如虚拟机)。

项目还可以具有更新事件 (event_type = identity.project.updated),其中项目已被禁用。Keystone 确保这立即影响到项目资源的可用性,方法是撤销对项目具有授权的令牌,但不应直接影响项目资源(换句话说,不应删除虚拟机)。

退出某些通知

Keystone 发出许多通知,并且某些部署者可能只关心某些事件。在 Keystone 中,有一种退出某些通知的方法。在 /etc/keystone/keystone.conf 中,您可以将 opt_out 设置为要退出的事件。可以退出多个事件。

示例

[DEFAULT]
notification_opt_out = identity.user.created
notification_opt_out = identity.role_assignment.created
notification_opt_out = identity.authenticate.pending

这将退出用户创建、角色分配创建和成功身份验证的通知。有关可用于事件类型的列表,请参阅:遥测测量

默认情况下,由于过于嘈杂,以下身份验证事件的消息将被抑制:identity.authenticate.successidentity.authenticate.pendingidentity.authenticate.failed