Skip to content

Commit abf85a9

Browse files
authored
Merge pull request #103309 from kgremban/release-x509
New article: DPS provisioning with X.509
2 parents 1edae5f + 731d57d commit abf85a9

File tree

5 files changed

+412
-41
lines changed

5 files changed

+412
-41
lines changed

articles/iot-edge/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
href: how-to-auto-provision-simulated-device-linux.md
140140
- name: Windows
141141
href: how-to-auto-provision-simulated-device-windows.md
142+
- name: X.509 certificate attestation
143+
href: how-to-auto-provision-x509-certs.md
142144
- name: Symmetric key attestation
143145
href: how-to-auto-provision-symmetric-keys.md
144146
- name: Develop and debug custom modules
Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
---
2+
title: Automatically provision devices with DPS using X.509 certificates - Azure IoT Edge | Microsoft Docs
3+
description: Use X.509 certificates to test automatic device provisioning for Azure IoT Edge with Device Provisioning Service
4+
author: kgremban
5+
manager: philmea
6+
ms.author: kgremban
7+
ms.reviewer: kevindaw
8+
ms.date: 02/28/2020
9+
ms.topic: conceptual
10+
ms.service: iot-edge
11+
services: iot-edge
12+
---
13+
14+
# Create and provision an IoT Edge device using X.509 certificates
15+
16+
With the [Azure IoT Hub Device Provisioning Service (DPS)](../iot-dps/index.yml), you can automatically provision IoT Edge devices using X.509 certificates. If you're unfamiliar with the process of auto-provisioning, review the [auto-provisioning concepts](../iot-dps/concepts-auto-provisioning.md) before continuing.
17+
18+
This article shows you how to create a Device Provisioning Service enrollment using X.509 certificates on an IoT Edge device with the following steps:
19+
20+
* Generate certificates and keys.
21+
* Create either an individual enrollment for a device, or a group enrollment for a set of devices.
22+
* Install the IoT Edge runtime and register the device with IoT Hub.
23+
24+
Using X.509 certificates as an attestation mechanism is an excellent way to scale production and simplify device provisioning. X.509 certificates are typically arranged in a certificate chain of trust in which each certificate in the chain is signed by the private key of the next higher certificate, and so on, terminating in a self-signed root certificate or a trusted root certificate. This arrangement establishes a delegated chain of trust from the root certificate generated by a trusted root certificate authority (CA) down through each intermediate CA to the end-entity "leaf" certificate installed on a device.
25+
26+
## Prerequisites
27+
28+
* An active IoT Hub.
29+
* A physical or virtual device to be the IoT Edge device.
30+
* Currently, group enrollment for IoT Edge is only supported for Linux devices.
31+
* The latest version of [Git](https://git-scm.com/download/) installed.
32+
* An instance of the IoT Hub Device Provisioning Service in Azure, linked to your IoT hub.
33+
* If you don't have a Device Provisioning Service instance, follow the instructions in [Set up the IoT Hub DPS](../iot-dps/quick-setup-auto-provision.md).
34+
* After you have the Device Provisioning Service running, copy the value of **ID Scope** from the overview page. You use this value when you configure the IoT Edge runtime.
35+
36+
## Generate device identity certificates
37+
38+
The device identity certificate is a leaf certificate that connects through a certificate chain of trust to the top X.509 CA certificate. The device identity certificate must have it common name (CN) set to the device ID that you want the device to have in your IoT hub.
39+
40+
Device identity certificates are only used for provisioning the IoT Edge device and authenticating the device with Azure IoT Hub. They are not signing certificates, unlike the CA certificates that the IoT Edge device presents to modules or leaf devices for verification. For more information, see [Azure IoT Edge certificate usage detail](iot-edge-certs.md).
41+
42+
After you create the device identity certificate, you should have two files: a .cer or .pem file that contains the public portion of the certificate, and a .cer or .pem file with the private key of the certificate. If you plan to use group enrollment in DPS, you also need the public portion of an intermediate or root CA certificate in the same certificate chain of trust.
43+
44+
### Use test certificates
45+
46+
If you don't have a certificate authority available to create new identity certs and want to try out this scenario, the Azure IoT Edge git repository contains scripts that you can use to generate test certificates. These certificates are designed for development testing only, and must not be used in production.
47+
48+
To create test certificates, follow the steps in [Create demo certificates to test IoT Edge device features](how-to-create-test-certificates.md). Complete the two required sections to set up the certificate generation scripts and to create a root CA certificate. Then, follow the steps to create a device identity certificate. When you're finished, you should have the following certificate chain and key pair:
49+
50+
Linux:
51+
52+
* `<WRKDIR>/certs/iot-edge-device-identity-<name>-full-chain.cert.pem`
53+
* `<WRKDIR>/private/iot-edge-device-identity-<name>.key.pem`
54+
55+
Windows:
56+
57+
* `<WRKDIR>\certs\iot-edge-device-identity-<name>-full-chain.cert.pem`
58+
* `<WRKDIR>\private\iot-edge-device-identity-<name>.key.pem`
59+
60+
You need both these certificates on the IoT Edge device. If you're going to use individual enrollment in DPS, then you will upload the .cert.pem file. If you're going to use group enrollment in DPS, then you also need an intermediate or root CA certificate in the same certificate chain of trust to upload. In the case of the test certs, you can use the `<WRKDIR>\certs\azure-iot-test-only.root.ca.cert.pem` certificate for group enrollment.
61+
62+
## Create a DPS individual enrollment
63+
64+
Use your generated certificates and keys to create an individual enrollment in DPS for a single IoT Edge device. Individual enrollments take the public portion of a device's identity certificate and match that to the certificate on the device.
65+
66+
If you're looking to provision multiple IoT Edge devices, follow the steps in the next section, [Create a DPS group enrollment](#create-a-dps-group-enrollment).
67+
68+
When you create an enrollment in DPS, you have the opportunity to declare an **Initial Device Twin State**. In the device twin, you can set tags to group devices by any metric you need in your solution, like region, environment, location, or device type. These tags are used to create [automatic deployments](how-to-deploy-monitor.md).
69+
70+
1. In the [Azure portal](https://portal.azure.com), navigate to your instance of IoT Hub Device Provisioning Service.
71+
72+
1. Under **Settings**, select **Manage enrollments**.
73+
74+
1. Select **Add individual enrollment** then complete the following steps to configure the enrollment:
75+
76+
* **Mechanism**: Select **X.509**.
77+
78+
* **Primary Certificate .pem or .cer file**: Upload the public file from the device identity certificate. If you used the scripts to generate a test certificate, choose the following file:
79+
80+
`<WRKDIR>/certs/iot-edge-device-identity-<name>-full-chain.cert.pem`
81+
82+
* **IoT Hub Device ID**: Provide an ID for your device if you'd like. You can use device IDs to target an individual device for module deployment. If you don't provide a device ID, the common name (CN) in the X.509 certificate is used.
83+
84+
* **IoT Edge device**: Select **True** to declare that the enrollment is for an IoT Edge device.
85+
86+
* **Select how you want to assign devices to hubs**: Accept the default value, evenly weighted distribution. Or choose a different value that is specific to this enrollment.
87+
88+
* **Select the IoT hubs this device can be assigned to**: Choose the linked IoT hub that you want to connect your device to. You can choose multiple hubs, and the device will be assigned to one of them according to the selected allocation policy.
89+
90+
* **Select how you want device data to be handled on re-provisioning**: Accept the default value, re-provision and migrate data. Or choose a different value to determine how to handle when devices request provisioning after the first time.
91+
92+
* **Initial Device Twin State**: Add a tag value to be added to the device twin if you'd like. You can use tags to target groups of devices for automatic deployment. For example:
93+
94+
```json
95+
{
96+
"tags": {
97+
"environment": "test"
98+
},
99+
"properties": {
100+
"desired": {}
101+
}
102+
}
103+
```
104+
105+
* **Enable entry**: Select **Enable**.
106+
107+
1. Select **Save**.
108+
109+
Now that an enrollment exists for this device, the IoT Edge runtime can automatically provision the device during installation. Continue to the [Install the IoT Edge runtime](#install-the-iot-edge-runtime) section to set up your IoT Edge device.
110+
111+
## Create a DPS group enrollment
112+
113+
Use your generated certificates and keys to create a group enrollment in DPS for multiple IoT Edge devices. Group enrollments use an intermediate or root CA certificate from the certificate chain of trust used to generate the individual device identity certificates.
114+
115+
>[!NOTE]
116+
>Currently, group enrollment is only supported for IoT Edge on Linux devices.
117+
118+
If you're looking to provision a single IoT Edge device instead, follow the steps in the previous section, [Create a DPS individual enrollment](#create-a-dps-individual-enrollment).
119+
120+
When you create an enrollment in DPS, you have the opportunity to declare an **Initial Device Twin State**. In the device twin, you can set tags to group devices by any metric you need in your solution, like region, environment, location, or device type. These tags are used to create [automatic deployments](how-to-deploy-monitor.md).
121+
122+
1. In the [Azure portal](https://portal.azure.com), navigate to your instance of IoT Hub Device Provisioning Service.
123+
124+
1. Under **Settings**, select **Manage enrollments**.
125+
126+
1. Select **Add enrollment group** then complete the following steps to configure the enrollment:
127+
128+
* **Group name**: Provide a memorable name for this group enrollment.
129+
130+
* **Attestation Type**: Select **Certificate**.
131+
132+
* **IoT Edge device**: Select **True**. For a group enrollment, all devices must be IoT Edge devices or none of them can be.
133+
134+
* **Certificate Type**: Select **CA Certificate** if you have a certificate stored with DPS already, or **Intermediate Certificate** if you want to upload a new file for just this enrollment.
135+
136+
* **Primary certificate**: If you chose CA certificate in the last section, choose your certificate from the dropdown list. If you chose intermediate certificate, upload the public file from an intermediate CA certificate in the certificate chain of trust that was used to generate the device identity certificates.
137+
138+
* **Select how you want to assign devices to hubs**: Accept the default value, evenly weighted distribution. Or choose a different value that is specific to this enrollment.
139+
140+
* **Select the IoT hubs this device can be assigned to**: Choose the linked IoT hub that you want to connect your device to. You can choose multiple hubs, and the device will be assigned to one of them according to the selected allocation policy.
141+
142+
* **Select how you want device data to be handled on re-provisioning**: Accept the default value, re-provision and migrate data. Or choose a different value to determine how to handle when devices request provisioning after the first time.
143+
144+
* **Initial Device Twin State**: Add a tag value to be added to the device twin if you'd like. You can use tags to target groups of devices for automatic deployment. For example:
145+
146+
```json
147+
{
148+
"tags": {
149+
"environment": "test"
150+
},
151+
"properties": {
152+
"desired": {}
153+
}
154+
}
155+
```
156+
157+
* **Enable entry**: Select **Enable**.
158+
159+
1. Select **Save**.
160+
161+
Now that an enrollment exists for this device, the IoT Edge runtime can automatically provision the device during installation. Continue to the next section to set up your IoT Edge device.
162+
163+
## Install the IoT Edge runtime
164+
165+
The IoT Edge runtime is deployed on all IoT Edge devices. Its components run in containers, and allow you to deploy additional containers to the device so that you can run code at the edge.
166+
167+
X.509 provisioning with DPS is only supported in IoT Edge version 1.0.9 or newer.
168+
169+
You'll need the following information when provisioning your device:
170+
171+
* The DPS **ID Scope** value. You can retrieve this value from the overview page of your DPS instance in the Azure portal.
172+
* The device identity certificate file on the device.
173+
* The device identity key file on the device.
174+
* An optional registration ID (pulled from the common name in the device identity certificate if not supplied).
175+
176+
### Linux device
177+
178+
Use the following link to install the Azure IoT Edge runtime on your device, using the commands appropriate for your device's architecture. When you get to the section on configuring the security daemon, configure the IoT Edge runtime for X.509 automatic, not manual, provisioning. You should have all the information and certificate files that you need after completing the previous sections of this article.
179+
180+
[Install the Azure IoT Edge runtime on Linux](how-to-install-iot-edge-linux.md)
181+
182+
When you add the X.509 certificate and key information to the config.yaml file, the paths should be provided as file URIs. For example:
183+
184+
* `file:///<path>/identity_certificate.pem`
185+
* `file:///<path>/identity_key.pem`
186+
187+
The section in the configuration file for X.509 automatic provisioning looks like this:
188+
189+
```yaml
190+
# DPS X.509 provisioning configuration
191+
provisioning:
192+
source: "dps"
193+
global_endpoint: "https://global.azure-devices-provisioning.net"
194+
scope_id: "{scope_id}"
195+
attestation:
196+
method: "x509"
197+
# registration_id: "<OPTIONAL REGISTRATION ID. IF UNSPECIFIED CAN BE OBTAINED FROM CN OF identity_cert"
198+
identity_cert: "<REQUIRED URI TO DEVICE IDENTITY CERTIFICATE>"
199+
identity_pk: "<REQUIRED URI TO DEVICE IDENTITY PRIVATE KEY>"
200+
```
201+
202+
Replace the placeholder values for `scope_id`, `identity_cert`, `identity_pk` with the scope ID from your DPS instance, and the URIs to the cert and key file locations on your device. Provide a `registration_id` for the device if you want, or leave this line commented out to register the device with the CN name of the identity certificate.
203+
204+
Always restart the security daemon after updating the config.yaml file.
205+
206+
```bash
207+
sudo systemctl restart iotedge
208+
```
209+
210+
### Windows device
211+
212+
Install the IoT Edge runtime on the device for which you generated the identity certificate and identity key. You'll configure the IoT Edge runtime for automatic, not manual, provisioning.
213+
214+
For more detailed information about installing IoT Edge on Windows, including prerequisites and instructions for tasks like managing containers and updating IoT Edge, see [Install the Azure IoT Edge runtime on Windows](how-to-install-iot-edge-windows.md).
215+
216+
1. Open a PowerShell window in administrator mode. Be sure to use an AMD64 session of PowerShell when installing IoT Edge, not PowerShell (x86).
217+
218+
1. The **Deploy-IoTEdge** command checks that your Windows machine is on a supported version, turns on the containers feature, and then downloads the moby runtime and the IoT Edge runtime. The command defaults to using Windows containers.
219+
220+
```powershell
221+
. {Invoke-WebRequest -useb https://aka.ms/iotedge-win} | Invoke-Expression; `
222+
Deploy-IoTEdge
223+
```
224+
225+
1. At this point, IoT Core devices may restart automatically. Other Windows 10 or Windows Server devices may prompt you to restart. If so, restart your device now. Once your device is ready, run PowerShell as an administrator again.
226+
227+
1. The **Initialize-IoTEdge** command configures the IoT Edge runtime on your machine. The command defaults to manual provisioning unless you use the `-Dps` flag to use automatic provisioning.
228+
229+
Replace the placeholder values for `{scope_id}`, `{identity cert path}`, and `{identity key path}` with the appropriate values from your DPS instance and the file paths on your device. If you want to specify the registration ID, include `-RegistrationId {registration_id}` as well, replacing the placeholder as appropriate.
230+
231+
```powershell
232+
. {Invoke-WebRequest -useb https://aka.ms/iotedge-win} | Invoke-Expression; `
233+
Initialize-IoTEdge -Dps -ScopeId {scope ID} -X509IdentityCertificate {identity cert path} -X509IdentityPrivateKey {identity key path}
234+
```
235+
236+
>[!TIP]
237+
>The config.yaml file stores your certificate and key information as file URIs. However, the Initialize-IoTEdge command handles this formatting step for you, so you can provide the absolute path to the certificate and key files on your device.
238+
239+
## Verify successful installation
240+
241+
If the runtime started successfully, you can go into your IoT Hub and start deploying IoT Edge modules to your device.
242+
243+
You can verify that the individual enrollment that you created in Device Provisioning Service was used. Navigate to your Device Provisioning Service instance in the Azure portal. Open the enrollment details for the individual enrollment that you created. Notice that the status of the enrollment is **assigned** and the device ID is listed.
244+
245+
Use the following commands on your device to verify that the runtime installed and started successfully.
246+
247+
### Linux device
248+
249+
Check the status of the IoT Edge service.
250+
251+
```cmd/sh
252+
systemctl status iotedge
253+
```
254+
255+
Examine service logs.
256+
257+
```cmd/sh
258+
journalctl -u iotedge --no-pager --no-full
259+
```
260+
261+
List running modules.
262+
263+
```cmd/sh
264+
iotedge list
265+
```
266+
267+
### Windows device
268+
269+
Check the status of the IoT Edge service.
270+
271+
```powershell
272+
Get-Service iotedge
273+
```
274+
275+
Examine service logs.
276+
277+
```powershell
278+
. {Invoke-WebRequest -useb aka.ms/iotedge-win} | Invoke-Expression; Get-IoTEdgeLog
279+
```
280+
281+
List running modules.
282+
283+
```powershell
284+
iotedge list
285+
```
286+
287+
## Next steps
288+
289+
The Device Provisioning Service enrollment process lets you set the device ID and device twin tags at the same time as you provision the new device. You can use those values to target individual devices or groups of devices using automatic device management. Learn how to [Deploy and monitor IoT Edge modules at scale using the Azure portal](how-to-deploy-monitor.md) or [using Azure CLI](how-to-deploy-monitor-cli.md).

0 commit comments

Comments
 (0)