Amazon IoT Events 基于身份的策略示例 - Amazon IoT Events
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

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

Amazon IoT Events 基于身份的策略示例

预设情况下,IAM 用户和角色没有创建或修改 Amazon IoT Events 资源的权限。它们还无法使用 Amazon Web Services Management Console、Amazon CLI 或 Amazon API 执行任务。IAM 管理员必须创建 IAM policy,以便为用户和角色授予权限以对所需的指定资源执行特定的 API 操作。然后,管理员必须将这些策略附加到需要这些权限的 IAM 用户或组。

要了解如何使用这些示例 JSON 策略文档创建 IAM 基于身份的策略,请参阅 IAM 用户指南中的在 JSON 选项卡上创建策略

策略最佳实践

基于身份的策略非常强大。它们确定某个人是否可以创建、访问或删除您账户中的 Amazon IoT Events 资源。这些操作可能会使 Amazon 账户产生成本。创建或编辑基于身份的策略时,请遵循以下准则和建议:

  • 开始使用 Amazon 托管式策略 – 要快速开始使用 Amazon IoT Events,请使用 Amazon 托管式策略,为您的员工提供他们所需的权限。这些策略已在您的账户中提供,并由 Amazon 维护和更新。有关更多信息,请参阅 IAM 用户指南中的开始使用 Amazon 托管式策略中的权限

  • 授予最低权限 – 创建自定义策略时,仅授予执行任务所需的许可。最开始只授予最低权限,然后根据需要授予其它权限。这样做比起一开始就授予过于宽松的权限而后再尝试收紧权限来说更为安全。有关更多信息,请参阅《IAM 用户指南》中的授予最低权限

  • 为敏感操作启用 MFA – 为增强安全性,要求 IAM 用户使用多重身份验证 (MFA) 来访问敏感资源或 API 操作。要了解更多信息,请参阅 IAM 用户指南中的在 Amazon 中使用多重身份验证 (MFA)

  • 使用策略条件来增强安全性 – 在切实可行的范围内,定义基于身份的策略在哪些情况下允许访问资源。例如,您可编写条件来指定请求必须来自允许的 IP 地址范围。您也可以编写条件,以便仅允许指定日期或时间范围内的请求,或者要求使用 SSL 或 MFA。有关更多信息,请参阅 。IAM JSON 策略元素:ConditionIAM 用户指南.

使用 Amazon IoT Events 控制台

要访问 Amazon IoT Events 控制台,您必须拥有一组最低的权限。这些权限必须允许您列出和查看有关您的 Amazon 账户中的 Amazon IoT Events 资源的详细信息。如果您创建的基于身份的策略比所需的最低权限更严格,则无法为具有该策略的实体(IAM 用户或角色)正常运行控制台。

要确保这些实体仍可使用 Amazon IoT Events 控制台,也可向实体附加以下 Amazon 托管策略。有关更多信息,请参阅 。向用户添加权限IAM 用户指南

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iotevents-data:BatchPutMessage", "iotevents-data:BatchUpdateDetector", "iotevents:CreateDetectorModel", "iotevents:CreateInput", "iotevents:DeleteDetectorModel", "iotevents:DeleteInput", "iotevents-data:DescribeDetector", "iotevents:DescribeDetectorModel", "iotevents:DescribeInput", "iotevents:DescribeLoggingOptions", "iotevents:ListDetectorModelVersions", "iotevents:ListDetectorModels", "iotevents-data:ListDetectors", "iotevents:ListInputs", "iotevents:ListTagsForResource", "iotevents:PutLoggingOptions", "iotevents:TagResource", "iotevents:UntagResource", "iotevents:UpdateDetectorModel", "iotevents:UpdateInput", "iotevents:UpdateInputRouting" ], "Resource": "arn:${Partition}:iotevents:${Region}:${Account}:detectorModel/${detectorModelName}", "Resource": "arn:${Partition}:iotevents:${Region}:${Account}:input/${inputName}" } ] }

对于只需要调用 Amazon CLI 或 Amazon API 的用户,无需为其提供最低控制台权限。相反,只允许访问与您尝试执行的 API 操作相匹配的操作。

允许用户查看他们自己的权限

该示例说明了您如何创建策略,以允许 IAM 用户查看附加到其用户身份的内联和托管式策略。此策略包括在控制台上完成此操作或者以编程方式使用 Amazon CLI 或 Amazon API 所需的权限。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ViewOwnUserInfo", "Effect": "Allow", "Action": [ "iam:GetUserPolicy", "iam:ListGroupsForUser", "iam:ListAttachedUserPolicies", "iam:ListUserPolicies", "iam:GetUser" ], "Resource": [ "arn:aws:iam::*:user/${aws:username}" ] }, { "Sid": "NavigateInConsole", "Effect": "Allow", "Action": [ "iam:GetGroupPolicy", "iam:GetPolicyVersion", "iam:GetPolicy", "iam:ListAttachedGroupPolicies", "iam:ListGroupPolicies", "iam:ListPolicyVersions", "iam:ListPolicies", "iam:ListUsers" ], "Resource": "*" } ] }

访问一个Amazon IoT Events输入

在本示例中,您希望向您的授予一个 IAM 用户Amazon访问其中一个的帐户Amazon IoT Events输入,exampleInput. 您还希望允许用户添加、更新和删除输入。

该策略为用户授予 iotevents:ListInputsiotevents:DescribeInputiotevents:CreateInputiotevents:DeleteInputiotevents:UpdateInput 权限。有关向用户授予权限并使用控制台测试这些权限的 Amazon S3 服务的示例演练,请参阅演练示例:使用用户策略控制对存储桶的访问.

{ "Version":"2012-10-17", "Statement":[ { "Sid":"ListInputsInConsole", "Effect":"Allow", "Action":[ "iotevents:ListInputs" ], "Resource":"arn:aws:iotevents:::*" }, { "Sid":"ViewSpecificInputInfo", "Effect":"Allow", "Action":[ "iotevents:DescribeInput" ], "Resource":"arn:aws:iotevents:::exampleInput" }, { "Sid":"ManageInputs", "Effect":"Allow", "Action":[ "iotevents:CreateInput", "iotevents:DeleteInput", "iotevents:DescribeInput", "iotevents:ListInputs", "iotevents:UpdateInput" ], "Resource":"arn:aws:iotevents:::exampleInput/*" } ] }

查看Amazon IoT Events输入基于标签

您可以在基于身份的策略中使用条件,以便基于标签控制对 Amazon IoT Events 资源的访问。此示例演示了如何创建允许查看输入. 但是,只有在以下情况下才会授予权限输入标签Owner的值等于该用户的用户名。此策略还授予在控制台上完成此操作的必要权限。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ListInputsInConsole", "Effect": "Allow", "Action": "iotevents:ListInputs", "Resource": "*" }, { "Sid": "ViewInputsIfOwner", "Effect": "Allow", "Action": "iotevents:ListInputs", "Resource": "arn:aws:iotevents:*:*:input/*", "Condition": { "StringEquals": {"aws:ResourceTag/Owner": "${aws:username}"} } } ] }

您可以将该策略附加到您账户中的 IAM 用户。如果用户名为richard-roe尝试查看Amazon IoT Events 输入输入必须标记Owner=richard-roe要么owner=richard-roe. 否则,他会被拒绝访问。条件标签键 Owner 匹配 Ownerowner,因为条件键名称不区分大小写。有关更多信息,请参阅 。IAM JSON 策略元素:ConditionIAM 用户指南.