To connect Azure Synapse to Azure Service Bus using managed identity, you need to ensure that the managed identity has the appropriate permissions assigned in Azure Service Bus. You can use Microsoft Entra ID for authentication and authorization, which is recommended over local authentication methods.
- Assign Permissions: Ensure that the managed identity used by Azure Synapse has been assigned one of the built-in roles for Azure Service Bus, such as Azure Service Bus Data Sender or Azure Service Bus Data Receiver. This can be done through the Azure portal by navigating to the Access control (IAM) page of your Service Bus namespace and assigning the role to the managed identity.
- Disable Local Authentication: You can disable local authentication for your Service Bus namespace, allowing only Microsoft Entra authentication. This is a secure method and is recommended for production environments. You can follow the steps outlined in the documentation to disable local authentication.
- Connection Code: When connecting to Service Bus from Azure Synapse, use the managed identity to authenticate. Here's a sample code snippet for connecting:
string fullyQualifiedNamespace = "<your namespace>.servicebus.windows.net>"; string userAssignedClientId = "<your managed identity client ID>"; var credential = new DefaultAzureCredential( new DefaultAzureCredentialOptions { ManagedIdentityClientId = userAssignedClientId }); var sbusClient = new ServiceBusClient(fullyQualifiedNamespace, credential);
By following these steps, you should be able to connect to Azure Service Bus from Azure Synapse with local authentication disabled, using a managed identity in a secure manner.