Skip to content

Commit a0f9149

Browse files
authored
Merge pull request #46 from microsoft/djong1-fix-eventgrid-mqtt-enhanced-auth
Authenticate to Event Grid MQTT with enhanced authentication
2 parents 2a9773e + 37d6f17 commit a0f9149

4 files changed

Lines changed: 477 additions & 90 deletions

File tree

‎radius/README.md‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,43 @@ rad group delete trading
350350

351351
---
352352

353+
## Choosing an MQTT broker recipe
354+
355+
`Radius.Resources/mqttBrokers` has two recipes, and the containers adapt to
356+
whichever one the environment registers — `MQTT_AUTH_METHOD` and
357+
`MQTT_TOKEN_AUDIENCE` are wired from `tradingMqtt.properties.*`, so the broker
358+
answers for itself.
359+
360+
| | `kubernetes-mosquitto.bicep` | `azure-event-grid.bicep` |
361+
|---|---|---|
362+
| `authMethod` | `none` | `OAUTH2-JWT` |
363+
| Transport | MQTT 1883 / WS 9001 | MQTTS 8883 / WSS 443 |
364+
| Backend order processing | ✅ | ✅ |
365+
| Browser live order stream | ✅ | ❌ |
366+
367+
**Event Grid requires MQTT v5 enhanced authentication.** The backend sends the
368+
Microsoft Entra token in the CONNECT *Authentication Data* property with
369+
*Authentication Method* `OAUTH2-JWT`, and uses the token's `oid` claim as the
370+
MQTT client identifier — Event Grid matches it against the authenticating
371+
principal. It re-authenticates with an `AUTH` packet (reason code 25) before the
372+
token expires. Event Grid never reads the CONNECT password field; see
373+
[Microsoft Entra JWT authentication and Azure RBAC](https://learn.microsoft.com/azure/event-grid/mqtt-client-microsoft-entra-token-and-rbac).
374+
375+
Set `MQTT_CLIENT_ID` on the container to override the derived client identifier.
376+
377+
**The browser has no Event Grid path.** `src/frontend/public/index.html` connects
378+
to `MQTT_WS_URL` with the `mqtt.js` client and no credentials. Selecting the
379+
Event Grid recipe therefore gives you server-side order processing but no
380+
browser-side live streaming.
381+
382+
**Deleting the app does not delete the namespace.** `azure-event-grid.bicep`
383+
returns `resources: []`, so Radius does not track the Event Grid namespace it
384+
created. `rad app delete`, or switching to another recipe, leaves it running and
385+
billing — delete it with
386+
`az eventgrid namespace delete --name <namespace> --resource-group <rg>`.
387+
388+
---
389+
353390
## Troubleshooting
354391

355392
**Recipe not found during deploy**
@@ -388,6 +425,17 @@ ready", this is likely the Kaito v0.9.0 node estimator bug (it ignores
388425
inflating the `nvidia.com/gpu.memory` node label — see the
389426
[root README known issues](../README.md#5-known-issues-kaito-v090) for details.
390427

428+
**Backend cannot connect to the MQTT broker**
429+
The backend logs the CONNECT result and retries with exponential backoff instead
430+
of terminating; the REST API stays available while order streaming is degraded.
431+
```bash
432+
kubectl logs -n <namespace> -l radapp.io/resource=backend --tail=50 | grep MQTT
433+
```
434+
Against Event Grid, `NotAuthorized` usually means the identity lacks the
435+
`EventGrid TopicSpaces Publisher`/`Subscriber` role on the topic space, or the
436+
CONNECT client identifier does not match the principal's object ID (the backend
437+
derives it from the token's `oid` claim — override with `MQTT_CLIENT_ID`).
438+
391439
**Bicep type errors**
392440
Make sure `types.tgz` has been generated (Step 3) and is present in the `radius/`
393441
directory alongside `bicepconfig.json`.

‎radius/app.bicep‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,16 @@ resource backend 'Applications.Core/containers@2023-10-01-preview' = {
483483
// Only secrets and non-connection values require explicit wiring.
484484
CONNECTION_DB_SECRETS_PASSWORD: { value: tradingDb.properties.secrets.password }
485485
AZURE_CLIENT_ID: { value: backendIdentity.properties.clientId }
486-
AZURE_TENANT_ID: { value: workloadIdentityTenantId }
487-
MQTT_AUTH_METHOD: { value: backendIdentity.properties.authMethod }
488-
MQTT_TOKEN_AUDIENCE: { value: backendIdentity.properties.tokenAudience }
486+
// The tenant comes from the workload-identity recipe; the parameter is
487+
// only an override. Wiring the parameter directly left it empty, which
488+
// also stopped WorkloadIdentityCredential from ever being selected.
489+
AZURE_TENANT_ID: { value: empty(workloadIdentityTenantId) ? backendIdentity.properties.tenantId : workloadIdentityTenantId }
490+
// The broker — not the identity — decides how clients authenticate, so
491+
// these must come from the mqttBrokers resource. Reading them from the
492+
// workload identity would force token auth even when the environment
493+
// registered the Mosquitto recipe.
494+
MQTT_AUTH_METHOD: { value: tradingMqtt.properties.authMethod }
495+
MQTT_TOKEN_AUDIENCE: { value: tradingMqtt.properties.tokenAudience }
489496
MQTT_TOPIC: { value: 'orders/new' }
490497
}
491498
}
@@ -521,9 +528,11 @@ resource frontend 'Applications.Core/containers@2023-10-01-preview' = {
521528
AI_AGENT_URL: { value: 'http://ai-agent:7000' }
522529
MQTT_WS_URL: { value: '${tradingMqtt.properties.wsPort == 443 ? 'wss' : 'ws'}://${tradingMqtt.properties.host}:${tradingMqtt.properties.wsPort}' }
523530
AZURE_CLIENT_ID: { value: frontendIdentity.properties.clientId }
524-
AZURE_TENANT_ID: { value: workloadIdentityTenantId }
525-
MQTT_AUTH_METHOD: { value: frontendIdentity.properties.authMethod }
526-
MQTT_TOKEN_AUDIENCE: { value: frontendIdentity.properties.tokenAudience }
531+
AZURE_TENANT_ID: { value: empty(workloadIdentityTenantId) ? frontendIdentity.properties.tenantId : workloadIdentityTenantId }
532+
// See the note on the backend container: the broker recipe answers for
533+
// its own authentication method.
534+
MQTT_AUTH_METHOD: { value: tradingMqtt.properties.authMethod }
535+
MQTT_TOKEN_AUDIENCE: { value: tradingMqtt.properties.tokenAudience }
527536
// OIDC values provided as parameters (from helm-deployed portfolio or external provider).
528537
OIDC_ISSUER: { value: effectiveOidcIssuer }
529538
OIDC_AUTH_ENDPOINT: { value: effectiveOidcAuthEndpoint }

‎radius/recipes/mqtt/azure-event-grid.bicep‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,21 @@
66
// resource type contract.
77
//
88
// Notes:
9-
// - Event Grid MQTT requires TLS and authenticated clients.
9+
// - Event Grid MQTT requires TLS and authenticated clients. Clients must use
10+
// MQTT v5 and present a Microsoft Entra token through enhanced authentication
11+
// (Authentication Method `OAUTH2-JWT`), with the CONNECT client identifier set
12+
// to the object ID of the authenticating principal.
13+
// https://learn.microsoft.com/azure/event-grid/mqtt-client-microsoft-entra-token-and-rbac
14+
// - Only the `backend` container speaks this dialect. The browser client in
15+
// `src/frontend/public/index.html` connects to `MQTT_WS_URL` without
16+
// credentials, so selecting this recipe gives you server-side order
17+
// processing but no browser-side live streaming.
1018
// - This recipe intentionally focuses on broker endpoint provisioning.
19+
// - Billing warning: `result.resources` is intentionally empty (see below), so
20+
// Radius does not track the namespace it created. `rad app delete` or a
21+
// switch to another mqttBrokers recipe leaves the Event Grid namespace
22+
// running and billing. Delete it manually:
23+
// az eventgrid namespace delete --name <namespace> --resource-group <rg>
1124

1225
@description('Information about what resource is calling this Recipe. Generated by Radius. For more information visit https://docs.radapp.io/reference/context-schema/')
1326
param context object

0 commit comments

Comments
 (0)