Amazon IoT 策略可能配置错误 - Amazon IoT Core
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

Amazon IoT 策略可能配置错误

已确定某项 Amazon IoT 策略可能配置错误。错误配置的策略,包括过于宽松的策略,可能会导致安全事件,例如允许设备访问意外资源。

可能配置错误的 Amazon IoT 策略检查是一种警告,提醒您确保在更新策略之前仅允许预期的操作。

在此 CLI 和 API 中,该检查显示为 IOT_POLICY_POTENTIAL_MISCONFIGURATION_CHECK

严重性:

详细信息

当此检查发现可能配置错误的 Amazon IoT 策略时,Amazon IoT 会返回以下原因代码:

  • POLICY_CONTAINS_MQTT_WILDCARDS_IN_DENY_STATEMENT

  • TOPIC_FILTERS_INTENDED_TO_DENY_ALLOWED_USING_WILDCARDS

为什么这非常重要

错误配置的策略可能会向设备提供超出所需的权限,从而导致意外后果。我们建议仔细考虑该政策,以限制对资源的访问并防止安全威胁。

可能配置错误的 Amazon IoT 策略检查会检查 deny 语句中是否有 MQTT 通配符(+#)。通配符被 Amazon IoT 策略视为文字字符串,可能会使策略过于宽松。

以下示例旨在通过在策略中使用 MQTT 通配符 # 来拒绝订阅与 building/control_room 相关的主题。但是,MQTT 通配符在 Amazon IoT 策略中没有通配符含义,设备可以订阅 building/control_room/data1

可能配置错误的 Amazon IoT 策略检查将使用原因代码 POLICY_CONTAINS_MQTT_WILDCARDS_IN_DENY_STATEMENT 标记此策略。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:Subscribe", "Resource": "arn:aws:iot:region:account-id:topicfilter/building/*" }, { "Effect": "Deny", "Action": "iot:Subscribe", "Resource": "arn:aws:iot:region:account-id:topicfilter/building/control_room/#" }, { "Effect": "Allow", "Action": "iot:Receive", "Resource": "arn:aws:iot:region:account-id:topic/building/*" } ] }

以下是正确配置的策略的示例。设备无权订阅 building/control_room/ 的子主题,也无权接收来自 building/control_room/ 的子主题的消息。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:Subscribe", "Resource": "arn:aws:region:account-id:topicfilter/building/*" }, { "Effect": "Deny", "Action": "iot:Subscribe", "Resource": "arn:aws:iot:region:account-id:topicfilter/building/control_room/*" }, { "Effect": "Allow", "Action": "iot:Receive", "Resource": "arn:aws:iot:region:account-id:topic/building/*" }, { "Effect": "Deny", "Action": "iot:Receive", "Resource": "arn:aws:iot:region:account-id:topic/building/control_room/*" } ] }

以下示例策略旨在通过拒绝资源 building/control_room/* 来拒绝订阅与 building/control_room 相关的主题。但是,设备可以发送 building/# 订阅请求,并接收来自与 building 相关的所有主题的消息,包括 building/control_room/data1

可能配置错误的 Amazon IoT 策略检查将使用原因代码 TOPIC_FILTERS_INTENDED_TO_DENY_ALLOWED_USING_WILDCARDS 标记此策略。

以下示例策略有权接收关于 building/control_room topics 的消息:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:Subscribe", "Resource": "arn:aws:iot:region:account-id:topicfilter/building/*" }, { "Effect": "Deny", "Action": "iot:Subscribe", "Resource": "arn:aws:iot:region:account-id:topicfilter/building/control_room/*" }, { "Effect": "Allow", "Action": "iot:Receive", "Resource": "arn:aws:iot:region:account-id:topic/building/*" } ] }

以下是正确配置的策略的示例。设备无权订阅 building/control_room/ 的子主题,也无权接收来自 building/control_room/ 的子主题的消息。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:Subscribe", "Resource": "arn:aws:iot:region:account-id:topicfilter/building/*" }, { "Effect": "Deny", "Action": "iot:Subscribe", "Resource": "arn:aws:iot:region:account-id:topicfilter/building/control_room/*" }, { "Effect": "Allow", "Action": "iot:Receive", "Resource": "arn:aws:iot:region:account-id:topic/building/*" }, { "Effect": "Deny", "Action": "iot:Receive", "Resource": "arn:aws:iot:region:account-id:topic/building/control_room/*" } ] }
注意

此检查可能会误报。我们建议您评估所有已标记的策略,并使用审计抑制功能标记误报资源。

如何修复

此检查会标记可能配置错误的策略,因此可能会出现误报。使用审计抑制功能标记所有误报,这样以后就不会再标记误报。

您可以按照以下步骤来修复附加到事物、事物组或其他实体的任何不合规策略:

  1. CreatePolicyVersion用于创建新的、合规的策略版本。将 setAsDefault 标记设置为 True。(这可使此新版本适用于使用策略的所有实体。)

    有关为常见用例创建 Amazon IoT 策略的示例,请参阅 Amazon IoT Core 开发者指南中的发布/订阅策略示例

  2. 验证所有关联的设备能否连接到 Amazon IoT。如果设备无法连接,请使用 SetPolicyVersion将默认策略还原到以前的版本,修改策略,然后重试。

您可以使用缓解操作实现以下目的:

  • 对您的审计查找结果应用 REPLACE_DEFAULT_POLICY_VERSION 缓解操作以进行此更改。

  • 如果要实现自定义响应以响应 Amazon SNS 消息,请应用 PUBLISH_FINDINGS_TO_SNS 缓解操作。

有关更多信息,请参阅缓解操作

使用 Amazon IoT 策略变量在策略中动态引用 Amazon IoT 资源。