已驗證的 Cognito 角色過度寬鬆 - AWS IoT Device Defender

已驗證的 Cognito 角色過度寬鬆

附加到經身分驗證的 Amazon Cognito 身分集區角色是過於寬鬆的政策,因為它授與執行以下 AWS IoT 動作的許可:

  • 管理或修改物件。

  • 管理與物件不相關的資料或資源。

或者,因為它授與可在廣泛的裝置上執行以下 AWS IoT 動作的許可:

  • 讀取物件管理資料。

  • 使用 MQTT 連接/發佈/訂閱保留的主題 (包括影子或任務執行資料)。

  • 使用 API 命令讀取或修改影子或任務執行資料。

一般而言,使用已驗證 Amazon Cognito 身分集區角色連線的裝置應僅有受限的許可來讀取特定物件管理資料,發佈和訂閱特定的 MQTT 主題或使用 API 命令讀取和修改影子或任務執行資料相關的特定物件資料。

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

嚴重性:關鍵

詳細資訊

對此檢查,AWS IoT Device Defender 會稽核所有 Amazon Cognito 身分集區在稽核執行前的 31 天內用於連接到 AWS IoT 訊息代理程式。稽核包含所有 Amazon Cognito 身分集區已驗證或未經驗證的 Amazon Cognito 身分集區連線。

當此檢查發現不合規的已驗證 Amazon Cognito 身分集區角色時,將會傳回下列原因代碼:

  • ALLOWS_BROAD_ACCESS_TO_IOT_THING_ADMIN_READ_ACTIONS

  • ALLOWS_ACCESS_TO_IOT_NON_THING_ADMIN_ACTIONS

  • ALLOWS_ACCESS_TO_IOT_THING_ADMIN_WRITE_ACTIONS

為什麼它很重要

如果已驗證身分遭到入侵,則可以使用管理動作修改帳戶設定、刪除資源或獲得存取敏感資料。

如何修正它

連接到已驗證的 Amazon Cognito 身分集區角色的政策僅應授與裝置完成其任務所需的那些許可。建議下列步驟:

  1. 建立新的合規角色。

  2. 建立 Amazon Cognito 身分集區,並連接至合規角色。

  3. 驗證您的身分可以存取 AWS IoT 以使用新的集區。

  4. 驗證完成後,將角色連接至標記為不合規的 Amazon Cognito 身分集區。

您也可以使用緩解行動:

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

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

管理或修改物件

下列 AWS IoT API 動作用來管理或修改物件,因此不應授與裝置透過已驗證的 Amazon Cognito 身分集區連接並執行這些許可:

  • AddThingToThingGroup

  • AttachThingPrincipal

  • CreateThing

  • DeleteThing

  • DetachThingPrincipal

  • ListThings

  • ListThingsInThingGroup

  • RegisterThing

  • RemoveThingFromThingGroup

  • UpdateThing

  • UpdateThingGroupsForThing

授與許可的任何角色執行這些動作,即使是單一資源都是視為不合規。

管理非物件

透過已驗證 Amazon Cognito 身分集區連接的裝置,不應被授與許可來執行非這些章節中所討論的任何其他 AWS IoT API 動作。為了利用透過已驗證 Amazon Cognito 身分集區連接的應用程式管理您的帳戶,請建立裝置尚未使用的單獨身分集區。

讀取物件管理資料

下列 AWS IoT API 動作用來讀取物件資料,因此應授與裝置透過已驗證 Amazon Cognito 身分集區連接並僅在一組有限的物件上執行這些許可:

  • DescribeThing

  • ListJobExecutionsForThing

  • ListThingGroupsForThing

  • ListThingPrincipals

  • 不合規:

    arn:aws:iot:region:account-id:thing/*

    這可讓裝置在任何物件上執行指定的動作。

  • 合規:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:DescribeThing", "iot:ListJobExecutionsForThing", "iot:ListThingGroupsForThing", "iot:ListThingPrincipals" ], "Resource": [ "arn:aws:iot:region:account-id:/thing/MyThing" ] } ] }

    這可讓裝置僅在一個物件上執行指定的動作。

  • 合規:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:DescribeThing", "iot:ListJobExecutionsForThing", "iot:ListThingGroupsForThing", "iot:ListThingPrincipals" ], "Resource": [ "arn:aws:iot:region:account-id:/thing/MyThing*" ] } ] }

    這是合規的,因為即使資源指定在特定字串之前使用萬用字元 (*),並且限制了存取具有指定前綴名稱字首的物件組別。

  • 不合規:

    arn:aws:iot:region:account-id:thing/*

    這可讓裝置在任何物件上執行指定的動作。

  • 合規:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:DescribeThing", "iot:ListJobExecutionsForThing", "iot:ListThingGroupsForThing", "iot:ListThingPrincipals" ], "Resource": [ "arn:aws:iot:region:account-id:/thing/MyThing" ] } ] }

    這可讓裝置僅在一個物件上執行指定的動作。

  • 合規:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:DescribeThing", "iot:ListJobExecutionsForThing", "iot:ListThingGroupsForThing", "iot:ListThingPrincipals" ], "Resource": [ "arn:aws:iot:region:account-id:/thing/MyThing*" ] } ] }

    這是合規的,因為即使資源指定在特定字串之前使用萬用字元 (*),並且限制了存取具有指定前綴名稱字首的物件組別。

訂閱/發佈至 MQTT 主題

會透過 AWS IoT 訊息代理程式傳送 MQTT 訊息,並裝置會使用該訊息來執行許多不同的動作,包括存取和修改影子狀態和任務執行狀態。與裝置連接、發佈或訂閱 MQTT 訊息許可的政策,應該對特定資源加以限制這些動作如下所示:

連線
  • 不合規:

    arn:aws:iot:region:account-id:client/*

    萬用字元 * 可讓任何裝置連接到 AWS IoT。

    arn:aws:iot:region:account-id:client/${iot:ClientId}

    除非 iot:Connection.Thing.IsAttached 在條件索引鍵中設定為 true,這相當於先前範例中的萬用字元 *。

  • 合規:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Connect" ], "Resource": [ "arn:aws:iot:region:account-id:client/${iot:Connection.Thing.ThingName}" ], "Condition": { "Bool": { "iot:Connection.Thing.IsAttached": "true" } } } ] }

    資源規範包含與用來連接的裝置名稱符合的變數,和條件陳述式進一步限制許可的檢查,通過 MQTT 用戶端使用的憑證是否與附加到具有使用名稱的物件相符合。

發佈
  • 不合規:

    arn:aws:iot:region:account-id:topic/$aws/things/*/shadow/update

    這可讓裝置更新任何裝置 (* = 所有裝置) 的影子。

    arn:aws:iot:region:account-id:topic/$aws/things/*

    這可讓裝置讀取/更新/刪除任何裝置 (* = 所有裝置) 的影子。

  • 合規:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Publish" ], "Resource": [ "arn:aws:iot:region:account-id:topic/$aws/things/${iot:Connection.Thing.ThingName}/shadow/*" ], } ] }

    資源規格包含萬用字元,但只符合任何影子相關主題物件名稱連線的裝置。

訂閱
  • 不合規:

    arn:aws:iot:region:account-id:topicfilter/$aws/things/*

    這可讓裝置為所有裝置訂閱保留影子或任務主題。

    arn:aws:iot:region:account-id:topicfilter/$aws/things/#

    前述範例相同,但使用 # 萬用字元。

    arn:aws:iot:region:account-id:topicfilter/$aws/things/+/shadow/update

    這可讓裝置看到任何裝置 (+ = 所有裝置) 的影子更新。

  • 合規:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Subscribe" ], "Resource": [ "arn:aws:iot:region:account-id:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/shadow/*" "arn:aws:iot:region:account-id:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/jobs/*" ], } ] }

    資源規格包含萬用字元,但只會針對物件名稱用於連線的裝置,比對任何影子相關主體與任何任務相關主題。

接收
  • 合規:

    arn:aws:iot:region:account-id:topicfilter/$aws/things/*

    這是合規的,因為裝置只能從已訂閱許可的主題接收訊息。

讀取或修改影子或任務資料

授與裝置執行 API 動作的許可以存取或修改裝置影子或任務執行資料的政策,應該於特定的資源限制這些動作。以下是 API 動作:

  • DeleteThingShadow

  • GetThingShadow

  • UpdateThingShadow

  • DescribeJobExecution

  • GetPendingJobExecutions

  • StartNextPendingJobExecution

  • UpdateJobExecution

範例

  • 不合規:

    arn:aws:iot:region:account-id:thing/*

    這可讓裝置在任何物件上執行指定的動作。

  • 合規:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:DeleteThingShadow", "iot:GetThingShadow", "iot:UpdateThingShadow", "iot:DescribeJobExecution", "iot:GetPendingJobExecutions", "iot:StartNextPendingJobExecution", "iot:UpdateJobExecution" ], "Resource": [ "arn:aws:iot:region:account-id:/thing/MyThing1", "arn:aws:iot:region:account-id:/thing/MyThing2" ] } ] }

    這可讓裝置僅在兩個物件上執行指定的動作。