繁体   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