Search code examples
google-cloud-platformiotgoogle-cloud-iot

Can we get RSA public key associated with device from google iot core


Actually, I have a device and its associated public key on Google IoT Core. Is it possible to get that public key from any script using the service account (and respective registry). Is it restricted keys on google-iot-core?


Solution

  • Yes, it is possible. An example using python iot client:

    from google.cloud import iot_v1
    
    client = iot_v1.DeviceManagerClient()
    
    name = client.device_path('my-project', 'my-location', 'my-registry', 'my-device')
    
    response = client.get_device(name)
    
    # Here you can see the credentials
    print(response.credentials)
    

    An example using gcloud:

    gcloud iot devices describe my-device --project=my-project --region=my-location --registry=my-registry --format=json | jq '.credentials
    

    You can get this information with other clients or using the Rest API directly.