AWS IoT 政策可能設定錯誤 - AWS IoT Device Defender

AWS IoT 政策可能設定錯誤

找到一項可能設定錯誤的 AWS IoT 政策。設定錯誤的政策 (包括過於寬鬆的政策) 可能會導致安全性事件,例如允許裝置存取非預期的資源。

AWS IoT 政策可能設定錯誤的檢查是一項警示,可提醒您確保在更新政策之前只允許執行預期的動作。

此檢查會以 IOT_POLICY_POTENTIAL_MISCONFIGURATION_CHECK 出現在 CLI 和 API 中。

嚴重性:

詳細資訊

當此檢查發現可能錯誤設定的 AWS IoT 政策時,AWS IoT 會傳回下列原因代碼:

  • POLICY_CONTAINS_MQTT_WILDCARDS_IN_DENY_STATEMENT

  • TOPIC_FILTERS_INTENDED_TO_DENY_ALLOWED_USING_WILDCARDS

為什麼它很重要

設定錯誤的政策可能會因為向裝置提供超出需求的許可而導致非預期後果。我們建議您審慎考慮在政策中限制資源存取權限並防範安全威脅。

AWS IoT 政策可能設定錯誤的檢查會確認拒絕陳述式中是否有 MQTT 萬用字元 (+#)。AWS IoT 政策會將萬用字元視為常值字串,且可能會使政策過於寬鬆。

下列範例旨在透過於政策中使用 MQTT 萬用字元 # 來拒絕訂閱與 building/control_room 相關的主題。然而,MQTT 萬用字元在 AWS IoT 政策中並未定義為萬用字元,且裝置可以訂閱 building/control_room/data1

AWS 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

AWS 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。(這可讓此新版本適用於使用該政策的所有實體。)

    如需為常見使用案例建立 AWS IoT 政策的範例,請參閱《AWS IoT Core 開發人員指南》中的發佈/訂閱政策範例

  2. 驗證所有相關的裝置可以連接到 AWS IoT。如果裝置無法連接,則復原到預設政策之前的版本,使用 SetPolicyVersion 將預設政策還原為先前版本,修訂政策,然後重試。

您可以使用緩解動作:

  • 套用 REPLACE_DEFAULT_POLICY_VERSION 緩解行動到稽核結果來產生此變更。

  • 如果您要實作自訂回應以回應 Amazon SNS 訊息,套用 PUBLISH_FINDINGS_TO_SNS 緩解動作。

如需詳細資訊,請參閱緩解動作

使用《AWS IoT Core 開發人員指南》中的 IoT Core 政策變數以動態參考您政策中的 AWS IoT 資源。