簡體   English   中英

AWS IoT-將主題限制為用戶的Cognito ID

[英]AWS IoT - Restrict topic to user's Cognito ID

我一直在嘗試將對IoT主題的Publish / Receive權限限制為用戶的Cognito ID。

在我的應用程序中,我正在創建看起來像messenger/{cognitoUserId} (例如messenger/us-east-1:fa610fd5-4fab-4511-834b-8f1198744efb )。

因此,在我的IAM策略中,我想指定僅主題中包含Cognito ID的用戶對該主題具有“ Publish / Receive權限。

這是我的IAM政策當前的樣子:


{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "iot:Connect",
                "mobileanalytics:PutEvents",
                "cognito-sync:*"
            ],
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "iot:Receive",
                "iot:Publish"
            ],
            "Resource": "arn:aws:iot:us-east-1:123456789:topic/messenger/${cognito-identity.amazonaws.com:sub}"
        },
        {
            "Sid": "VisualEditor2",
            "Effect": "Allow",
            "Action": "iot:Subscribe",
            "Resource": "arn:aws:iot:us-east-1:123456789:topicfilter/messenger/${cognito-identity.amazonaws.com:sub}"
        },
        {
            "Effect": "Deny",
            "Action": [
                "iot:Receive",
                "iot:Publish"
            ],
            "Resource": "arn:aws:iot:us-east-1:123456789:topic/messenger/*",
            "Condition": {"StringNotLike": {"iot:topicfilter": [
                "messenger/${cognito-identity.amazonaws.com:sub}"
              ]}}
        }
    ]
}

任何幫助將不勝感激。 我已經花了整整兩天的時間來研究AWS文檔,博客文章以及其他內容。 在我看來,這似乎是AWS IoT主題的這種正常的常規用例,但是很難做到。

將cognito與AWSIoT結合使用時有兩種情況:

  1. Cognito身份驗證池:在這種情況下,您可以在池級別定義限制較少的策略。 現在,您需要將策略附加到每個認知用戶(IoT的AttachPolicy調用),以向認知用戶授予特定權限。

注意:如果您未指定任何IoT策略,則一切都被視為拒絕,如果您使用的是經過身份驗證的池認知身份,則似乎是這種情況。

  1. Cognito未經身份驗證的池:在這種情況下,IoT不會進行任何范圍縮小(不需要IoT的AttachPolicy調用),並且池級別的策略將確定用戶可以使用IoT資源做什么。

有關詳細信息,請訪問: https ://docs.aws.amazon.com/iot/latest/developerguide/pub-sub-policy.html#pub-sub-policy-cognito http://docs.aws.amazon。 com / iot / latest / developerguide / authorization.html

您可能會對https://stackoverflow.com/a/47838529/962545感興趣的另一個類似線程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM