Skip to content

AWS IoT API call using Device Certificate

0

I am trying to reach the AWS IoT API using the device certificate, but got a ResourceNotFoundError. It stated in the documentation, that such flow should work.

Devices can use X.509 certificates to connect to AWS IoT Core using TLS mutual authentication protocols.

Here is the CURL request, that I am trying to perform:

curl --tlsv1.2 -v \
    --cacert AmazonRootCA.pem \
    --cert certificate.pem.crt \
    --key private.pem.key \
    --request GET \
    "https://{redacted}-ats.iot.eu-north-1.amazonaws.com/things/abc"

but got the following response:

< HTTP/1.1 404 Not Found
< content-type: application/json
< content-length: 72
< date: Mon, 18 Nov 2024 14:37:37 GMT
< x-amzn-RequestId: {redacted}
< connection: keep-alive
< x-amzn-ErrorType: ResourceNotFoundException:
<
* Connection #0 to host {redacted}-ats.iot.eu-north-1.amazonaws.com left intact
{"message":"Not Found","traceId":"{redacted}"}

Same response came on the ListThings endpoint.

My policy should allow such API calls:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "iot:DescribeThing",
        "iot:ListThings"
      ],
      "Resource": "*"
    }
  ]
}

I am trying to find the easiest way to authenticate my API calls, because I have so few of them. Executing that complex flow to get a security token seems like overkill in this scenario.

asked 2 years ago335 views

1 Answer
1

To make API calls to AWS IoT services using a device certificate, you need to use the AWS IoT Core credential provider. This process involves a few more steps than your current approach:

  1. First, you need to create an IAM role that has the permissions to perform the API actions you want (like DescribeThing and ListThings).

  2. Then, you need to create a role alias in AWS IoT Core that points to this IAM role.

  3. You must attach a policy to your device certificate that allows the iot:AssumeRoleWithCertificate action for the role alias you created.

  4. Finally, you need to make an HTTPS request to the AWS IoT credentials provider endpoint to get temporary security credentials (access key ID, secret access key, and session token).

Once you have these temporary credentials, you can use them to sign your API requests to AWS IoT services.

Your current approach of directly using the device certificate for API calls won't work because the IoT service endpoints don't recognize device certificates for API authentication. They expect either IAM credentials or temporary security tokens obtained through the credential provider.

While this process might seem complex for just a few API calls, it's the secure way AWS IoT Core is designed to work with devices. It allows devices to obtain temporary credentials without storing long-term access keys on the device itself.

If you find this process too cumbersome for your use case, you might want to consider alternative authentication methods for your API calls, such as using IAM users or roles, depending on your specific requirements and security considerations.
Sources
Authorizing direct calls to AWS services using AWS IoT Core credential provider - AWS IoT Core
Resources in AWS IoT Core - Device Manufacturing and Provisioning with X.509 Certificates in AWS IoT Core

answered 2 years ago

AWS
EXPERT

revised 2 years ago

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.