Skip to content

Commit ce4d43c

Browse files
committed
Merge branch 'main' of https://github.com/MicrosoftDocs/azure-docs-pr into managing-billing-benefits
2 parents a3f0e49 + 5f37852 commit ce4d43c

8 files changed

Lines changed: 143 additions & 122 deletions

articles/app-service/webjobs-sdk-how-to.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ The following table shows built-in roles that we recommend when you use triggers
158158
[Azure Service Bus Data Receiver]: ../role-based-access-control/built-in-roles.md#azure-service-bus-data-receiver
159159
[Azure Service Bus Data Sender]: ../role-based-access-control/built-in-roles.md#azure-service-bus-data-sender
160160
[Azure Service Bus Data Owner]: ../role-based-access-control/built-in-roles.md#azure-service-bus-data-owner
161-
[role-assignment-scope]: ../service-bus-messaging/service-bus-managed-service-identity.md#resource-scope
161+
[role-assignment-scope]: ../service-bus-messaging/service-bus-managed-service-identity.md#choose-the-resource-scope
162162

163163
#### Connection strings in version 2.*x*
164164

articles/event-grid/deliver-events-using-managed-identity.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ To deliver events to event hubs in your Event Hubs namespace using managed ident
3737
To deliver events to Service Bus queues or topics in your Service Bus namespace using managed identity, follow these steps:
3838

3939
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
4141
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).
4242
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.
4343

articles/sap/center-sap-solutions/prepare-network.md

Lines changed: 71 additions & 72 deletions
Large diffs are not rendered by default.

articles/service-bus-messaging/jms-developer-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Each connection factory is an instance of `ConnectionFactory`, `QueueConnectionF
6161
To simplify connecting with Azure Service Bus, these interfaces are implemented through `ServiceBusJmsConnectionFactory`, `ServiceBusJmsQueueConnectionFactory`, or `ServiceBusJmsTopicConnectionFactory` respectively.
6262

6363
> [!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.
6565
6666
# [System Assigned Managed Identity](#tab/system-assigned-managed-identity-backed-authentication)
6767

articles/service-bus-messaging/service-bus-dotnet-multi-tier-app-using-service-bus-queues.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ In this tutorial, you'll use Microsoft Entra authentication to create `ServiceBu
8181
1. [Add the application to the `Service Bus Data Owner` role](/azure/role-based-access-control/role-assignments-portal).
8282
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).
8383

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).
8585

8686
## Create a namespace
8787

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,64 @@
11
---
2-
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
55
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+
69
---
710

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)
1029

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).
1232
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
1834

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.
2036

21-
```csharp
22-
string fullyQualifiedNamespace = "<your namespace>.servicebus.windows.net>";
23-
string userAssignedClientId = "<your managed identity client ID>";
37+
The following table lists the Azure built-in roles for authorizing access to a Service Bus namespace:
2438

25-
var credential = new DefaultAzureCredential(
26-
new DefaultAzureCredentialOptions
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 |
3044

31-
var sbusClient = new ServiceBusClient(fullyQualifiedNamespace, credential);
32-
```
45+
### Assign a role in the Azure portal
3346

34-
> [!IMPORTANT]
35-
> 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).
36-
37-
## Azure built-in roles for Azure Service Bus
38-
Microsoft Entra authorizes access to secured resources through [Azure role-based access control (RBAC)](../role-based-access-control/overview.md). Azure Service Bus defines a set of Azure built-in roles that encompass common sets of permissions used to access Service Bus entities. You can also define custom roles for accessing the data.
47+
To assign a role to a managed identity in the Azure portal:
3948

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**.
4156

42-
- [Azure Service Bus Data Owner](../role-based-access-control/built-in-roles.md#azure-service-bus-data-owner): Use this role to allow full access to Service Bus namespace and its entities (queues, topics, subscriptions, and filters)
43-
- [Azure Service Bus Data Sender](../role-based-access-control/built-in-roles.md#azure-service-bus-data-sender): Use this role to allow sending messages to Service Bus queues and topics.
44-
- [Azure Service Bus Data Receiver](../role-based-access-control/built-in-roles.md#azure-service-bus-data-receiver): Use this role to allow receiving messages from Service Bus queues and subscriptions.
57+
For more information, see [Assign Azure roles using the Azure portal](../role-based-access-control/role-assignments-portal.md).
4558

46-
To assign a role to a managed identity in the Azure portal, use the **Access control (IAM)** page. Navigate to this page by selecting **Access control (IAM)** on the **Service Bus Namespace** page or **Service Bus queue** page, or **Service Bus topic** page. For step-by-step instructions for assigning a role, see [Assign Azure roles using the Azure portal](/azure/role-based-access-control/role-assignments-portal).
59+
### Choose the resource scope
4760

48-
## Resource scope
49-
Before you assign an Azure role to a managed identity, determine the scope of access that the managed identity should have. Best practices dictate that it's always best to grant only the narrowest possible scope.
61+
Before you assign an Azure role, determine the scope of access that the managed identity needs. Grant only the narrowest possible scope.
5062

5163
The following list describes the levels at which you can scope access to Service Bus resources, starting with the narrowest scope:
5264

@@ -56,9 +68,11 @@ The following list describes the levels at which you can scope access to Service
5668
- **Subscription**: Role assignment applies to all the Service Bus resources in all of the resource groups in the subscription.
5769

5870
> [!NOTE]
59-
> Keep in mind that Azure role assignments may take up to five minutes to propagate.
71+
> Azure role assignments might take up to five minutes to propagate.
6072
61-
Currently, the Azure portal doesn't support assigning users, groups, or managed identities to Service Bus Azure roles at the topic's subscription level. Here's an example of using the Azure CLI command: [az-role-assignment-create](/cli/azure/role/assignment?#az-role-assignment-create) to assign an identity to a Service Bus Azure role:
73+
### Assign a role using Azure CLI
74+
75+
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:
6276

6377
```azurecli
6478
az role assignment create \
@@ -70,30 +84,35 @@ az role assignment create \
7084
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).
7185

7286
> [!NOTE]
73-
> If the source service or app doesn't restart after the access to a Service Bus entity is disabled by removing the source's managed identity from the Service Bus RBAC role, the source app may continue to send/receive messages to/from the Service Bus entity until the token expires (default token validity is 24 hours). This behavior is by design.
87+
> 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.
7488
>
75-
> Therefore, 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 messages to or receiving messages from the Service Bus entity.
89+
> 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
7692

77-
## Using SDKs
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.
7894

7995
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.
8096

8197
```csharp
82-
var client = new ServiceBusClient('cotosons.servicebus.windows.net', new DefaultAzureCredential());
98+
var client = new ServiceBusClient("contoso.servicebus.windows.net", new DefaultAzureCredential());
8399
```
84100

85101
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).
86102

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.
88104

89-
- [.NET](service-bus-dotnet-get-started-with-queues.md).
90-
- [Java](service-bus-java-how-to-use-queues.md).
105+
- [.NET](service-bus-dotnet-get-started-with-queues.md)
106+
- [Java](service-bus-java-how-to-use-queues.md)
91107
- [JavaScript](service-bus-nodejs-how-to-use-queues.md)
92108
- [Python](service-bus-python-how-to-use-queues.md)
93109

94110
> [!NOTE]
95-
> 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).
96112
97113

98114
## 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

Comments
 (0)