aws / aws-iot-device-sdk-embedded-C

SDK for connecting to AWS IoT from a device using embedded C.
MIT License
988 stars 634 forks source link

Updating Shadow without "Action": "iot:UpdateThingShadow" in policy #1526

Closed anubhav1 closed 3 years ago

anubhav1 commented 3 years ago

My device had following policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "iot:Connect",
        "iot:Publish",
        "iot:Subscribe",
        "iot:Receive",
        "greengrass:Discover"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

I used the aws_iot_shadow_update() of the sdk and I am able to update the shadow successfully. How it is possible to update the shadow without without "Action": "iot:UpdateThingShadow" in policy?

aggarw13 commented 3 years ago

Hi @anubhav1, to understand the behavior you are noticing, can you clarify the following?

anubhav1 commented 3 years ago
    jsonStruct_t carDoor;
    carDoor.cb = carDoor_callback;
    carDoor.pData = &carDoorOpen;
    carDoor.pKey = "carDoorOpen";
    carDoor.type = SHADOW_JSON_BOOL;
    carDoor.dataLength = sizeof(carDoorOpen);

All these things are not supposed to happen.

aggarw13 commented 3 years ago

@anubhav1. thanks for your responses and confirmation about seeing Shadow updates on the console. I am able to see the same behavior with the policy you provided.

I checked internally with the IoT Shadow service team, and received information that the iot:UpdateThingShadow policy action is only applicable for HTTP requests. For MQTT communication, as long as the policy contains the iot:Publish action, the Shadow Update/Delete/Get operations can be successfully executed by PUBLISHing to their MQTT topics.

We will look into updating the AWS documentation for IoT Core Policy Actions to clarify that the Shadow Policy actions are only applicable to HTTP requests.

anubhav1 commented 3 years ago

I think it will be confusing for developers to have same policies behaving differently on different protocols. Also policy action names are self-explanatory. For example, iot:UpdateThingShadow is supposed to update the shadow only.

aggarw13 commented 3 years ago

I agree that the policy action name can be confusing. Unfortunately, as the policy action has been already available, we will update the documentation to clearly mention that the Shadow Action Policies are only relevant for HTTP requests.

For example, there is already a note for the Job Execution Policy Actions (for AWS IoT Jobs service APIs) in the AWS documentation that the policies are relevant only for HTTP requests.

anubhav1 commented 3 years ago

Alright!