You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/iot-operations/manage-mqtt-broker/howto-test-connection.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -446,13 +446,16 @@ If the external IP is not assigned, you might need to use port forwarding or a v
446
446
447
447
With [minikube](https://minikube.sigs.k8s.io/docs/), [kind](https://kind.sigs.k8s.io/), and other cluster emulation systems, an external IP might not be automatically assigned. For example, it might show as *Pending* state.
448
448
449
-
1. To access the broker, forward the broker listening port 18883 to the host.
449
+
1. To access the broker, forward the broker listener port to the host.
1. Use 127.0.0.1 to connect to the broker at port 18883 with the same authentication and TLS configuration as the example without port forwarding.
456
+
1. Leave the port forwarding command running in the terminal.
457
+
458
+
1. Connect to the broker at the host port with the same authentication and TLS configuration as the example without port forwarding.
456
459
457
460
For more information about minikube, see [Use Port Forwarding to Access Applications in a Cluster](https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/)
Copy file name to clipboardExpand all lines: articles/iot-operations/manage-mqtt-broker/tutorial-tls-x509.md
+47-29Lines changed: 47 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,21 +27,48 @@ The tutorial simulates an environment where Azure IoT Operations is installed in
27
27
28
28
To follow this tutorial, you need:
29
29
30
+
- A Kubernetes cluster with port forwarding enabled for port 8883.
30
31
- Azure IoT Operations deployed without an existing load balancer listener.
31
-
- A Kubernetes cluster with port forwarding enabled for port 8883, allowing localhost access to the broker listener.
32
32
- Kubectl access to the cluster to create Kubernetes secrets and config maps.
33
+
-[Mosquitto client](https://mosquitto.org/download/) to publish and subscribe to MQTT messages running on the same machine as the Kubernetes cluster for `localhost` access. To not use `localhost`, see [Optional: Use a real hostname or IP address instead of `localhost`](#optional-use-a-real-hostname-or-ip-address-instead-of-localhost) section.
33
34
-[Step CLI](https://smallstep.com/docs/step-cli/) to create certificates.
34
-
-[Mosquitto client](https://mosquitto.org/download/) to publish and subscribe to MQTT messages.
35
35
36
-
We recommend using the [quickstart codespace](../get-started-end-to-end-sample/quickstart-deploy.md), which already meets all these requirements. The quickstart codespace simplifies the setup process by providing these components out of the box.
36
+
> [!TIP]
37
+
> To meet these requirements, use the [quickstart codespace](../get-started-end-to-end-sample/quickstart-deploy.md). The quickstart codespace simplifies the setup process by providing these components out of the box.
37
38
38
39
Additionally, familiarity with public key cryptography and terms like root CA, private key, and intermediate certificates is useful.
39
40
41
+
### Optional: Use a real hostname or IP address instead of `localhost`
42
+
43
+
To keep this tutorial simple, we use `localhost` to access the MQTT broker. This approach ensures that the broker's server certificate has a Subject Alternative Name (SAN) that matches the hostname used to access the broker. Using `localhost` simplifies the setup since the SAN is already set correctly.
44
+
45
+
In a real-world scenario, you'd use the hostname or external IP of the broker instead of `localhost` and connect to it from another device on the network. In this case, you need to determine the correct hostname or IP address and use it as the SAN when creating the server certificate:
46
+
47
+
- If the hostname or IP address is already known (for example, through a DNS record or static IP), use it as the SAN when creating the server certificate. Then, connect to the broker using that hostname or IP instead of `localhost`.
48
+
- If the hostname or IP address isn't already known, you can use a placeholder service to determine the external IP address:
49
+
1. Create the LoadBalancer service on a port that's not being used (like 8080):
50
+
```sh
51
+
kubectl create service loadbalancer placeholder-service --tcp=8080:8080
52
+
```
53
+
1. Retrieve the external IP:
54
+
```sh
55
+
kubectl get svc placeholder-service
56
+
```
57
+
1. If the external IP:
58
+
- Shows a value like `192.168.X.X` - use that IP as the SAN when creating the server certificate and secret. Then, connect to the broker using that IP instead of `localhost`.
59
+
- Shows `<pending>` - the Kubernetes distribution you use might not support automatically assigning an external IP. To find the external IP, follow the steps in the Kubernetes documentation for your distribution and host environment. You might also need to configure [port forwarding](./howto-test-connection.md#use-port-forwarding) or a VPN depending on the network setup.
60
+
1. After determining the external IP, delete the placeholder service:
61
+
```sh
62
+
kubectl delete svc placeholder-service
63
+
```
64
+
65
+
This method ensures that the server certificate matches the external IP address, allowing secure access to the MQTT broker.
66
+
40
67
## Prepare server-side certificates and full chain
41
68
42
69
First, create a server-side root CA. This CA is separate from the client-side root CA which is created later. To keep the separation clear, we name everything server side "Contoso". To make later steps easier, we skip the password forencrypting the private key. This practice is only acceptablein a tutorial setting.
Lastly, use this intermediate CA to sign a server certificate for MQTT broker's broker frontend. Here, `localhost` is the Subject Alternative Name (SAN) used for the tutorial.
With the `--bundle` flag, the server certificate is bundled with the signing intermediate certificate. TLS handshake requires the bundle to verify the full chain.
74
101
75
-
> [!TIP]
76
-
> To simplify the tutorial, we use `localhost` as the Subject Alternative Name (SAN).
77
-
>
78
-
> If you don't have localhost port forwarding set up, [create the listener](#listener) first. Then, retrieve the external IP using `kubectl get service mqtts-endpoint -n azure-iot-operations`, and use that IP as the SAN when creating the server certificate and the secret. The broker waits for the secret to be created before fully starting the listener, so the order of operations is flexible.
79
-
80
102
## Prepare client-side certificates and full chain
81
103
82
104
Similarly, create the root CA for Fabrikam and the intermediate CA.
Import the newly generated server certificate and private key into a Kubernetes secret. This secret is used to configure a TLS listener for MQTT broker later.
Also, create a config map to contain the Fabrikam (client-side) root CA. This config map is required for MQTT broker to trust it for X.509 authentication.
Instead of using the external IP, we use `localhost` for the tutorial.
230
252
231
253
> [!TIP]
232
-
> The codespace configuration automatically sets up port forwarding for 8883. To setup other environments, use `kubectl port-forward` to forward the port.
> The codespace configuration automatically sets up port forwarding for 8883. To setup other environments, see [Use port forwarding](./howto-test-connection.md#use-port-forwarding).
237
255
238
256
## Use a single Mosquito client to publish messages over TLS
239
257
240
258
From the same folder as the certificate files: `contoso_root_ca.crt`, `thermostat.crt`, and `thermostat.key`, use Mosquito client to publish a message. The `--cafile contoso_root_ca.crt` flag is for Mosquito to perform server certificate verification.
241
259
242
-
```bash
260
+
```sh
243
261
mosquitto_pub -t "example/topic" -m "example temperature measurement" -i thermostat \
244
262
-q 1 -V mqttv5 -d \
245
263
-h localhost \
@@ -372,7 +390,7 @@ In this section, we test out the newly applied authorization policies.
372
390
373
391
First, connect with `thermostat` and try to publish on topic `telemetry/humidity`:
374
392
375
-
```bash
393
+
```sh
376
394
mosquitto_pub -t "telemetry/humidity" -m "example temperature measurement" -i thermostat \
377
395
-q 1 -V mqttv5 -d \
378
396
-h localhost \
@@ -393,7 +411,7 @@ Warning: Publish 1 failed: Not authorized.
393
411
394
412
Change to publish to `telemetry/temperature`, which is allowed and the publish succeeds. Leave the command running.
395
413
396
-
```bash
414
+
```sh
397
415
mosquitto_pub -t "telemetry/temperature" -m "example temperature measurement" -i thermostat \
0 commit comments