Skip to content

Commit 5667376

Browse files
authored
Merge pull request #204785 from fcabrera23/eflow-gateway
Eflow gateway
2 parents 25f6bda + bef2a26 commit 5667376

File tree

1 file changed

+113
-12
lines changed

1 file changed

+113
-12
lines changed

articles/iot-edge/how-to-create-transparent-gateway.md

Lines changed: 113 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ For a device to act as a gateway, it needs to securely connect to its downstream
4747

4848
<!-- 1.1 -->
4949
:::moniker range="iotedge-2018-06"
50-
A downstream device can be any application or platform that has an identity created with the [Azure IoT Hub](../iot-hub/index.yml) cloud service. These applications often use the [Azure IoT device SDK](../iot-hub/iot-hub-devguide-sdks.md). A downstream device could even be an application running on the IoT Edge gateway device itself. However, an IoT Edge device cannot be downstream of an IoT Edge gateway.
50+
A downstream device can be any application or platform that has an identity created with the [Azure IoT Hub](../iot-hub/index.yml) cloud service. These applications often use the [Azure IoT device SDK](../iot-hub/iot-hub-devguide-sdks.md). A downstream device could even be an application running on the IoT Edge gateway device itself. However, an IoT Edge device can't be downstream of an IoT Edge gateway.
5151
:::moniker-end
5252
<!-- end 1.1 -->
5353

@@ -66,9 +66,22 @@ The following steps walk you through the process of creating the certificates an
6666

6767
## Prerequisites
6868

69+
# [IoT Edge](#tab/iotedge)
70+
6971
A Linux or Windows device with IoT Edge installed.
7072

71-
If you do not have a device ready, you can create one in an Azure virtual machine. Follow the steps in [Deploy your first IoT Edge module to a virtual Linux device](quickstart-linux.md) to create an IoT Hub, create a virtual machine, and configure the IoT Edge runtime.
73+
If you don't have a device ready, you can create one in an Azure virtual machine. Follow the steps in [Deploy your first IoT Edge module to a virtual Linux device](quickstart-linux.md) to create an IoT Hub, create a virtual machine, and configure the IoT Edge runtime.
74+
75+
# [IoT Edge for Linux on Windows](#tab/eflow)
76+
77+
>[!WARNING]
78+
> Because the IoT Edge for Linux on Windows (EFLOW) virtual machine needs to be accessible from external devices, ensure to deploy EFLOW with an _external_ virtual switch. For more information about EFLOW networking configurations, see [Networking configuration for Azure IoT Edge for Linux on Windows](./how-to-configure-iot-edge-for-linux-on-windows-networking.md).
79+
80+
A Windows device with IoT Edge for Linux on Windows installed.
81+
82+
If you don't have a device ready, you should create one before continuing with this guide. Follow the steps in [Create and provision an IoT Edge for Linux on Windows device using symmetric keys](./how-to-provision-single-device-linux-on-windows-symmetric.md) to create an IoT Hub, create an EFLOW virtual machine, and configure the IoT Edge runtime.
83+
84+
---
7285

7386
## Set up the device CA certificate
7487

@@ -89,16 +102,69 @@ Have the following files ready:
89102

90103
For production scenarios, you should generate these files with your own certificate authority. For development and test scenarios, you can use demo certificates.
91104

105+
### Create demo certificates
106+
92107
If you don't have your own certificate authority and want to use demo certificates, follow the instructions in [Create demo certificates to test IoT Edge device features](how-to-create-test-certificates.md) to create your files. On that page, you need to take the following steps:
93108

94-
1. To start, set up the scripts for generating certificates on your device.
95-
2. Create a root CA certificate. At the end of those instructions, you'll have a root CA certificate file:
96-
* `<path>/certs/azure-iot-test-only.root.ca.cert.pem`.
97-
3. Create IoT Edge device CA certificates. At the end of those instructions, you'll have a device CA certificate and its private key:
98-
* `<path>/certs/iot-edge-device-ca-<cert name>-full-chain.cert.pem` and
99-
* `<path>/private/iot-edge-device-ca-<cert name>.key.pem`
109+
1. To start, set up the scripts for generating certificates on your device.
110+
1. Create a root CA certificate. At the end of those instructions, you'll have a root CA certificate file `<path>/certs/azure-iot-test-only.root.ca.cert.pem`.
111+
1. Create IoT Edge device CA certificates. At the end of those instructions, you'll have a device CA certificate `<path>/certs/iot-edge-device-ca-<cert name>-full-chain.cert.pem` its private key `<path>/private/iot-edge-device-ca-<cert name>.key.pem`.
112+
113+
### Copy certificates to device
114+
115+
# [IoT Edge](#tab/iotedge)
116+
117+
If you created the certificates on a different machine, copy them over to your IoT Edge device then proceed with the next steps. You can use a USB drive, a service like [Azure Key Vault](../key-vault/general/overview.md), or with a function like [Secure file copy](https://www.ssh.com/ssh/scp/). Choose one of these methods that best matches your scenario.
118+
119+
# [IoT Edge for Linux on Windows](#tab/eflow)
120+
121+
Now, you need to copy the certificates to the Azure IoT Edge for Linux on Windows virtual machine.
122+
123+
1. Open an elevated _PowerShell_ session by starting with **Run as Administrator**.
124+
125+
Connect to the EFLOW virtual machine.
126+
127+
```powershell
128+
Connect-EflowVm
129+
```
130+
131+
1. Create the certificates directory. You can select any writeable directory. For this tutorial, we'll use the _iotedge-user_ home folder.
132+
133+
```bash
134+
cd ~
135+
mkdir certs
136+
cd certs
137+
mkdir certs
138+
mkdir private
139+
```
140+
141+
1. Exit the EFLOW VM connection.
142+
143+
```bash
144+
exit
145+
```
146+
147+
1. Copy the certificates to the EFLOW virtual machine.
100148

101-
If you created the certificates on a different machine, copy them over to your IoT Edge device then proceed with the next steps.
149+
```powershell
150+
# Copy the IoT Edge device CA certificates
151+
Copy-EflowVMFile -fromFile <path>\certs\iot-edge-device-ca-<cert name>-full-chain.cert.pem -toFile /home/iotedge-user/certs/certs/iot-edge-device-ca-<cert name>-full-chain.cert.pem -pushFile
152+
Copy-EflowVMFile -fromFile <path>\private\iot-edge-device-ca-<cert name>.key.pem -toFile /home/iotedge-user/certs/private/iot-edge-device-ca-<cert name>.key.pem -pushFile
153+
154+
# Copy the root CA certificate
155+
Copy-EflowVMFile -fromFile <path>\certs\azure-iot-test-only.root.ca.cert.pem -toFile /home/iotedge-user/certs/certs/azure-iot-test-only.root.ca.cert.pem -pushFile
156+
```
157+
158+
1. Invoke the following commands on the EFLOW VM to grant iotedge permissions to the certificate files since `Copy-EflowVMFile` copies files with root only access permissions.
159+
160+
```powershell
161+
Invoke-EflowVmCommand "sudo chown -R iotedge /home/iotedge-user/certs/"
162+
Invoke-EflowVmCommand "sudo chmod 0644 /home/iotedge-user/certs/"
163+
```
164+
165+
----
166+
167+
### Configure certificates on device
102168

103169
<!-- 1.1 -->
104170
:::moniker range="iotedge-2018-06"
@@ -107,26 +173,32 @@ If you created the certificates on a different machine, copy them over to your I
107173

108174
* Windows: `C:\ProgramData\iotedge\config.yaml`
109175
* Linux: `/etc/iotedge/config.yaml`
176+
* IoT Edge for Linux on Windows: `/etc/iotedge/config.yaml`
177+
178+
>[!TIP]
179+
> If you are using IoT Edge for Linux on Windows (EFLOW) you'll have to connect to the EFLOW virtual machine and change the file inside the VM. You can connect to the EFLOW VM using the PowerShell cmdlet `Connect-EflowVm` and then use your preferred editor.
110180
111181
1. Find the **Certificate settings** section of the file. Uncomment the four lines starting with **certificates:** and provide the file URIs to your three files as values for the following properties:
112182
* **device_ca_cert**: device CA certificate
113183
* **device_ca_pk**: device CA private key
114184
* **trusted_ca_certs**: root CA certificate
115185

116-
Make sure there is no preceding whitespace on the **certificates:** line, and that the other lines are indented by two spaces.
186+
Make sure there's no preceding whitespace on the **certificates:** line, and that the other lines are indented by two spaces.
117187

118188
1. Save and close the file.
119189

120190
1. Restart IoT Edge.
121191
* Windows: `Restart-Service iotedge`
122192
* Linux: `sudo systemctl restart iotedge`
193+
* IoT Edge for Linux on Windows: `sudo systemctl restart iotedge`
194+
123195
:::moniker-end
124196
<!-- end 1.1 -->
125197

126198
<!-- iotedge-2020-11 -->
127199
:::moniker range=">=iotedge-2020-11"
128200

129-
1. On your IoT Edge device, open the config file: `/etc/aziot/config.toml`
201+
1. On your IoT Edge device, open the config file: `/etc/aziot/config.toml`. If you're using IoT Edge for Linux on Windows, you'll have to connect to the EFLOW virtual machine using the `Connect-EflowVm` PowerShell cmdlet.
130202

131203
>[!TIP]
132204
>If the config file doesn't exist on your device yet, then use `/etc/aziot/config.toml.edge.template` as a template to create one.
@@ -194,14 +266,43 @@ To deploy the IoT Edge hub module and configure it with routes to handle incomin
194266

195267
Standard IoT Edge devices don't need any inbound connectivity to function, because all communication with IoT Hub is done through outbound connections. Gateway devices are different because they need to receive messages from their downstream devices. If a firewall is between the downstream devices and the gateway device, then communication needs to be possible through the firewall as well.
196268

197-
For a gateway scenario to work, at least one of the IoT Edge hub's supported protocols must be open for inbound traffic from downstream devices. The supported protocols are MQTT, AMQP, HTTPS, MQTT over WebSockets, and AMQP over WebSockets.
269+
# [IoT Edge](#tab/iotedge)
270+
271+
For a gateway scenario to work, at least one of the IoT Edge Hub's supported protocols must be open for inbound traffic from downstream devices. The supported protocols are MQTT, AMQP, HTTPS, MQTT over WebSockets, and AMQP over WebSockets.
198272

199273
| Port | Protocol |
200274
| ---- | -------- |
201275
| 8883 | MQTT |
202276
| 5671 | AMQP |
203277
| 443 | HTTPS <br> MQTT+WS <br> AMQP+WS |
204278

279+
# [IoT Edge for Linux on Windows](#tab/eflow)
280+
281+
For a gateway scenario to work, at least one of the IoT Edge Hub's supported protocols must be open for inbound traffic from downstream devices. The supported protocols are MQTT, AMQP, HTTPS, MQTT over WebSockets, and AMQP over WebSockets.
282+
283+
| Port | Protocol |
284+
| ---- | -------- |
285+
| 8883 | MQTT |
286+
| 5671 | AMQP |
287+
| 443 | HTTPS <br> MQTT+WS <br> AMQP+WS |
288+
289+
Finally, you must open the EFLOW virtual machine ports. You can open the three ports mentioned above using the following PowerShell cmdlets.
290+
291+
```powershell
292+
# Open MQTT port
293+
Invoke-EflowVmCommand "sudo iptables -A INPUT -p tcp --dport 8883 -j ACCEPT"
294+
295+
# Open AMQP port
296+
Invoke-EflowVmCommand "sudo iptables -A INPUT -p tcp --dport 5671 -j ACCEPT"
297+
298+
# Open HTTPS/MQTT+WS/AMQP+WS port
299+
Invoke-EflowVmCommand "sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT"
300+
301+
# Save the iptables rules
302+
Invoke-EflowVmCommand "sudo iptables-save | sudo tee /etc/systemd/scripts/ip4save"
303+
```
304+
---
305+
205306
## Next steps
206307

207308
Now that you have an IoT Edge device set up as a transparent gateway, you need to configure your downstream devices to trust the gateway and send messages to it. Continue on to [Authenticate a downstream device to Azure IoT Hub](how-to-authenticate-downstream-device.md) for the next steps in setting up your transparent gateway scenario.

0 commit comments

Comments
 (0)