Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect system information at fleet provisioning #451

Closed
wants to merge 0 commits into from

Conversation

JarryShaw
Copy link
Contributor

@JarryShaw JarryShaw commented Mar 13, 2024

Motivation

  • Please give a brief description for the background of this change.
  • Issue number: N/A

We would like to collect and publish system information when the IoT device client proceeds with fleet provisioning,
such that our pre-provisioning hook (Lambda service) will be able to validate necessary information per security considerations and
revoke the provisioning SSL certificates upon success of this event.

This change has been reviewed internally by our team and a team member of ours had spoken with the owner of this package and gained
confirmation of contributing our envisioned change to this open-source project.

Modifications

Change summary

Please describe what changes are included in this pull request.

Added several auxiliary methods to the FleetProvisioning class to collect the following information:

  1. device's IP and MAC address
  2. SHA-256 hash value of the device client
  3. serial number (ID) of the provisioning certificate

and publish such information along with the fleet provisioning request to the AWS IoT Core.

Revision diff summary

If there is more than one revision, please explain what has been changed since the last revision.

N/A

Testing

Is your change tested? If not, please justify the reason.
Please list your testing steps and test results.

  • CI test run result: N/A

Since the added methods are private methods, no unit tests were created. However, we have tested on a camera in our testing environment
with the changes made in this PR. Below is the IoT device client's log emitting collected system information (sensitive information has
been reducted):

Mar 13 14:35:48 aws-iot-device-client[20326]: 2024-03-13T14:35:48.199Z [INFO]  {FleetProvisioning.cpp}: Provisioning new device certificate and private key using CreateKeysAndCertificate API
Mar 13 14:35:48 aws-iot-device-client[20326]: 2024-03-13T14:35:48.199Z [INFO]  {FleetProvisioning.cpp}: Subscribing to CreateKeysAndCertificate Accepted and Rejected topics
Mar 13 14:35:48 aws-iot-device-client[20326]: 2024-03-13T14:35:48.248Z [INFO]  {FleetProvisioning.cpp}: Publishing to CreateKeysAndCertificate topic
Mar 13 14:35:48 aws-iot-device-client[20326]: 2024-03-13T14:35:48.570Z [INFO]  {FleetProvisioning.cpp}: CreateKeysAndCertificateResponse certificateId: [REDUCTED].
Mar 13 14:35:48 aws-iot-device-client[20326]: 2024-03-13T14:35:48.572Z [INFO]  {FleetProvisioning.cpp}: Stored certificate and private key in /root/.aws-iot-device-client/keys/[REDUCTED]-certificate.pem.crt and /root/.aws-iot-device-client/keys/[REDUCTED]-private.pem.key files
Mar 13 14:35:48 aws-iot-device-client[20326]: 2024-03-13T14:35:48.573Z [INFO]  {FleetProvisioning.cpp}: Attempting to set permissions for certificate and private key...
Mar 13 14:35:48 aws-iot-device-client[20326]: 2024-03-13T14:35:48.573Z [INFO]  {FleetProvisioning.cpp}: Successfully set permissions on provisioned public certificate and private key
Mar 13 14:35:48 aws-iot-device-client[20326]: 2024-03-13T14:35:48.573Z [INFO]  {FleetProvisioning.cpp}: Subscribing to RegisterThing Accepted and Rejected topics
Mar 13 14:35:48 aws-iot-device-client[20326]: 2024-03-13T14:35:48.625Z [INFO]  {FleetProvisioning.cpp}: Collect system information
Mar 13 14:35:48 aws-iot-device-client[20326]: 2024-03-13T14:35:48.625Z [DEBUG] {FleetProvisioning.cpp}: Successfully collected network information: {"DeviceIPAddress": "[REDUCTED]", "DeviceMACAddress": "[REDUCTED]"}
Mar 13 14:35:49 aws-iot-device-client[20326]: 2024-03-13T14:35:49.225Z [DEBUG] {FleetProvisioning.cpp}: File 'IoTDeviceClient' SHA256 hash: 591ed4238e753226dcca4659fac39dbac60db78855d1dfa54be6e5bdab17f923
Mar 13 14:35:49 aws-iot-device-client[20326]: 2024-03-13T14:35:49.229Z [DEBUG] {FleetProvisioning.cpp}: Provisioning certificate serial number: [REDUCTED]
Mar 13 14:35:49 aws-iot-device-client[20326]: 2024-03-13T14:35:49.229Z [INFO]  {FleetProvisioning.cpp}: System information:
Mar 13 14:35:49 aws-iot-device-client[20326]: 	"DeviceIPAddress": "[REDUCTED]",
Mar 13 14:35:49 aws-iot-device-client[20326]: 	"DeviceMACAddress": "[REDUCTED]",
Mar 13 14:35:49 aws-iot-device-client[20326]: 	"IoTDeviceClient-SHA256Hash": "591ed4238e753226dcca4659fac39dbac60db78855d1dfa54be6e5bdab17f923",
Mar 13 14:35:49 aws-iot-device-client[20326]: 	"ProvisioningCertSerialNumber": "[REDUCTED]",
Mar 13 14:35:49 aws-iot-device-client[20326]: 	"SerialNumber": "[REDUCTED]"
Mar 13 14:35:49 aws-iot-device-client[20326]: 2024-03-13T14:35:49.229Z [INFO]  {FleetProvisioning.cpp}: Publishing to RegisterThing topic
Mar 13 14:35:49 aws-iot-device-client[20326]: 2024-03-13T14:35:49.866Z [INFO]  {FleetProvisioning.cpp}: RegisterThingResponse ThingName: ProvisioningTest-[REDUCTED].
Mar 13 14:35:49 aws-iot-device-client[20326]: 2024-03-13T14:35:49.867Z [DEBUG] {FleetProvisioning.cpp}: {
Mar 13 14:35:49 aws-iot-device-client[20326]: "runtime-config": {
Mar 13 14:35:49 aws-iot-device-client[20326]:     "completed-fp": true,
Mar 13 14:35:49 aws-iot-device-client[20326]:     "cert": "/root/.aws-iot-device-client/keys/[REDUCTED]-certificate.pem.crt",
Mar 13 14:35:49 aws-iot-device-client[20326]:     "key": "/root/.aws-iot-device-client/keys/[REDUCTED]-private.pem.key",
Mar 13 14:35:49 aws-iot-device-client[20326]:     "thing-name": "ProvisioningTest-[REDUCTED]",
Mar 13 14:35:49 aws-iot-device-client[20326]:     "device-config": {
Mar 13 14:35:49 aws-iot-device-client[20326]:         
Mar 13 14:35:49 aws-iot-device-client[20326]:         }
Mar 13 14:35:49 aws-iot-device-client[20326]:     }
Mar 13 14:35:49 aws-iot-device-client[20326]: }
Mar 13 14:35:49 aws-iot-device-client[20326]: 2024-03-13T14:35:49.867Z [INFO]  {FleetProvisioning.cpp}: Exported runtime configurations to: ~/.aws-iot-device-client/aws-iot-device-client-runtime.conf
Mar 13 14:35:49 aws-iot-device-client[20326]: 2024-03-13T14:35:49.868Z [INFO]  {FleetProvisioning.cpp}: Successfully provisioned thing: ProvisioningTest-[REDUCTED]

and from our preprovisioning Lambda, the fleet provisioning request successfully received the published system information:

@timestamp @message
2024-03-13 14:35:49.476 INIT_START Runtime Version: python:3.12.v20 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:[REDUCTED]
2024-03-13 14:35:49.558 START RequestId: [REDUCTED] Version: $LATEST
2024-03-13 14:35:49.559 Received event: {
2024-03-13 14:35:49.559 "claimCertificateId": "[REDUCTED]",
2024-03-13 14:35:49.559 "certificateId": "[REDUCTED]",
2024-03-13 14:35:49.559 "certificatePem": "[REDUCTED]",
2024-03-13 14:35:49.559 "templateArn": "arn:aws:iot:us-east-1:[REDUCTED]:provisioningtemplate/TrustedUserProvisioningTemplate",
2024-03-13 14:35:49.559 "clientId": "FleetProvisionedCamera-1",
2024-03-13 14:35:49.559 "parameters": {
2024-03-13 14:35:49.559 "DeviceIPAddress": "[REDUCTED]",
2024-03-13 14:35:49.559 "ProvisioningCertSerialNumber": "[REDUCTED]",
2024-03-13 14:35:49.559 "SerialNumber": "[REDUCTED]",
2024-03-13 14:35:49.559 "DeviceMACAddress": "[REDUCTED]",
2024-03-13 14:35:49.559 "IoTDeviceClient-SHA256Hash": "591ed4238e753226dcca4659fac39dbac60db78855d1dfa54be6e5bdab17f923"
2024-03-13 14:35:49.559 }
2024-03-13 14:35:49.559 }
2024-03-13 14:35:49.563 END RequestId: [REDUCTED]
2024-03-13 14:35:49.563 REPORT RequestId: [REDUCTED] Duration: 4.09 ms Billed Duration: 5 ms Memory Size: 128 MB Max Memory Used: 33 MB Init Duration: 81.16 ms

Hence, the fleet provisioning attempt with the changes in this PR was successful.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@maheshrkumar
Copy link

maheshrkumar commented Mar 15, 2024

We (********) would like to collect and publish system information when the IoT device client proceeds with fleet provisioning, such that our pre-provisioning hook (Lambda service) will be able to validate necessary information per security considerations and revoke the provisioning SSL certificates upon success of this event.

Can you remove our organization's name ?

Copy link

@maheshrkumar maheshrkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Copy link
Contributor

@RogerZhongAWS RogerZhongAWS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments and a couple of outstanding questions.. LGTM otherwise. Thank you folks for your contributions!

source/fleetprovisioning/FleetProvisioning.cpp Outdated Show resolved Hide resolved
source/fleetprovisioning/FleetProvisioning.cpp Outdated Show resolved Hide resolved
source/fleetprovisioning/FleetProvisioning.cpp Outdated Show resolved Hide resolved
source/fleetprovisioning/FleetProvisioning.cpp Outdated Show resolved Hide resolved
source/fleetprovisioning/FleetProvisioning.h Outdated Show resolved Hide resolved
Copy link
Contributor

@HarshGandhi-AWS HarshGandhi-AWS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comments. Everything else looks good to me.

@RogerZhongAWS
Copy link
Contributor

changes mostly look good to me, just missing adding an option in the CLI and JSON parser but we can add a change on top of this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants