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 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南