Skip to content

Authorization Failure when publishing to IoT Core from MQTT Bridge

0

I'm experiencing an authorization error when publishing to IoT Core from MQTT on a Greengrass device. The greengrass device is running a Mosquitto broker with a bridging configuration to AWS IoT Core as shown here -

listener 1883 0.0.0.0
allow_anonymous true
log_dest stdout

connection aws-iot-core
address ${MQTT_CLOUD_BROKER_ADDRESS}:8883
remote_clientid ${MQTT_THING_PREFIX}
bridge_protocol_version mqttv311
bridge_insecure false
cleansession true
start_type automatic
notifications false
try_private false
bridge_cafile /mosquitto/certs/awsRootCA.pem
bridge_certfile /mosquitto/certs/deviceCertAndCACert.crt
bridge_keyfile /mosquitto/certs/deviceCert.key

topic # out 0 grid-cloud/ ${MQTT_THING_PREFIX}/

This same certificate when used with mosquitto_pub or MQTT Explorer is successful.

In the success scenario this publication is successful.

mosquitto_pub --cafile /mosquitto/certs/awsRootCA.pem \
--cert /mosquitto/certs/deviceCertAndCACert.crt \
--key /mosquitto/certs/deviceCert.key \
-h aws-redacted.iot.us-east-2.amazonaws.com \
-p 8883 \
-t DeviceGrid_SO1/test/ \
-m '{"value": "test" }' \
-i DeviceGrid_SO1 \
-V mqttv311 \
-d

with this cloudwatch logging the successful publication -

[
    {
        "@timestamp": "2025-02-04 18:04:04.588",
        "@message": {
            "timestamp": "2025-02-04 18:04:04.588",
            "logLevel": "INFO",
            "traceId": "912e662c-1157-c612-8838-8be8b7d175ad",
            "accountId": "my-accountId",
            "status": "Success",
            "eventType": "Connect",
            "protocol": "MQTT",
            "clientId": "DeviceGrid_SO1",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba",
            "sourceIp": "50.232.1.166",
            "sourcePort": 60546
        }
    },
    {
        "@timestamp": "2025-02-04 18:04:04.620",
        "@message": {
            "timestamp": "2025-02-04 18:04:04.620",
            "logLevel": "INFO",
            "traceId": "8bf1f5f9-5e53-6bab-d20a-c6d0deb4ccc1",
            "accountId": "my-accountId",
            "status": "Success",
            "eventType": "Publish-In",
            "protocol": "MQTT",
            "topicName": "DeviceGrid_SO1/test/",
            "clientId": "DeviceGrid_SO1",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba",
            "sourceIp": "50.232.1.166",
            "sourcePort": 60546
        }
    },
    {
        "@timestamp": "2025-02-04 18:04:04.622",
        "@message": {
            "timestamp": "2025-02-04 18:04:04.622",
            "logLevel": "INFO",
            "traceId": "8bf1f5f9-5e53-6bab-d20a-c6d0deb4ccc1",
            "accountId": "my-accountId",
            "status": "Success",
            "eventType": "RuleMatch",
            "clientId": "DeviceGrid_SO1",
            "topicName": "DeviceGrid_SO1/test/",
            "ruleName": "LNDEV_forward_to_kinesis",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba"
        }
    },
    {
        "@timestamp": "2025-02-04 18:04:04.622",
        "@message": {
            "timestamp": "2025-02-04 18:04:04.622",
            "logLevel": "DEBUG",
            "traceId": "8bf1f5f9-5e53-6bab-d20a-c6d0deb4ccc1",
            "accountId": "my-accountId",
            "status": "Success",
            "eventType": "StartingRuleExecution",
            "clientId": "DeviceGrid_SO1",
            "topicName": "DeviceGrid_SO1/test/",
            "ruleName": "LNDEV_forward_to_kinesis",
            "ruleAction": "KinesisAction",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba"
        }
    },
    {
        "@timestamp": "2025-02-04 18:04:04.635",
        "@message": {
            "timestamp": "2025-02-04 18:04:04.635",
            "logLevel": "INFO",
            "traceId": "ce98e815-5c42-4b87-0579-e20e914b835e",
            "accountId": "my-accountId",
            "status": "Success",
            "eventType": "Disconnect",
            "protocol": "MQTT",
            "clientId": "DeviceGrid_SO1",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba",
            "sourceIp": "50.232.1.166",
            "sourcePort": 60546,
            "disconnectReason": "CLIENT_INITIATED_DISCONNECT"
        }
    },
    {
        "@timestamp": "2025-02-04 18:04:04.655",
        "@message": {
            "timestamp": "2025-02-04 18:04:04.655",
            "logLevel": "INFO",
            "traceId": "8bf1f5f9-5e53-6bab-d20a-c6d0deb4ccc1",
            "accountId": "my-accountId",
            "status": "Success",
            "eventType": "RuleExecution",
            "clientId": "DeviceGrid_SO1",
            "topicName": "DeviceGrid_SO1/test/",
            "ruleName": "LNDEV_forward_to_kinesis",
            "ruleAction": "KinesisAction",
            "resources": {
                "StreamName": "LNDEV_telegraf-input-stream",
                "PartitionKey": "DeviceGrid_SO1/test/",
                "ShardId": "shardId-000000000000",
                "SequenceNumber": "49659725967821851025920655818127633624539141380218290178"
            },
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba"
        }
    }
]

In the failure scenario publishing with a Mosquitto broker and a bridge configuration, The Cloudwatch log are is as shown here -

[
    {
        "@timestamp": "2025-02-04 17:14:58.247",
        "@message": {
            "timestamp": "2025-02-04 17:14:58.247",
            "logLevel": "INFO",
            "traceId": "d21f4fb9-08e7-aef5-cb19-8634a9eef7ef",
            "accountId": "my-accountId",
            "status": "Success",
            "eventType": "Connect",
            "protocol": "MQTT",
            "clientId": "DeviceGrid_SO1",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba",
            "sourceIp": "50.232.1.166",
            "sourcePort": 37426
        }
    },
    {
        "@timestamp": "2025-02-04 17:14:58.293",
        "@message": {
            "timestamp": "2025-02-04 17:14:58.293",
            "logLevel": "INFO",
            "traceId": "61fcd645-87fc-d345-42e7-a98bdd12a6e2",
            "accountId": "my-accountId",
            "status": "Success",
            "eventType": "Unsubscribe",
            "protocol": "MQTT",
            "clientId": "DeviceGrid_SO1",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba",
            "sourceIp": "50.232.1.166",
            "sourcePort": 37426
        }
    },
    {
        "@timestamp": "2025-02-04 17:14:58.293",
        "@message": {
            "timestamp": "2025-02-04 17:14:58.293",
            "logLevel": "ERROR",
            "traceId": "3d2ffdbb-8b3e-81d9-f469-263eadabc6a8",
            "accountId": "my-accountId",
            "status": "Failure",
            "eventType": "Publish-In",
            "protocol": "MQTT",
            "topicName": "DeviceGrid_SO1/system-heartbeat",
            "clientId": "DeviceGrid_SO1",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba",
            "sourceIp": "50.232.1.166",
            "sourcePort": 37426,
            "reason": "AUTHORIZATION_FAILURE",
            "details": "Authorization Failure"
        }
    },
    {
        "@timestamp": "2025-02-04 17:14:58.293",
        "@message": {
            "timestamp": "2025-02-04 17:14:58.293",
            "logLevel": "ERROR",
            "traceId": "98b128a9-40ed-c488-6446-b9404dfea64d",
            "accountId": "my-accountId",
            "status": "Failure",
            "eventType": "Publish-In",
            "protocol": "MQTT",
            "topicName": "DeviceGrid_SO1/system-info/system-time-utc",
            "clientId": "DeviceGrid_SO1",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba",
            "sourceIp": "50.232.1.166",
            "sourcePort": 37426,
            "reason": "AUTHORIZATION_FAILURE",
            "details": "Authorization Failure"
        }
    },
    {
        "@timestamp": "2025-02-04 17:14:58.293",
        "@message": {
            "timestamp": "2025-02-04 17:14:58.293",
            "logLevel": "ERROR",
            "traceId": "eb01b42e-45cf-7255-ef15-6280a7913418",
            "accountId": "my-accountId",
            "status": "Failure",
            "eventType": "Publish-In",
            "protocol": "MQTT",
            "topicName": "DeviceGrid_SO1/system-info/bsp-version",
            "clientId": "DeviceGrid_SO1",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba",
            "sourceIp": "50.232.1.166",
            "sourcePort": 37426,
            "reason": "AUTHORIZATION_FAILURE",
            "details": "Authorization Failure"
        }
    },
    {
        "@timestamp": "2025-02-04 17:14:58.293",
        "@message": {
            "timestamp": "2025-02-04 17:14:58.293",
            "logLevel": "ERROR",
            "traceId": "7b1d36b4-1faa-0909-a05e-8bda99a021e5",
            "accountId": "my-accountId",
            "status": "Failure",
            "eventType": "Publish-In",
            "protocol": "MQTT",
            "topicName": "DeviceGrid_SO1/system-info/cpu-temperature-degrees-celsius",
            "clientId": "DeviceGrid_SO1",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba",
            "sourceIp": "50.232.1.166",
            "sourcePort": 37426,
            "reason": "AUTHORIZATION_FAILURE",
            "details": "Authorization Failure"
        }
    },
    {
        "@timestamp": "2025-02-04 17:14:58.293",
        "@message": {
            "timestamp": "2025-02-04 17:14:58.293",
            "logLevel": "ERROR",
            "traceId": "4fc9e6d1-b73d-a4b3-8377-2a4dbfe803f6",
            "accountId": "my-accountId",
            "status": "Failure",
            "eventType": "Publish-In",
            "protocol": "MQTT",
            "topicName": "DeviceGrid_SO1/system-info/uptime-seconds",
            "clientId": "DeviceGrid_SO1",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba",
            "sourceIp": "50.232.1.166",
            "sourcePort": 37426,
            "reason": "AUTHORIZATION_FAILURE",
            "details": "Authorization Failure"
        }
    },
    {
        "@timestamp": "2025-02-04 17:14:58.316",
        "@message": {
            "timestamp": "2025-02-04 17:14:58.316",
            "logLevel": "INFO",
            "traceId": "1de83b1a-ee39-0dfb-e525-b1253c4dd054",
            "accountId": "my-accountId",
            "status": "Success",
            "eventType": "Disconnect",
            "protocol": "MQTT",
            "clientId": "DeviceGrid_SO1",
            "principalId": "11de9f15fd7bccc905d9838e9120280a7f039a81c13eea5be5217117ae7067ba",
            "sourceIp": "50.232.1.166",
            "sourcePort": 37426,
            "disconnectReason": "CLIENT_ERROR"
        }
    }
]

The policy, verified by aws iot get-effective-policies --thing-name DeviceGrid_SO1 --principal $PRINCIPAL_ID is as follows

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "iot:Connect",
      "Resource": "arn:aws:iot:us-east-2:471112966900:client/${iot:Connection.Thing.ThingName}"
    },
    {
      "Effect": "Allow",
      "Action": [
        "iot:Publish",
        "iot:Receive"
      ],
      "Resource": [
        "arn:aws:iot:us-east-2:471112966900:topic/${iot:Connection.Thing.ThingName}/*",
        "arn:aws:iot:us-east-2:471112966900:topic/$aws/things/${iot:Connection.Thing.ThingName}/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": "iot:Subscribe",
      "Resource": [
        "arn:aws:iot:us-east-2:471112966900:topicfilter/${iot:Connection.Thing.ThingName}/*",
        "arn:aws:iot:us-east-2:471112966900:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": "greengrass:*",
      "Resource": "*"
    }
  ]
}

asked 2 years ago249 views

2 Answers
0

The first suggestion did not resolve the issue. The bridge configuration doesn't produce any publication to AWS IOT.
This configuration does produce a cloud publication that is still receiving the AUTHORIZATION_FAILURE result.

topic grid-cloud/# out 0 "" ${MQTT_THING_PREFIX}/

Cloudwatch reports the topic as shown which should be allowed by the policy.

topicName	DeviceGrid_SO1/grid-cloud/system-info/cpu-temperature-degrees-celsius

answered 2 years ago

-1

The authorization failure you're experiencing when publishing to IoT Core from MQTT on your Greengrass device is likely due to a mismatch between the topic structure in your bridge configuration and the permissions granted in your IoT policy.

In your Mosquitto bridge configuration, you're using this topic mapping:

topic # out 0 grid-cloud/ ${MQTT_THING_PREFIX}/

This means that messages published to any topic on the local broker will be forwarded to IoT Core with "grid-cloud/" prepended to the topic, followed by the thing name.

However, your IoT policy only allows publishing to topics that start with the thing name:

"Resource": [
  "arn:aws:iot:us-east-2:471112966900:topic/${iot:Connection.Thing.ThingName}/*",
  "arn:aws:iot:us-east-2:471112966900:topic/$aws/things/${iot:Connection.Thing.ThingName}/*"
]

To resolve this issue, you have two options:

  1. Modify your Mosquitto bridge configuration to match your policy: Change the topic mapping to:

    topic # out 0 ${MQTT_THING_PREFIX}/
    

    This will ensure that all forwarded topics start with the thing name.

  2. Update your IoT policy to allow publishing to topics that start with "grid-cloud/": Add this resource to your policy's Publish permission:

    "arn:aws:iot:us-east-2:471112966900:topic/grid-cloud/${iot:Connection.Thing.ThingName}/*"
    

Either of these changes should resolve the authorization failure. Remember to redeploy your policy or restart your Mosquitto broker after making changes.

Additionally, ensure that your ${MQTT_THING_PREFIX} variable in the Mosquitto configuration matches exactly with the thing name used in AWS IoT Core. Any mismatch here could also lead to authorization failures.
Sources
AWS Greengrass Manual Provisioning is failing because of error=TLS (SSL) negotiation failed | AWS re:Post
AWS Greengrass: Trouble with MQTT-IPC bridging with 1 Client device -> multiple Core devices | AWS re:Post
Troubleshooting client devices - AWS IoT Greengrass

answered 2 years ago

  • Does the certificate Subject or Issuer affect the authorization by AWS IOT?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.