I'm using flutter/dart (mqtt_client / https://pub.dev/packages/mqtt_client) to send an AWS IOT MQTT messages over websockets and I'd like to restrict an IAM user to only specific topics that a user is allowed to Publish messages only to their specific topic. I've attempted to add some restricted policies, but the application will fail with little information on the client side. Also, in Cloud Watch, I don't see any specific errors.
Here's some example topics:
arn:aws:iot:us-east-2:1234567890:topic/action_request/ASDF1234
arn:aws:iot:us-east-2:1234567890:topic/action_request/ASDF5678
So, I want to add the proper JSON policy attached to the IAM user and they only have access to ASDF1234
All of my publish topics are patterned like the above. For now, I'm focusing on restricting the Publish endpoints and then working others like Subscribe.
I've tried numerous different policies like below. Also with adding some wildcards to no success on the client side. They look right, but I'm not sure if there's indirectly other publish topics that are used internally within MQTT that's causing the failures or maybe just my syntax.
Another thought is if I add a condition that would allow only the above endpoint and no others.
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"iot:Receive",
"iot:ListNamedShadowsForThing",
"iot:Subscribe",
"iot:Connect",
"iot:GetThingShadow",
"iot:DeleteThingShadow",
"iot:UpdateThingShadow"
],
"Resource": "*"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": "iot:Publish",
"Resource": "arn:aws:iot:us-east-2:1234567890:topic/*/ASDF1234*"
}
]
}
thanks for the reply. We originally were using associated certificates for policy association. However, to get past security requirements for Android app store, we had to use MQTT over websockets and Signature Version 4 authentication. It then just uses https/wss protocol instead. That eliminates the certificate need at the mobile app, thus eliminating some security requirements. We also did enable the logging on the AWS IoT console. We have seen some really generic failures coming in but nothing to help build out a proper Resource arn to lock things down. Thanks for the advice.