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/event-grid/deliver-events-using-managed-identity.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ To deliver events to event hubs in your Event Hubs namespace using managed ident
37
37
To deliver events to Service Bus queues or topics in your Service Bus namespace using managed identity, follow these steps:
38
38
39
39
1. Enable system-assigned or user-assigned managed identity: [system topics](enable-identity-system-topics.md), [custom topics, and domains](enable-identity-custom-topics-domains.md).
40
-
1.[Add the identity to the **Azure Service Bus Data Sender**](../service-bus-messaging/service-bus-managed-service-identity.md#azure-built-in-roles-for-azure-service-bus) role on the Service Bus namespace
40
+
1.[Add the identity to the **Azure Service Bus Data Sender**](../service-bus-messaging/service-bus-managed-service-identity.md#assign-a-service-bus-role-to-the-managed-identity) role on the Service Bus namespace
41
41
1.[Enable the **Allow trusted Microsoft services to bypass this firewall** setting on your Service Bus namespace](../service-bus-messaging/service-bus-service-endpoints.md#trusted-microsoft-services).
42
42
1.[Configure the event subscription](managed-service-identity.md) that uses a Service Bus queue or topic as an endpoint to use the system-assigned or user-assigned managed identity.
Copy file name to clipboardExpand all lines: articles/service-bus-messaging/jms-developer-guide.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ Each connection factory is an instance of `ConnectionFactory`, `QueueConnectionF
61
61
To simplify connecting with Azure Service Bus, these interfaces are implemented through `ServiceBusJmsConnectionFactory`, `ServiceBusJmsQueueConnectionFactory`, or `ServiceBusJmsTopicConnectionFactory` respectively.
62
62
63
63
> [!IMPORTANT]
64
-
> Java applications leveraging JMS 2.0 API can connect to Azure Service Bus using the connection string, or using a `TokenCredential` for leveraging Microsoft Entra backed authentication. When using Microsoft Entra backed authentication, ensure to [assign roles and permissions](service-bus-managed-service-identity.md#azure-built-in-roles-for-azure-service-bus) to the identity as needed.
64
+
> Java applications leveraging JMS 2.0 API can connect to Azure Service Bus using the connection string, or using a `TokenCredential` for leveraging Microsoft Entra backed authentication. When using Microsoft Entra backed authentication, ensure to [assign roles and permissions](service-bus-managed-service-identity.md#assign-a-service-bus-role-to-the-managed-identity) to the identity as needed.
Copy file name to clipboardExpand all lines: articles/service-bus-messaging/service-bus-dotnet-multi-tier-app-using-service-bus-queues.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,7 @@ In this tutorial, you'll use Microsoft Entra authentication to create `ServiceBu
81
81
1.[Add the application to the `Service Bus Data Owner` role](/azure/role-based-access-control/role-assignments-portal).
82
82
1. Set the `AZURE-CLIENT-ID`, `AZURE-TENANT-ID`, AND `AZURE-CLIENT-SECRET` environment variables. For instructions, see [this article](/dotnet/api/overview/azure/identity-readme#environment-variables).
83
83
84
-
For a list of Service Bus built-in roles, see [Azure built-in roles for Service Bus](service-bus-managed-service-identity.md#azure-built-in-roles-for-azure-service-bus).
84
+
For a list of Service Bus built-in roles, see [Azure built-in roles for Service Bus](service-bus-managed-service-identity.md#assign-a-service-bus-role-to-the-managed-identity).
title: Managed identities for Azure resources with Service Bus
3
-
description: This article describes how to use managed identities to access with Azure Service Bus entities (queues, topics, and subscriptions).
4
-
ms.topic: article
2
+
title: Use Managed Identities with Azure Service Bus
3
+
description: Learn how to authenticate and access Azure Service Bus queues, topics, and subscriptions using managed identities for Azure resources.
4
+
ms.topic: how-to
5
5
ms.date: 02/11/2025
6
+
7
+
#customer intent: As a developer, I want to use managed identities to authenticate my application to Azure Service Bus so that I can avoid storing credentials in my code.
8
+
6
9
---
7
10
8
-
# Authenticate a managed identity with Microsoft Entra ID to access Azure Service Bus resources
9
-
Managed identities for Azure resources provide Azure services with an automatically managed identity in Microsoft Entra ID. You can use this identity to authenticate to any service such as Azure Service Bus that supports Microsoft Entra authentication, without having credentials in your code. If you aren't familiar with managed identities, see [Managed identities for Azure resources](../active-directory/managed-identities-azure-resources/overview.md) before proceeding to read through this article.
11
+
# How to use managed identities with Azure Service Bus
12
+
13
+
Managed identities for Azure resources provide Azure services with an automatically managed identity in Microsoft Entra ID. You can use this identity to authenticate to Azure Service Bus without storing credentials in your code.
14
+
15
+
This article walks you through enabling a managed identity, assigning the appropriate Service Bus role, and connecting to Service Bus from your application code.
16
+
17
+
> [!NOTE]
18
+
> If you're not familiar with managed identities, see [Managed identities for Azure resources](../active-directory/managed-identities-azure-resources/overview.md).
19
+
20
+
## Prerequisites
21
+
22
+
To use managed identities with Azure Service Bus, you need:
23
+
24
+
- An Azure subscription. If you don't have one, create a [free account](https://azure.microsoft.com/free/) before you begin.
25
+
- An Azure Service Bus namespace. To create one, see [Create a Service Bus namespace](service-bus-create-namespace-portal.md).
26
+
- A managed identity enabled on your Azure compute resource. See:
27
+
-[Configure managed identities for App Service and Azure Functions](../app-service/overview-managed-identity.md)
28
+
-[Configure managed identities for Azure resources on a virtual machine (VM)](../active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vm.md)
10
29
11
-
Here are the high-level steps to use a managed identity to access a Service Bus entity:
30
+
> [!IMPORTANT]
31
+
> You can disable local or SAS key authentication for a Service Bus namespace and allow only Microsoft Entra authentication. For step-by-step instructions, see [Disable local authentication](disable-local-authentication.md).
12
32
13
-
1. Enable managed identity for your client app or environment. For example, enable managed identity for your Azure App Service app, Azure Functions app, or a virtual machine in which your app is running. Here are the articles that help you with this step:
14
-
-[Configure managed identities for App Service and Azure Functions](../app-service/overview-managed-identity.md)
15
-
-[Configure managed identities for Azure resources on a virtual machine (VM)](../active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vm.md)
16
-
1. Assign Azure Service Bus Data Owner, Azure Service Bus Data Sender, or Azure Service Bus Data Receiver role to the managed identity at the appropriate scope (Azure subscription, resource group, Service Bus namespace, or Service Bus queue or topic). For instructions to assign a role to a managed identity, see [Assign Azure roles using the Azure portal](/azure/role-based-access-control/role-assignments-portal).
17
-
1. In your application, use the managed identity and the endpoint to Service Bus namespace to connect to the namespace.
33
+
## Assign a Service Bus role to the managed identity
18
34
19
-
For example, in .NET, you use the [ServiceBusClient](/dotnet/api/azure.messaging.servicebus.servicebusclient.-ctor#azure-messaging-servicebus-servicebusclient-ctor(system-string-azure-core-tokencredential)) constructor that takes `TokenCredential` and `fullyQualifiedNamespace` (a string, for example: `cotosons.servicebus.windows.net`) parameters to connect to Service Bus using the managed identity. You pass in [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential), which derives from `TokenCredential` and uses the managed identity. In `DefaultAzureCredentialOptions`, set the `ManagedIdentityClientId` to the ID of client's managed identity.
35
+
Microsoft Entra authorizes access to secured resources through [Azure role-based access control (RBAC)](../role-based-access-control/overview.md). Azure Service Bus provides Azure built-in roles that encompass common sets of permissions used to access Service Bus entities. You can also define custom roles.
The following table lists the Azure built-in roles for authorizing access to a Service Bus namespace:
24
38
25
-
varcredential=newDefaultAzureCredential(
26
-
newDefaultAzureCredentialOptions
27
-
{
28
-
ManagedIdentityClientId=userAssignedClientId
29
-
});
39
+
| Role | Description |
40
+
|------|-------------|
41
+
|[Azure Service Bus Data Owner](../role-based-access-control/built-in-roles.md#azure-service-bus-data-owner)| Full access to Service Bus namespace and its entities (queues, topics, subscriptions, and filters) |
42
+
|[Azure Service Bus Data Sender](../role-based-access-control/built-in-roles.md#azure-service-bus-data-sender)| Send messages to Service Bus queues and topics |
43
+
|[Azure Service Bus Data Receiver](../role-based-access-control/built-in-roles.md#azure-service-bus-data-receiver)| Receive messages from Service Bus queues and subscriptions |
>YoucandisablelocalorSASkeyauthenticationfor a Service Bus namespace and allow only Microsoft Entra authentication. For step-by-step instructions, see [Disable local authentication](disable-local-authentication.md).
36
-
37
-
## Azure built-in roles for Azure Service Bus
38
-
MicrosoftEntraauthorizesaccesstosecuredresourcesthrough [Azurerole-basedaccesscontrol (RBAC)](../role-based-access-control/overview.md). AzureServiceBusdefinesasetofAzurebuilt-inrolesthatencompasscommonsetsofpermissionsusedtoaccessServiceBusentities. Youcanalsodefinecustomrolesfor accessing the data.
47
+
To assign a role to a managed identity in the Azure portal:
39
48
40
-
Azure provides the following Azure built-in roles for authorizing access to a Service Bus namespace:
49
+
1. Go to your Service Bus namespace, queue, or topic.
50
+
1. Select **Access control (IAM)** from the left menu.
51
+
1. Select **Add** > **Add role assignment**.
52
+
1. On the **Role** tab, select the appropriate Service Bus data role.
53
+
1. On the **Members** tab, select **Managed identity**, then select **Select members**.
54
+
1. Select the managed identity for your Azure resource.
55
+
1. Select **Review + assign**.
41
56
42
-
- [Azure Service Bus Data Owner](../role-based-access-control/built-in-roles.md#azure-service-bus-data-owner):UsethisroletoallowfullaccesstoServiceBusnamespaceanditsentities (queues, topics, subscriptions, andfilters)
The Azure portal doesn't support assigning managed identities to Service Bus roles at the topic subscription level. Use the Azure CLI [az role assignment create](/cli/azure/role/assignment#az-role-assignment-create) command to assign a role at any scope:
62
76
63
77
```azurecli
64
78
az role assignment create \
@@ -70,30 +84,35 @@ az role assignment create \
70
84
For more information about how built-in roles are defined, see [Understand role definitions](../role-based-access-control/role-definitions.md#control-and-data-actions). For information about creating Azure custom roles, see [Azure custom roles](../role-based-access-control/custom-roles.md).
> If the source service or app doesn't restart after you remove its managed identity from the Service Bus RBAC role, the source app might continue to send or receive messages to or from the Service Bus entity until the token expires (default token validity is 24 hours). This behavior is by design.
> After you remove the source's managed identity from the RBAC role, restart the source app or service to immediately expire the token and prevent it from sending or receiving messages from the Service Bus entity.
90
+
91
+
## Connect to Service Bus using managed identity in Azure SDKs
76
92
77
-
## UsingSDKs
93
+
Azure SDKs for .NET, Java, JavaScript, and Python support managed identity authentication with Service Bus. The following example shows how to connect using the .NET SDK.
78
94
79
95
In .NET, the [ServiceBusClient](/dotnet/api/azure.messaging.servicebus.servicebusclient) object is initialized by using a constructor that takes a fully qualified namespace and a `TokenCredential`. The `DefaultAzureCredential` derives from `TokenCredential`, which automatically uses the managed identity configured for the app. The flow of the managed identity context to Service Bus and the authorization handshake are automatically handled by the token credential. It's a simpler model than using SAS.
You send and receive messages as usual using [ServiceBusSender](/dotnet/api/azure.messaging.servicebus.servicebussender) and [ServiceBusReceiver](/dotnet/api/azure.messaging.servicebus.servicebusreceiver) or [ServiceBusProcessor](/dotnet/api/azure.messaging.servicebus.servicebusprocessor).
86
102
87
-
For complete step-by-step instructions to send and receive messages using a managed identity, see the following quickstarts. These quickstarts have the code to use a service principal to send and receive messages, but the code is the same for using a managed identity.
103
+
For step-by-step instructions to send and receive messages using a managed identity, see the following quickstarts. These quickstarts have the code to use a service principal to send and receive messages, but the code is the same for using a managed identity.
> The managed identity works only inside the Azure environment, on App services, Azure VMs, and scale sets. For .NET applications, the Microsoft.Azure.Services.AppAuthentication library, which is used by the Service Bus NuGet package, provides an abstraction over this protocol and supports a local development experience. This library also allows you to test your code locally on your development machine, using your user account from Visual Studio, Azure CLI 2.0, or Active Directory Integrated Authentication. For more on local development options with this library, see [Service-to-service authentication to Azure Key Vault using .NET](/dotnet/api/overview/azure/service-to-service-authentication).
111
+
> Managed identities work only inside the Azure environment, on App Service, Azure VMs, and scale sets. For .NET applications, the Microsoft.Azure.Services.AppAuthentication library, which the Service Bus NuGet package uses, provides an abstraction over this protocol and supports a local development experience. This library also lets you test your code locally on your development machine, using your user account from Visual Studio, Azure CLI, or Microsoft Entra Integrated Authentication. For more on local development options with this library, see [Service-to-service authentication to Azure Key Vault using .NET](/dotnet/api/overview/azure/service-to-service-authentication).
96
112
97
113
98
114
## Next steps
99
-
See [this .NET web application sample on GitHub](https://github.com/Azure-Samples/app-service-msi-servicebus-dotnet/tree/master), which uses a managed identity to connect to Service Bus to send and receive messages. Add the identity of the app service to the **Azure Service Bus Data Owner** role.
115
+
116
+
-[Sample: .NET web application using managed identity with Service Bus](https://github.com/Azure-Samples/app-service-msi-servicebus-dotnet/tree/master)
117
+
-[What are managed identities for Azure resources?](../active-directory/managed-identities-azure-resources/overview.md)
118
+
-[Disable local authentication for Service Bus](disable-local-authentication.md)
0 commit comments