Skip to content

Commit 1ec4afd

Browse files
authored
Merge pull request #313441 from EldertGrootenboer/docs/disable-local-auth-expansion
docs: expand disable-local-authentication guide for Service Bus
2 parents 8929791 + f9965b1 commit 1ec4afd

1 file changed

Lines changed: 206 additions & 10 deletions

File tree

articles/service-bus-messaging/disable-local-authentication.md

Lines changed: 206 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
11
---
22
title: Disable local authentication with Azure Service Bus
3-
description: This article explains how to disable local or Shared Access Signature key authentication for a Service Bus namespace.
3+
description: This article explains how to disable local or Shared Access Signature key authentication for a Service Bus namespace and use only Microsoft Entra ID.
44
ms.topic: how-to
5-
ms.date: 07/25/2024
5+
ms.date: 03/19/2026
66
ms.custom: sfi-image-nochange
77
#customer intent: As a developer or IT administrator, I want to know how to disable shared access key authentication and use only the Microsoft Entra ID authentication for higher security.
88
---
99

1010
# Disable local or shared access key authentication with Azure Service Bus
11-
There are two ways to authenticate to Azure Service Bus resources:
11+
You can authenticate to Azure Service Bus resources in two ways:
1212

1313
- Microsoft Entra ID
1414
- Shared Access Signatures (SAS)
1515

16-
Microsoft Entra ID provides superior security and ease of use over shared access signatures (SAS). With Microsoft Entra ID, there’s no need to store the tokens in your code and risk potential security vulnerabilities. We recommend that you use Microsoft Entra ID with your Azure Service Bus applications when possible.
16+
Microsoft Entra ID provides superior security and ease of use over shared access signatures (SAS). By using Microsoft Entra ID, you don't need to store tokens in your code, which reduces potential security vulnerabilities. Use Microsoft Entra ID with your Azure Service Bus applications when possible.
1717

1818
This article explains how to disable SAS key authentication (or local authentication) and use only Microsoft Entra ID for authentication.
1919

20+
## Why disable local authentication?
21+
22+
Disabling local (SAS key) authentication strengthens the security of your Service Bus namespace in several ways:
23+
24+
- **Eliminates static credentials.** SAS keys are long-lived shared secrets. If a key leaks, anyone who has it can access your namespace until you manually rotate the key. Microsoft Entra ID uses short-lived tokens that are automatically refreshed.
25+
- **Enables fine-grained access control.** SAS policies grant broad rights (Send, Listen, Manage) at the namespace or entity level. Microsoft Entra role-based access control (RBAC) lets you assign specific roles (`Azure Service Bus Data Sender`, `Azure Service Bus Data Receiver`, `Azure Service Bus Data Owner`) to individual users, groups, service principals, or managed identities.
26+
- **Provides an audit trail.** Microsoft Entra authentication events appear in the Microsoft Entra sign-in logs. SAS key usage doesn't produce comparable identity-level audit records.
27+
- **Supports conditional access.** By using Microsoft Entra ID, you can enforce policies such as multifactor authentication, trusted device requirements, and location restrictions - none of which are available by using SAS keys.
28+
29+
> [!TIP]
30+
> Before you disable local authentication, update all applications to authenticate by using Microsoft Entra ID. See the [migration steps](#migrate-from-sas-to-microsoft-entra-id) section later in this article.
31+
2032
## Use portal to disable local auth
2133
In this section, you learn how to use the Azure portal to disable local authentication.
2234

23-
1. Navigate to your Service Bus namespace in the [Azure portal](https://portal.azure.com).
24-
1. In the **Essentials** section of the **Overview** page, select **Enabled**, for **Local Authentication**.
35+
1. Go to your Service Bus namespace in the [Azure portal](https://portal.azure.com).
36+
1. In the **Essentials** section of the **Overview** page, select **Enabled** for **Local Authentication**.
2537

2638
:::image type="content" source="./media/disable-local-authentication/portal-overview-enabled.png" alt-text="Screenshot that shows the Overview page of a Service Bus namespace with Local Authentication set to Enabled." lightbox="./media/disable-local-authentication/portal-overview-enabled.png":::
2739
1. On the **Local Authentication** page, select **Disabled**, and select **OK**.
2840

2941
:::image type="content" source="./media/disable-local-authentication/select-disabled.png" alt-text="Screenshot that shows the selection of Disabled option on the Local Authentication page.":::
3042

3143
## Use a template to disable local auth
32-
You can disable local authentication for a Service Bus namespace by setting `disableLocalAuth` property to `true` as shown in the following templates.
44+
You can disable local authentication for a Service Bus namespace by setting the `disableLocalAuth` property to `true` as shown in the following templates.
3345

3446
# [Bicep](#tab/bicep)
3547

@@ -94,13 +106,197 @@ resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2024-01-01' = {
94106

95107
---
96108

97-
## Azure policy
98-
You can assign the [disable local auth](https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2Fcfb11c26-f069-4c14-8e36-56c394dae5af) Azure policy to an Azure subscription or a resource group to enforce disabling of local authentication for all Service Bus namespaces in the subscription or the resource group.
109+
## Use Azure CLI or PowerShell to disable local auth
110+
111+
You can also disable local authentication by using command-line tools for an existing namespace.
112+
113+
# [Azure CLI](#tab/azure-cli)
114+
115+
```azurecli
116+
az servicebus namespace update \
117+
--resource-group <resource-group-name> \
118+
--name <namespace-name> \
119+
--disable-local-auth true
120+
```
121+
122+
To re-enable local authentication:
123+
124+
```azurecli
125+
az servicebus namespace update \
126+
--resource-group <resource-group-name> \
127+
--name <namespace-name> \
128+
--disable-local-auth false
129+
```
130+
131+
# [Azure PowerShell](#tab/azure-powershell)
132+
133+
```azurepowershell
134+
Set-AzServiceBusNamespace `
135+
-ResourceGroupName <resource-group-name> `
136+
-Name <namespace-name> `
137+
-DisableLocalAuth
138+
```
139+
140+
To re-enable local authentication:
141+
142+
```azurepowershell
143+
Set-AzServiceBusNamespace `
144+
-ResourceGroupName <resource-group-name> `
145+
-Name <namespace-name> `
146+
-DisableLocalAuth:$false
147+
```
148+
149+
---
150+
151+
You can verify the current state by checking the `disableLocalAuth` property:
152+
153+
# [Azure CLI](#tab/azure-cli)
154+
155+
```azurecli
156+
az servicebus namespace show \
157+
--resource-group <resource-group-name> \
158+
--name <namespace-name> \
159+
--query disableLocalAuth
160+
```
161+
162+
# [Azure PowerShell](#tab/azure-powershell)
163+
164+
```azurepowershell
165+
(Get-AzServiceBusNamespace -ResourceGroupName <resource-group-name> -Name <namespace-name>).DisableLocalAuth
166+
```
167+
168+
---
169+
170+
## Enforce with Azure Policy
171+
172+
For tenant-wide or subscription-wide enforcement, use the built-in Azure Policy [**Service Bus namespaces should have local authentication methods disabled**](https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2Fcfb11c26-f069-4c14-8e36-56c394dae5af) (policy ID: `cfb11c26-f069-4c14-8e36-56c394dae5af`).
173+
174+
This policy evaluates Service Bus namespaces and flags any that have `disableLocalAuth` set to `false` or unset. You can assign it at the management group, subscription, or resource group level.
175+
176+
### Policy effects
177+
178+
When you assign the policy, choose an effect that matches your enforcement needs:
179+
180+
| Effect | Behavior |
181+
|--------|----------|
182+
| **Audit** (default) | Existing namespaces with local auth enabled appear as **non-compliant** in the compliance dashboard. New namespaces are still allowed. |
183+
| **Deny** | Prevents the creation or update of any namespace that has local auth enabled. Use this effect to enforce compliance for new resources. |
184+
185+
### Assign the policy
186+
187+
1. In the [Azure portal](https://portal.azure.com), go to **Policy** > **Definitions**.
188+
1. Search for *Service Bus namespaces should have local authentication methods disabled*.
189+
1. Select the policy definition, and then select **Assign**.
190+
1. Choose the scope (management group, subscription, or resource group).
191+
1. On the **Parameters** tab, select the desired effect (**Audit** or **Deny**).
192+
1. Select **Review + create**, and then **Create**.
193+
194+
After assignment, namespaces that don't comply appear in **Policy** > **Compliance**. You can create a remediation task for namespaces that need updating.
99195

100196
:::image type="content" source="./media/disable-local-authentication/azure-policy.png" alt-text="Screenshot of Azure policy to disable location authentication." lightbox="./media/disable-local-authentication/azure-policy.png":::
101197

198+
## Migrate from SAS to Microsoft Entra ID
199+
200+
Before you disable local authentication, update all applications that connect to your Service Bus namespace to use Microsoft Entra ID instead of connection strings or SAS tokens. Follow these steps:
201+
202+
### Step 1: Assign RBAC roles
203+
204+
Assign the appropriate Azure Service Bus data role to each identity (user, service principal, or managed identity) that needs access:
205+
206+
| Role | Permission |
207+
|------|-----------|
208+
| `Azure Service Bus Data Sender` | Send messages to queues and topics |
209+
| `Azure Service Bus Data Receiver` | Receive messages from queues and subscriptions |
210+
| `Azure Service Bus Data Owner` | Full access (send, receive, manage entities) |
211+
212+
You can assign roles through the Azure portal, Azure CLI, or Azure PowerShell. For detailed instructions, see [Assign Azure roles using the Azure portal](/azure/role-based-access-control/role-assignments-portal).
213+
214+
### Step 2: Update application code
215+
216+
Replace connection string-based authentication with `DefaultAzureCredential` (or another Microsoft Entra credential) from the Azure Identity library. The following examples show the change for each language:
217+
218+
# [.NET](#tab/dotnet)
219+
220+
```csharp
221+
// Before (connection string):
222+
await using ServiceBusClient client = new("<connection-string>");
223+
224+
// After (Microsoft Entra ID):
225+
await using ServiceBusClient client = new(
226+
"<your-namespace>.servicebus.windows.net",
227+
new DefaultAzureCredential());
228+
```
229+
230+
# [Java](#tab/java)
231+
232+
```java
233+
// Before (connection string):
234+
ServiceBusSenderClient sender = new ServiceBusClientBuilder()
235+
.connectionString("<connection-string>")
236+
.sender()
237+
.queueName("<queue-name>")
238+
.buildClient();
239+
240+
// After (Microsoft Entra ID):
241+
TokenCredential credential = new DefaultAzureCredentialBuilder().build();
242+
ServiceBusSenderClient sender = new ServiceBusClientBuilder()
243+
.credential("<your-namespace>.servicebus.windows.net", credential)
244+
.sender()
245+
.queueName("<queue-name>")
246+
.buildClient();
247+
```
248+
249+
# [Python](#tab/python)
250+
251+
```python
252+
# Before (connection string):
253+
client = ServiceBusClient.from_connection_string("<connection-string>")
254+
255+
# After (Microsoft Entra ID):
256+
from azure.identity import DefaultAzureCredential
257+
client = ServiceBusClient(
258+
fully_qualified_namespace="<your-namespace>.servicebus.windows.net",
259+
credential=DefaultAzureCredential())
260+
```
261+
262+
# [JavaScript](#tab/javascript)
263+
264+
```javascript
265+
// Before (connection string):
266+
const client = new ServiceBusClient("<connection-string>");
267+
268+
// After (Microsoft Entra ID):
269+
const { DefaultAzureCredential } = require("@azure/identity");
270+
const client = new ServiceBusClient(
271+
"<your-namespace>.servicebus.windows.net",
272+
new DefaultAzureCredential());
273+
```
274+
275+
---
276+
277+
For more detail on each SDK, see:
278+
- .NET: [Sample — Authenticate the client](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample00_AuthenticateClient.md)
279+
- Java: [Sample — Send with Azure Identity](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/servicebus/azure-messaging-servicebus/src/samples/java/com/azure/messaging/servicebus/SendMessageWithAzureIdentityAsyncSample.java)
280+
- Python: [Sample — Service Bus client](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/servicebus/azure-servicebus/samples/sync_samples/sample_code_servicebus.py)
281+
- JavaScript: [Service Bus samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/servicebus/service-bus/samples)
282+
283+
### Step 3: Test with both auth methods enabled
284+
285+
Deploy your updated application while local auth is still enabled. Verify that:
286+
- You send and receive messages successfully.
287+
- The application logs show Microsoft Entra token acquisition (not SAS).
288+
- No errors related to authentication appear.
289+
290+
### Step 4: Disable local authentication
291+
292+
After you confirm all applications work with Microsoft Entra ID, disable local auth by using any of the methods described earlier in this article (portal, CLI, PowerShell, or template).
293+
294+
### Step 5: Clean up SAS policies (optional)
295+
296+
After you disable local auth, existing SAS policies on the namespace remain but can't be used to generate functional tokens. You can leave them in place or remove them for a cleaner configuration. Removing unused policies reduces the attack surface if someone accidentally re-enables local auth.
297+
102298
## Related content
103-
See the following to learn about Microsoft Entra ID and SAS authentication.
299+
To learn about Microsoft Entra ID and SAS authentication, see the following articles:
104300

105301
- [Authentication with SAS](service-bus-sas.md)
106302
- Authentication with Microsoft Entra ID

0 commit comments

Comments
 (0)