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

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

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

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

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

策略最佳实践

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

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

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

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

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

使用 Amazon IoT Events控制台

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

要确保这些实体仍可使用 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 操作相匹配的操作。

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

此示例显示您可以如何创建策略,以便允许 用户查看附加到其用户身份的内联和托管策略。此策略包括在控制台上完成此操作或者以编程方式使用 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输入

在此示例中,您想要为您的 Amazon Web Services 账户 中的用户授予访问其中一个 Amazon IoT Events 输入 (exampleInput) 的权限。您还想要允许该用户添加、更新和删除输入。

该策略为用户授予 iotevents:ListInputsiotevents:DescribeInputiotevents:CreateInputiotevents:DeleteInputiotevents:UpdateInput 权限。有关为用户授予权限并使用控制台测试这些权限的 Amazon Simple Storage Service (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}"} } } ] }

您可以将此策略附加到您账户中的用户。如果一个名为 richard-roe 的用户尝试查看Amazon IoT Events输入,则必须使用 Owner=richard-roeowner=richard-roe输入加上标签。否则,将拒绝其访问。条件标签键 Owner 匹配 Ownerowner,因为条件键名称不区分大小写。有关更多信息,请参阅《IAM 用户指南》中的 IAM JSON 策略元素:条件