Amazon EventBridge 事件总线的权限 - Amazon EventBridge
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon EventBridge 事件总线的权限

您 Amazon 账户中的默认事件总线仅允许来自一个账户的事件。您可以为事件总线附加基于资源的策略,向其授予其他权限。使用基于资源的策略,您可以允许来自其他账户的 PutEventsPutRulePutTargets API 调用。您还可以在策略中使用 IAM 条件向组织授予权限、应用标签或仅筛选来自特定规则或账户的事件。您可以在创建事件总线时为其设置基于资源的策略,也可以稍后设置。

接受事件总线 Name 参数的 EventBridge API,例如 PutRulePutTargetsDeleteRuleRemoveTargetsDisableRuleEnableRule,也接受事件总线 ARN。使用这些参数通过 API 引用跨账户或跨区域的事件总线。例如,您可以调用 PutRule,在其他账户的事件总线上创建规则,而无需担任角色。

您可以将本主题中的示例策略附加到 IAM 角色,授予向其他账户或区域发送事件的权限。使用 IAM 角色设置组织控制策略和边界,确定谁可以将事件从您的账户发送到其他账户。如果规则的目标是事件总线,我们建议始终使用 IAM 角色。您可以使用 PutTarget 调用来附加 IAM 角色。有关如何创建规则并向其他账户或区域发送事件的的信息,请参阅在 Amazon 账户之间发送和接收 Amazon EventBridge 事件

管理事件总线权限

使用以下过程修改现有事件总线的权限。有关如何使用 Amazon CloudFormation 创建事件总线策略的信息,请参阅 AWS::Events::EventBusPolicy

管理现有事件总线的权限
  1. 访问 https://console.aws.amazon.com/events/,打开 Amazon EventBridge 控制台。

  2. 在左侧导航窗格中,选择事件总线

  3. 名称中,选择要管理权限的事件总线的名称。

    如果有某个资源策略附加到此事件总线,则会显示该策略。

  4. 选择管理权限,然后执行以下操作之一:

    • 输入策略,其中包含要为事件总线授予的权限。您可以粘贴其他来源的策略,也可以为此策略输入 JSON。

    • 要使用策略模板,请选择加载模板。根据您的环境修改策略,并添加其他操作,授权策略中的主体使用。

  5. 选择更新

该模板提供了示例策略语句,您可以根据自己的账户和环境对其进行自定义。模板不是有效策略。您可以根据您的使用场景修改模板,也可以复制其中一个示例策略并对其进行自定义。

该模板加载的策略包括一个示例,展示如何向账户授予使用 PutEvents 操作的权限、如何向组织授予权限以及如何向该账户授予权限,以管理账户中的规则。您可以为特定账户自定义模板,然后从模板中删除其他部分。本主题的后续部分会包含更多策略示例。

如果您尝试更新总线的权限,但策略中包含错误,则会显示一条错误消息,指明策略中的具体问题。

### Choose which sections to include in the policy to match your use case. ### ### Be sure to remove all lines that start with ###, including the ### at the end of the line. ### ### The policy must include the following: ### { "Version": "2012-10-17", "Statement": [ ### To grant permissions for an account to use the PutEvents action, include the following, otherwise delete this section: ### { "Sid": "AllowAccountToPutEvents", "Effect": "Allow", "Principal": { "AWS": "<ACCOUNT_ID>" }, "Action": "events:PutEvents", "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/default" }, ### Include the following section to grant permissions to all members of your Amazon Organizations to use the PutEvents action ### { "Sid": "AllowAllAccountsFromOrganizationToPutEvents", "Effect": "Allow", "Principal": "*", "Action": "events:PutEvents", "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/default", "Condition": { "StringEquals": { "aws:PrincipalOrgID": "o-yourOrgID" } } }, ### Include the following section to grant permissions to the account to manage the rules created in the account ### { "Sid": "AllowAccountToManageRulesTheyCreated", "Effect": "Allow", "Principal": { "AWS": "<ACCOUNT_ID>" }, "Action": [ "events:PutRule", "events:PutTargets", "events:DeleteRule", "events:RemoveTargets", "events:DisableRule", "events:EnableRule", "events:TagResource", "events:UntagResource", "events:DescribeRule", "events:ListTargetsByRule", "events:ListTagsForResource"], "Resource": "arn:aws:events:us-east-1:123456789012:rule/default", "Condition": { "StringEqualsIfExists": { "events:creatorAccount": "<ACCOUNT_ID>" } } }] }

策略示例:向另一账户中的默认总线发送事件

以下策略示例授予账户 111122223333 向账户 123456789012 中的默认事件总线发布事件的权限。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "sid1", "Effect": "Allow", "Principal": {"AWS":"arn:aws:iam::111112222333:root"}, "Action": "events:PutEvents", "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/default" } ] }

策略示例:向另一账户中的自定义总线发送事件

以下策略示例向账户 111122223333 授予权限,向账户 123456789012 中的 central-event-bus 发布事件,但仅适用于源值设置为 com.exampleCorp.webStoredetail-type 设置为 newOrderCreated 的事件。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "WebStoreCrossAccountPublish", "Effect": "Allow", "Action": [ "events:PutEvents" ], "Principal": { "AWS": "arn:aws:iam::111112222333:root" }, "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/central-event-bus", "Condition": { "StringEquals": { "events:detail-type": "newOrderCreated", "events:source": "com.exampleCorp.webStore" } } } ] }

策略示例:将事件发送到同一账户中的事件总线

以下策略示例附加到名为 CustomBus1 的事件总线,允许该事件总线接收来自同一账户和区域的事件。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "events:PutEvents" ], "Resource": [ "arn:aws:events:us-east-1:123456789:event-bus/CustomBus1" ] } ] }

策略示例:向同一账户发送事件并限制更新

以下策略示例向账户 123456789012 授予权限,以创建、删除、更新、禁用和启用规则,并添加或删除目标。它限制这些规则,与来源为 com.exampleCorp.webStore 的事件匹配,并使用 "events:creatorAccount": "${aws:PrincipalAccount}" 来确保只有账户 123456789012 才能在创建这些规则和目标后对其进行修改。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "InvoiceProcessingRuleCreation", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:root" }, "Action": [ "events:PutRule", "events:DeleteRule", "events:DescribeRule", "events:DisableRule", "events:EnableRule", "events:PutTargets", "events:RemoveTargets" ], "Resource": "arn:aws:events:us-east-1:123456789012:rule/central-event-bus/*", "Condition": { "StringEqualsIfExists": { "events:creatorAccount": "${aws:PrincipalAccount}", "events:source": "com.exampleCorp.webStore" } } } ] }

策略示例:仅将事件从特定规则发送到不同区域中的总线

以下策略示例授予账户 111122223333 权限,将与中东(巴林)和美国西部(俄勒冈州)区域中名为 SendToUSE1AnotherAccount 的规则匹配的事件发送到账户 123456789012 中名为 CrossRegionBus 的事件总线,该账户位于美国东部(弗吉尼亚州北部)。策略示例已添加到账户 123456789012 中名为 CrossRegionBus 的事件总线。只有当事件与账户 111122223333 中为此事件总线指定的规则相匹配时,该策略才允许这些事件。Condition 语句将事件限制为仅与具有指定规则 ARN 的规则匹配的事件。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSpecificRulesAsCrossRegionSource", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111112222333:root" }, "Action": "events:PutEvents", "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/CrossRegionBus", "Condition": { "ArnEquals": { "aws:SourceArn": [ "arn:aws:events:us-west-2:111112222333:rule/CrossRegionBus/SendToUSE1AnotherAccount", "arn:aws:events:me-south-1:111112222333:rule/CrossRegionBus/SendToUSE1AnotherAccount" ] } } } ] }

策略示例:仅将事件从特定区域发送到另一区域

以下策略示例授予账户 111122223333 权限,将在中东(巴林)和美国西部(俄勒冈州)区域中生成的所有事件发送到账户 123456789012 中名为 CrossRegionBus 的事件总线,该账户位于美国东部(弗吉尼亚州北部)区域。账户 111122223333 无权发送在任何其他区域生成的事件。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowCrossRegionEventsFromUSWest2AndMESouth1", "Effect": "Allow", "Principal": { "Amazon": "arn:aws:iam::111112222333:root" }, "Action": "events:PutEvents", "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/CrossRegionBus", "Condition": { "ArnEquals": { "aws:SourceArn": [ "arn:aws:events:us-west-2:*:*", "arn:aws:events:me-south-1:*:*" ] } } } ] }

策略示例:拒绝从特定区域发送事件

以下策略示例附加到账户 123456789012 中名为 CrossRegionBus 的事件总线,允许此事件总线接收来自账户 111122223333 的事件,但不允许接收在美国西部(俄勒冈州)区域生成的事件。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "1AllowAnyEventsFromAccount111112222333", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111112222333:root" }, "Action": "events:PutEvents", "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/CrossRegionBus" }, { "Sid": "2DenyAllCrossRegionUSWest2Events", "Effect": "Deny", "Principal": { "AWS": "*" }, "Action": "events:PutEvents", "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/CrossRegionBus", "Condition": { "ArnEquals": { "aws:SourceArn": [ "arn:aws:events:us-west-2:*:*" ] } } } ] }