Skip to content

Commit e71c548

Browse files
committed
Warn about port conflicts, default listener, service name
1 parent fbaed86 commit e71c548

File tree

3 files changed

+170
-44
lines changed

3 files changed

+170
-44
lines changed

articles/iot-operations/manage-mqtt-broker/howto-configure-brokerlistener.md

Lines changed: 169 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.subservice: azure-mqtt-broker
88
ms.topic: how-to
99
ms.custom:
1010
- ignite-2023
11-
ms.date: 10/30/2024
11+
ms.date: 11/06/2024
1212

1313
#CustomerIntent: As an operator, I want understand options to secure MQTT communications for my IoT Operations solution.
1414
---
@@ -20,7 +20,7 @@ To customize the network access and security use the *BrokerListener* resource.
2020
Each listener port can have its own authentication and authorization rules that define who can connect to the listener and what actions they can perform on the broker. You can use *BrokerAuthentication* and *BrokerAuthorization* resources to specify the access control policies for each listener. This flexibility allows you to fine-tune the permissions and roles of your MQTT clients, based on their needs and use cases.
2121

2222
> [!TIP]
23-
> You can only access the default MQTT broker deployment by using the cluster IP, TLS, and a service account token. Clients connecting from outside the cluster need extra configuration before they can connect.
23+
> You can only access the default MQTT broker deployment by using the cluster IP, TLS, and a service account token. Clients connecting from outside the cluster [need extra configuration](./howto-test-connection.md) before they can connect.
2424
2525
Listeners have the following characteristics:
2626

@@ -35,9 +35,12 @@ For a list of the available settings, see the [Broker Listener](/rest/api/iotope
3535

3636
## Default BrokerListener
3737

38-
When you deploy Azure IoT Operations, the deployment also creates a *BrokerListener* resource named `default` in the `azure-iot-operations` namespace. This listener is linked to the default *Broker* resource named `default` that's also created during deployment. The default listener exposes the broker on port 18883 with TLS and SAT authentication enabled. The TLS certificate is [automatically managed](#configure-tls-with-automatic-certificate-management) by cert-manager. Authorization is disabled by default.
38+
When you deploy Azure IoT Operations, the deployment also creates a *BrokerListener* resource named `default`. This listener is used to for encrypted internal communication between Azure IoT Operations components. The default listener is part of the [default *Broker*](./overview-broker.md#default-broker-resource), exposes a [ClusterIp service](https://kubernetes.io/docs/concepts/services-networking/service/#type-clusterip) on port 18883, uses [Kubernetes service account authentication](./howto-configure-authentication.md#enable-service-account-token-sat-authentication), has an [automatically managed](#configure-tls-with-automatic-certificate-management) TLS certificate, and doesn't use any authorization.
3939

40-
To view or edit the listener:
40+
> [!CAUTION]
41+
> To avoid disrupting internal Azure IoT Operations communication, keep the default listener unchanged and dedicated for internal use. For external communication, [create a new listener](#create-new-broker-listeners). If you need to use the ClusterIp service, add more ports to the default listener without changing any of the existing settings.
42+
43+
To view or edit the default listener:
4144

4245
# [Portal](#tab/portal)
4346

@@ -50,11 +53,72 @@ To view or edit the listener:
5053

5154
:::image type="content" source="media/howto-configure-brokerlistener/default-broker-listener.png" alt-text="Screenshot using Azure portal to view or edit the default broker listener.":::
5255

53-
1. Review the listener settings and make any changes as needed.
56+
1. Review the listener settings, but avoid modifying any of the existing settings. Instead, create a new port and configure it as needed.
5457

5558
# [Bicep](#tab/bicep)
5659

57-
You shouldn't modify the default listener using Bicep. Instead, create a new listener and configure it as needed.
60+
You shouldn't modify the default listener using Bicep.
61+
62+
```bicep
63+
param aioInstanceName string = '<AIO_INSTANCE_NAME>'
64+
param customLocationName string = '<CUSTOM_LOCATION_NAME>'
65+
66+
resource aioInstance 'Microsoft.IoTOperations/instances@2024-09-15-preview' existing = {
67+
name: aioInstanceName
68+
}
69+
70+
resource customLocation 'Microsoft.ExtendedLocation/customLocations@2021-08-31-preview' existing = {
71+
name: customLocationName
72+
}
73+
74+
resource defaultBroker 'Microsoft.IoTOperations/instances/brokers@2024-09-15-preview' existing = {
75+
parent: aioInstance
76+
name: 'default'
77+
}
78+
79+
resource nodePortListener 'Microsoft.IoTOperations/instances/brokers/listeners@2024-09-15-preview' = {
80+
parent: defaultBroker
81+
name: 'default'
82+
extendedLocation: {
83+
name: customLocation.id
84+
type: 'CustomLocation'
85+
}
86+
properties: {
87+
// Don't change the service name or service type
88+
serviceType: 'ClusterIp'
89+
serviceName: 'aio-broker'
90+
ports: [
91+
// Don't modify the default port 18883 settings
92+
{
93+
port: 18883
94+
authenticationRef: 'default'
95+
protocol: 'Mqtt'
96+
tls: {
97+
mode: 'Automatic'
98+
certManagerCertificateSpec: {
99+
issuerRef: {
100+
name: 'azure-iot-operations-aio-certificate-issuer'
101+
kind: 'ClusterIssuer'
102+
group: 'cert-manager.io'
103+
}
104+
privateKey: {
105+
algorithm: 'Ec256'
106+
rotationPolicy: 'Always'
107+
}
108+
}
109+
}
110+
}
111+
// Add more ports here
112+
]
113+
}
114+
}
115+
```
116+
117+
Deploy the Bicep file using Azure CLI.
118+
119+
```azurecli
120+
az deployment group create --resource-group <RESOURCE_GROUP> --template-file <FILE>.bicep
121+
```
58122

59123
# [Kubernetes](#tab/kubernetes)
60124

@@ -67,26 +131,32 @@ kubectl get brokerlistener default -n azure-iot-operations -o yaml
67131
The output should look similar to this, with most metadata removed for brevity:
68132

69133
```yaml
70-
apiVersion: mqttbroker.iotoperations.azure.com/v1beta1
134+
apiVersion: mqttbroker.iotoperations.azure.com/v1beta2
71135
kind: BrokerListener
72136
metadata:
73137
name: default
74138
namespace: azure-iot-operations
139+
ownerReferences:
140+
- apiVersion: mqttbroker.iotoperations.azure.com/v1beta2
141+
kind: Broker
142+
name: default
75143
spec:
76-
brokerRef: default
77-
serviceName: aio-broker
78144
serviceType: ClusterIp
145+
serviceName: aio-broker
79146
ports:
80-
- authenticationRef: default
81-
port: 18883
147+
- port: 18883
148+
authenticationRef: default
82149
protocol: Mqtt
83150
tls:
151+
mode: Automatic
84152
certManagerCertificateSpec:
85153
issuerRef:
154+
name: azure-iot-operations-aio-certificate-issuer
155+
kind: ClusterIssuer
86156
group: cert-manager.io
87-
kind: Issuer
88-
name: mq-dmqtt-frontend
89-
mode: Automatic
157+
privateKey:
158+
algorithm: Ec256
159+
rotationPolicy: Always
90160
```
91161
92162
To learn more about the default BrokerAuthentication resource linked to this listener, see [Default BrokerAuthentication resource](howto-configure-authentication.md#default-brokerauthentication-resource).
@@ -96,37 +166,72 @@ To learn more about the default BrokerAuthentication resource linked to this lis
96166
The default *BrokerListener* uses the service type *ClusterIp*. You can have only one listener per service type. If you want to add more ports to service type *ClusterIp*, you can update the default listener to add more ports. For example, you could add a new port 1883 with no TLS and authentication off with the following kubectl patch command:
97167
98168
```bash
99-
kubectl patch brokerlistener default -n azure-iot-operations --type='json' -p='[{"op": "add", "path": "/spec/ports/", "value": {"port": 1883, "protocol": "Mqtt"}}]'
169+
kubectl patch brokerlistener default -n azure-iot-operations --type='json' -p='[{"op": "add", "path": "/spec/ports/-", "value": {"port": 1883, "protocol": "Mqtt"}}]'
100170
```
101171
102172
---
103173
104174
## Create new broker listeners
105175
106-
This example shows how to create a new *BrokerListener* resource named *loadbalancer-listener* for a *Broker* resource. The *BrokerListener* resource defines a two ports that accept MQTT connections from clients.
176+
To create a new listener, you need to specify the following settings:
177+
178+
- **Name**: Name of the *BrokerListener* resource. The name must be unique within the namespace.
179+
- **Service name**: Name of the Kubernetes service that exposes the broker. If left empty, the listener name is used as the service name.
180+
- **Service type**: Type of the Kubernetes service. Can be `LoadBalancer`, `ClusterIp`, or `NodePort`.
181+
- **Ports**: List of ports that the listener listens on. Each port can have its own authentication, authorization, and TLS settings.
182+
- To use your own authentication or authorization setting for a port, you must create the corresponding resources before creating the *BrokerListener* resource. For more information, see [Configure MQTT broker authentication](howto-configure-authentication.md) and [Configure MQTT broker authorization](howto-configure-authorization.md).
183+
- To use TLS, see [Configure TLS with automatic certificate management](#configure-tls-with-automatic-certificate-management) or [Configure TLS with manual certificate management](#configure-tls-with-manual-certificate-management) sections.
184+
185+
This example shows how to create a new listener with load balancer service type. The *BrokerListener* resource defines a two ports that accept MQTT connections from clients.
107186

108-
- The first port listens on port 1883 with no TLS and authentication off. Clients can connect to the broker without encryption or authentication.
109-
- The second port listens on port 18883 with TLS and authentication enabled. Only authenticated clients can connect to the broker with TLS encryption. TLS is set to `automatic`, which means that the listener uses cert-manager to get and renew its server certificate.
187+
- The first port listens on port 1883 without TLS and authentication. Clients can connect to the broker without encryption or authentication. This setup is suitable for testing only. [Don't use this configuration in production](./howto-test-connection.md#only-turn-off-tls-and-authentication-for-testing).
188+
- The second port listens on port 8883 with TLS and authentication enabled. Only [authenticated clients with a Kubernetes service account token](./howto-configure-authentication.md#default-brokerauthentication-resource) can connect. TLS is set to [automatic mode](#enable-tls-automatic-certificate-management-for-a-port), using cert-manager to manage the server certificate from the [default issuer](../secure-iot-ops/concept-default-root-ca.md#default-self-signed-issuer-and-root-ca-certificate-for-tls-server-certificates). This setup is closer to a production configuration.
110189

111190
# [Portal](#tab/portal)
112191

113192
1. In the Azure portal, navigate to your IoT Operations instance.
114193
1. Under **Azure IoT Operations resources**, select **MQTT Broker**.
115-
1. Select **MQTT broker listener for LoadBalancer** > **Create**. You can only create one listener per service type. If you already have a listener of the same service type, you can add more ports to the existing listener.
116-
117-
:::image type="content" source="media/howto-configure-brokerlistener/create-loadbalancer.png" alt-text="Screenshot using Azure portal to create MQTT broker for load balancer listener.":::
194+
1. Select **MQTT broker listener for LoadBalancer** > **Create**.
118195

119196
Enter the following settings:
120197

121198
| Setting | Description |
122199
| -------------- | --------------------------------------------------------------------------------------------- |
123200
| Name | Name of the BrokerListener resource. |
124-
| Service name | Name of the Kubernetes service associated with the BrokerListener. |
125-
| Service type | Type of broker service, such as *LoadBalancer*, *NodePort*, or *ClusterIP*. |
126-
| Port | Port number on which the BrokerListener listens for MQTT connections. |
127-
| Authentication | The [authentication resource reference](howto-configure-authentication.md). |
128-
| Authorization | The [authorization resource reference](howto-configure-authorization.md). |
129-
| TLS | Indicates whether TLS is enabled for secure communication. Can be set to [automatic](#configure-tls-with-automatic-certificate-management) or [manual](#configure-tls-with-manual-certificate-management). |
201+
| Service name | Name of the Kubernetes service. Leave empty to use the listener name as service name. |
202+
| Service type | **LoadBalancer** already selected. |
203+
204+
1. Under **Ports**, enter the following settings for the first port:
205+
206+
| Setting | Description |
207+
| -------------- | --------------------- |
208+
| Port | Enter 1883 |
209+
| Authentication | Choose **None** |
210+
| Authorization | Choose **None** |
211+
| Protocol | Choose **MQTT** |
212+
| TLS | Don't add |
213+
214+
1. Select **Add port entry** to add a second port and enter the following settings:
215+
216+
| Setting | Description |
217+
| -------------- | --------------------- |
218+
| Port | Enter 8883 |
219+
| Authentication | Choose **default** |
220+
| Authorization | Choose **None** |
221+
| Protocol | Choose **MQTT** |
222+
| TLS | Select **Add** |
223+
224+
1. In the **TLS configuration** pane, enter the following settings:
225+
226+
| Setting | Description |
227+
| -------------- | --------------------- |
228+
| TLS Mode | Choose **Automatic** |
229+
| Issuer name | Enter `azure-iot-operations-aio-certificate-issuer` |
230+
| Issuer kind | Choose **ClusterIssuer** |
231+
232+
Leave other settings as default, and select **Apply**.
233+
234+
:::image type="content" source="media/howto-configure-brokerlistener/create-loadbalancer.png" alt-text="Screenshot using Azure portal to create MQTT broker for load balancer listener.":::
130235

131236
1. Select **Create listener**.
132237

@@ -135,7 +240,6 @@ This example shows how to create a new *BrokerListener* resource named *loadbala
135240
```bicep
136241
param aioInstanceName string = '<AIO_INSTANCE_NAME>'
137242
param customLocationName string = '<CUSTOM_LOCATION_NAME>'
138-
param listenerServiceName string = '<LISTENER_SERVICE_NAME>'
139243
param listenerName string = '<LISTENER_NAME>'
140244
141245
resource aioInstance 'Microsoft.IoTOperations/instances@2024-09-15-preview' existing = {
@@ -160,22 +264,25 @@ resource loadBalancerListener 'Microsoft.IoTOperations/instances/brokers/listene
160264
}
161265
162266
properties: {
163-
serviceName: listenerServiceName
164267
serviceType: 'LoadBalancer'
165268
ports: [
269+
{
270+
port: 1883
271+
protocol: 'Mqtt'
272+
}
166273
{
167274
authenticationRef: 'default'
168-
port: 18883
275+
port: 8883
169276
protocol: 'Mqtt'
170277
tls: {
278+
mode: 'Automatic'
171279
certManagerCertificateSpec: {
172280
issuerRef: {
281+
name: 'azure-iot-operations-aio-certificate-issuer'
282+
kind: 'ClusterIssuer'
173283
group: 'cert-manager.io'
174-
kind: 'Issuer'
175-
name: 'mq-dmqtt-frontend'
176284
}
177285
}
178-
mode: 'Automatic'
179286
}
180287
}
181288
]
@@ -191,37 +298,57 @@ az deployment group create --resource-group <RESOURCE_GROUP> --template-file <FI
191298

192299
# [Kubernetes](#tab/kubernetes)
193300

194-
To create these *BrokerListener* resources, apply this YAML manifest to your Kubernetes cluster:
195-
196301
```yaml
197302
apiVersion: mqttbroker.iotoperations.azure.com/v1beta1
198303
kind: BrokerListener
199304
metadata:
200-
name: loadbalancer-listener
305+
name: <LISTENER_NAME>
201306
namespace: azure-iot-operations
202307
spec:
203308
brokerRef: default
204309
serviceType: LoadBalancer
205-
serviceName: aio-broker-loadbalancer
206310
ports:
207311
- port: 1883
208312
protocol: Mqtt
209-
- port: 18883
313+
- port: 8883
210314
authenticationRef: default
211315
protocol: Mqtt
212316
tls:
213317
mode: Automatic
214318
certManagerCertificateSpec:
215319
issuerRef:
216-
name: e2e-cert-issuer
217-
kind: Issuer
320+
name: azure-iot-operations-aio-certificate-issuer
321+
kind: ClusterIssuer
218322
group: cert-manager.io
219323
```
220324

221-
For more information about authentication, see [Configure MQTT broker authentication](howto-configure-authentication.md). For more information about authorization, see [Configure MQTT broker authorization](howto-configure-authorization.md). For more information about TLS, see [Configure TLS with automatic certificate management](#configure-tls-with-automatic-certificate-management) or [Configure TLS with manual certificate management](#configure-tls-with-manual-certificate-management) sections.
222-
223325
---
224326

327+
## Service type
328+
329+
Each BrokerListener maps to a [Kubernetes service](https://kubernetes.io/docs/concepts/services-networking/service/).. The service type determines how the broker is exposed to the network. The three service types are:
330+
331+
- **ClusterIp**: Exposes the broker on a cluster-internal IP. Clients can connect to the broker from within the cluster. This is the default service type for the default listener.
332+
- **NodePort**: Exposes the broker on each node's IP at a static port. Clients can connect to the broker from outside the cluster. This service type is useful for development and testing.
333+
- **LoadBalancer**: Exposes the broker externally. The service is assigned an external IP address that clients can use to connect to the broker. This is the most common service type for production deployments.
334+
335+
Only one listener per service type is allowed. If you need more connectivity of the same service type, add more ports to the existing listener.
336+
337+
## Service name
338+
339+
The service name is the name of the Kubernetes service that exposes the broker. If left empty, the broker listener name is used as the service name. The service name must be unique within the namespace.
340+
341+
> [!TIP]
342+
> To prevent management overhead, we recommend leaving the service name empty. The listener name is unique and can be used to identify the service. Use the service name as an override only when you can't name the service after the listener.
343+
344+
## Ports
345+
346+
Each listener can have multiple ports, but each port number must be unique within the Azure IoT Operations MQTT broker. For example, if you have a NodePort listener using port 1883, you can't create another LoadBalancer listener with port 1883. Similarly, the default listener uses port 18883, so you can't create another listener with port 18883.
347+
348+
## WebSockets support
349+
350+
Azure IoT Operations MQTT broker supports MQTT over WebSockets. To enable WebSockets, set the protocol to `WebSockets` in the port settings.
351+
225352
## Configure TLS with automatic certificate management
226353

227354
To enable TLS with automatic certificate management, specify the TLS settings on a listener port.

articles/iot-operations/manage-mqtt-broker/howto-test-connection.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.subservice: azure-mqtt-broker
77
ms.topic: how-to
88
ms.custom:
99
- ignite-2023
10-
ms.date: 10/30/2024
10+
ms.date: 11/06/2024
1111

1212
#CustomerIntent: As an operator or developer, I want to test MQTT connectivity with tools that I'm already familiar with to know that I set up my MQTT broker correctly.
1313
ms.service: azure-iot-operations
@@ -218,7 +218,6 @@ resource nodePortListener 'Microsoft.IoTOperations/instances/brokers/listeners@2
218218
]
219219
}
220220
}
221-
222221
```
223222

224223
Deploy the Bicep file using Azure CLI.
12.1 KB
Loading

0 commit comments

Comments
 (0)