Cognito policy for accessing IoT things

0

Here's what happens in my application...

  • I have a Node JS web application that displays an HTML page with live device information on.
  • A user logs in using Open ID Connect (using Cognito).
  • I use the user's identity token to get their identity that has an IoT policy attached to it.

All of this works so far up until I start using a Condition in the IoT policy associated with the user.

I want a user to only access a 'Thing' if the user's organization and Thing's organization match. I create a unique IoT policy for each user and attach it to the user's cognito identity.

Here's my security policy. Again this is the policy that's attached to the user's identity. I should point out that if I remove the 'Condition' everything works...

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "iot:Connect"
      ],
      "Effect": "Allow",
      "Resource": "arn:aws:iot:us-east-1:1234567890:client/*"
    },
    {
      "Action": [
        "iot:Publish",
        "iot:Receive"
      ],
      "Effect": "Allow",
      "Resource": "arn:aws:iot:us-east-1:1234567890:topic/*",
      "Condition": {
        "StringEquals": {
          "iot:Connection.Thing.Attributes[org]": "acme"
        }
      }
    },
    {
      "Action": [
        "iot:Subscribe"
      ],
      "Effect": "Allow",
      "Resource": "arn:aws:iot:us-east-1:1234567890:topicfilter/device/*"
    }
  ]
}

What am I doing wrong? Why is this not working? The Thing definitely has an 'org' attribute on it. Please don't tell me the condition is being somehow applied to the user rather than the thing the user is trying to connect too :(.

Edited by: gemehendrix on Jan 9, 2019 7:26 AM

質問済み 5年前428ビュー
1回答
0

Ok I've found the AttachThingPrincipal API where I can attach a cognito identity to a Thing. The Thing's name will then be used accordingly.

In order to achieve what I need to organization wise, I'll probably just need to rework the format of the topics.

Any further suggestions are welcome.

回答済み 5年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ