Skip to content

Commit 3d68f10

Browse files
authored
Merge pull request #217977 from alexwolfmsft/event-hub-passwordless-quickstart
Event Hubs Passwordless Flow
2 parents 3a9f3fd + 140600c commit 3d68f10

File tree

10 files changed

+551
-156
lines changed

10 files changed

+551
-156
lines changed

articles/event-hubs/event-hubs-dotnet-standard-getstarted-send.md

Lines changed: 277 additions & 154 deletions
Large diffs are not rendered by default.

articles/service-bus-messaging/service-bus-dotnet-get-started-with-queues.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ You can authorize access to the service bus namespace using the following steps:
4040
1. Launch Visual Studio. If you see the **Get started** window, select the **Continue without code** link in the right pane.
4141
1. Select the **Sign in** button in the top right of Visual Studio.
4242

43-
:::image type="content" source="./media/service-bus-dotnet-get-started-with-queues/azure-sign-button-visual-studio.png" alt-text="Screenshot showing the button to sign in to Azure using Visual Studio.":::
43+
:::image type="content" source="./media/service-bus-dotnet-get-started-with-queues/azure-sign-button-visual-studio.png" alt-text="Screenshot showing a button to sign in to Azure using Visual Studio.":::
44+
4445
1. Sign-in using the Azure AD account you assigned a role to previously.
4546

4647
:::image type="content" source="..//storage/blobs/media/storage-quickstart-blobs-dotnet/sign-in-visual-studio-account-small.png" alt-text="Screenshot showing the account selection.":::
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
title: "include file"
3+
description: "include file"
4+
services: storage
5+
author: alexwolfmsft
6+
ms.service: storage
7+
ms.topic: include
8+
ms.date: 09/09/2022
9+
ms.author: alexwolf
10+
ms.custom: include file
11+
---
12+
13+
When developing locally, make sure that the user account that connects to Azure Event Hubs has the correct permissions. You'll need the [Azure Event Hubs Data Owner](../../../articles/role-based-access-control/built-in-roles.md#azure-event-hubs-data-owner) role in order to send and receive messages. To assign yourself this role, you'll need the User Access Administrator role, or another role that includes the `Microsoft.Authorization/roleAssignments/write` action. You can assign Azure RBAC roles to a user using the Azure portal, Azure CLI, or Azure PowerShell. Learn more about the available scopes for role assignments on the [scope overview](/azure/role-based-access-control/scope-overview) page.
14+
15+
The following example assigns the `Azure Event Hubs Data Owner` role to your user account, which provides full access to Azure Event Hubs resources. In a real scenario, follow the [Principle of Least Privilege](/azure/active-directory/develop/secure-least-privileged-access) to give users only the minimum permissions needed for a more secure production environment.
16+
17+
### Azure built-in roles for Azure Event Hubs
18+
For Azure Event Hubs, the management of namespaces and all related resources through the Azure portal and the Azure resource management API is already protected using the Azure RBAC model. Azure provides the below Azure built-in roles for authorizing access to an Event Hubs namespace:
19+
20+
- [Azure Event Hubs Data Owner](../../../articles/role-based-access-control/built-in-roles.md#azure-event-hubs-data-owner): Enables data access to Event Hubs namespace and its entities (queues, topics, subscriptions, and filters)
21+
- [Azure Event Hubs Data Sender](../../../articles/role-based-access-control/built-in-roles.md#azure-event-hubs-data-sender): Use this role to give the sender access to Event Hubs namespace and its entities.
22+
- [Azure Event Hubs Data Receiver](../../../articles/role-based-access-control/built-in-roles.md#azure-event-hubs-data-receiver): Use this role to give the receiver access to Event Hubs namespace and its entities.
23+
24+
If you want to create a custom role, see [Rights required for Event Hubs operations](../../../articles/service-bus-messaging/service-bus-sas.md#rights-required-for-service-bus-operations).
25+
26+
> [!IMPORTANT]
27+
> In most cases, it will take a minute or two for the role assignment to propagate in Azure. In rare cases, it may take up to eight minutes. If you receive authentication errors when you first run your code, wait a few moments and try again.
28+
29+
### [Azure portal](#tab/roles-azure-portal)
30+
31+
1. In the Azure portal, locate your Event Hubs namespace using the main search bar or left navigation.
32+
33+
2. On the overview page, select **Access control (IAM)** from the left-hand menu.
34+
35+
3. On the **Access control (IAM)** page, select the **Role assignments** tab.
36+
37+
4. Select **+ Add** from the top menu and then **Add role assignment** from the resulting drop-down menu.
38+
39+
:::image type="content" source="media/event-hub-assign-roles/add-role.png" alt-text="A screenshot showing how to assign a role.":::
40+
41+
5. Use the search box to filter the results to the desired role. For this example, search for `Azure Event Hubs Data Owner` and select the matching result. Then choose **Next**.
42+
43+
6. Under **Assign access to**, select **User, group, or service principal**, and then choose **+ Select members**.
44+
45+
7. In the dialog, search for your Azure AD username (usually your *user@domain* email address) and then choose **Select** at the bottom of the dialog.
46+
47+
8. Select **Review + assign** to go to the final page, and then **Review + assign** again to complete the process.
48+
49+
### [Azure CLI](#tab/roles-azure-cli)
50+
51+
To assign a role at the resource level using the Azure CLI, you first must retrieve the resource ID using the `az servicebus namespace show` command. You can filter the output properties using the `--query` parameter.
52+
53+
```azurecli
54+
az servicebus namespace show -g '<your-event-hub-resource-group>' -n '<your-event-hub-name> --query id
55+
```
56+
57+
Copy the output `Id` from the preceding command. You can then assign roles using the [az role](/cli/azure/role) command of the Azure CLI.
58+
59+
```azurecli
60+
az role assignment create --assignee "<user@domain>" \
61+
--role "Azure Event Hubs Data Owner" \
62+
--scope "<your-resource-id>"
63+
```
64+
65+
### [PowerShell](#tab/roles-powershell)
66+
67+
To assign a role at the resource level using Azure PowerShell, you first must retrieve the resource ID using the `Get-AzResource` command.
68+
69+
```azurepowershell
70+
Get-AzResource -ResourceGroupName "<your-event-hub-resource-group>" -Name "<your-event-hub-name>"
71+
```
72+
73+
Copy the `Id` value from the preceding command output. You can then assign roles using the [New-AzRoleAssignment](/powershell/module/az.resources/new-azroleassignment) command in PowerShell.
74+
75+
```azurepowershell
76+
New-AzRoleAssignment -SignInName <user@domain> `
77+
-RoleDefinitionName "Azure Event Hubs Data Owner" `
78+
-Scope <yourStorageAccountId>
79+
```
80+
81+
---
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: include file
3+
description: include file
4+
services: service-bus-messaging
5+
author: spelluru
6+
ms.service: service-bus-messaging
7+
ms.topic: include
8+
ms.date: 04/26/2022
9+
ms.author: spelluru
10+
ms.custom: include file
11+
---
12+
13+
## Create a namespace in the Azure portal
14+
To begin using Event Hubs messaging entities in Azure, you must first create a namespace with a name that is unique across Azure. A namespace provides a scoping container for Event Hubs resources within your application.
15+
16+
To create a namespace:
17+
18+
1. Sign in to the [Azure portal](https://portal.azure.com)
19+
2. In the left navigation pane of the portal, select **+ Create a resource**, select **Integration**, and then select **Event Hubs**.
20+
21+
:::image type="content" source="./media/service-bus-create-namespace-portal/create-resource-service-bus-menu.png" alt-text="Screenshot of the selection of Create a resource, Integration, and then Event Hubs in the menu.":::
22+
3. In the **Basics** tag of the **Create namespace** page, follow these steps:
23+
1. For **Subscription**, choose an Azure subscription in which to create the namespace.
24+
1. For **Resource group**, choose an existing resource group in which the namespace will live, or create a new one.
25+
1. Enter a **name for the namespace**. The namespace name should adhere to the following naming conventions:
26+
- The name must be unique across Azure. The system immediately checks to see if the name is available.
27+
- The name length is at least 6 and at most 50 characters.
28+
- The name can contain only letters, numbers, and hyphens ("-").
29+
- The name must start with a letter and end with a letter or number.
30+
- The name doesn't end with "-sb" or "-mgmt".
31+
1. For **Location**, choose the region in which your namespace should be hosted.
32+
1. For **Pricing tier**, select the pricing tier (Basic, Standard, or Premium) for the namespace. For this quickstart, select **Standard**.
33+
34+
If you selected the **Premium** pricing tier, specify the number of **messaging units**. The premium tier provides resource isolation at the CPU and memory level so that each workload runs in isolation. This resource container is called a messaging unit. A premium namespace has at least one messaging unit. You can select 1, 2, 4, 8 or 16 messaging units for each Event Hubs Premium namespace. For more information, see [Event Hubs Premium Messaging](../../../articles/service-bus-messaging/service-bus-premium-messaging.md).
35+
36+
1. Select **Review + create**. The system now creates your namespace and enables it. You might have to wait several minutes for the system to provision resources for your account.
37+
38+
:::image type="content" source="./media/service-bus-create-namespace-portal/create-namespace.png" alt-text="Screenshot of the Create a namespace page.":::
39+
1. On the **Create** page, review settings, and select **Create**.
40+
4. Select **Go to resource** on the deployment page.
41+
42+
:::image type="content" source="./media/service-bus-create-namespace-portal/deployment-alert.png" alt-text="Screenshot of the deployment succeeded page with the Go to resource link.":::
43+
5. You see the home page for your Event Hubs namespace.
44+
45+
:::image type="content" source="./media/service-bus-create-namespace-portal/service-bus-namespace-home-page.png" alt-text="Screenshot of the home page of the Event Hubs namespace created." :::
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: "include file"
3+
description: "include file"
4+
services: storage
5+
author: alexwolfmsft
6+
ms.service: storage
7+
ms.topic: include
8+
ms.date: 09/09/2022
9+
ms.author: alexwolf
10+
ms.custom: include file
11+
---
12+
13+
This quick start shows you two ways of connecting to Azure Event Hubs: passwordless and connection string. The first option shows you how to use your security principal in Azure Active Directory and role-based access control (RBAC) to connect to an Event Hubs namespace. You don't need to worry about having hard-coded connection strings in your code or in a configuration file or in a secure storage like Azure Key Vault. The second option shows you how to use a connection string to connect to an Event Hubs namespace. If you're new to Azure, you may find the connection string option easier to follow. We recommend using the passwordless option in real-world applications and production environments. For more information, see [Authentication and authorization](../../../articles/service-bus-messaging/service-bus-authentication-and-authorization.md). You can also read more about passwordless authentication on the [overview page](/azure/sdk/authentication?tabs=command-line).
14+
15+
## [Passwordless](#tab/passwordless)
16+
17+
### Assign roles to your Azure AD user
18+
19+
[!INCLUDE [event-hub-assign-roles](event-hub-assign-roles.md)]
20+
21+
## Launch Visual Studio and sign-in to Azure
22+
23+
You can authorize access to the service bus namespace using the following steps:
24+
25+
1. Launch Visual Studio. If you see the **Get started** window, select the **Continue without code** link in the right pane.
26+
1. Select the **Sign in** button in the top right of Visual Studio.
27+
28+
:::image type="content" source="../../../articles/service-bus-messaging/media/service-bus-dotnet-get-started-with-queues/azure-sign-button-visual-studio.png" alt-text="Screenshot showing a button to sign in to Azure using Visual Studio.":::
29+
30+
1. Sign-in using the Azure AD account you assigned a role to previously.
31+
32+
:::image type="content" source="../../../articles/storage/blobs/media/storage-quickstart-blobs-dotnet/sign-in-visual-studio-account-small.png" alt-text="Screenshot showing the account selection.":::
33+
34+
## [Connection String](#tab/connection-string)
35+
36+
## Get the connection string
37+
Creating a new namespace automatically generates an initial Shared Access Signature (SAS) policy with primary and secondary keys and connection strings that each grant full control over all aspects of the namespace. See [Event Hubs authentication and authorization](../../../articles/service-bus-messaging/service-bus-authentication-and-authorization.md) for information about how to create rules with more constrained rights for regular senders and receivers.
38+
39+
A client can use the connection string to connect to the Event Hubs namespace. To copy the primary connection string for your namespace, follow these steps:
40+
41+
1. On the **Event Hub Namespace** page, select **Shared access policies** on the left menu.
42+
3. On the **Shared access policies** page, select **RootManageSharedAccessKey**.
43+
4. In the **Policy: RootManageSharedAccessKey** window, select the copy button next to **Primary Connection String**, to copy the connection string to your clipboard for later use. Paste this value into Notepad or some other temporary location.
44+
45+
:::image type="content" source="./media/event-hub-passwordless-template-tabbed/connection-string.png"alt-text="Screenshot shows an SAS policy called RootManageSharedAccessKey, which includes keys and connection strings.":::
46+
47+
You can use this page to copy primary key, secondary key, primary connection string, and secondary connection string.
48+
49+
---
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: "include file"
3+
description: "include file"
4+
services: storage
5+
author: alexwolfmsft
6+
ms.service: storage
7+
ms.topic: include
8+
ms.date: 10/21/2022
9+
ms.author: alexwolf
10+
ms.custom: include file
11+
---
12+
13+
Creating a new namespace automatically generates an initial Shared Access Signature (SAS) policy with primary and secondary keys, and primary and secondary connection strings that each grant full control over all aspects of the namespace. See [Service Bus authentication and authorization](../../../articles/event-hub-messaging/event-hub-authentication-and-authorization.md) for information about how to create rules with more constrained rights for regular senders and receivers.
14+
15+
To copy the primary connection string for your namespace, follow these steps:
16+
17+
1. On the **Event Hubs Namespace** page, select **Shared access policies** on the left menu.
18+
2. On the **Shared access policies** page, select **RootManageSharedAccessKey**.
19+
3. In the **Policy: RootManageSharedAccessKey** window, select the copy button next to **Primary Connection String**, to copy the connection string to your clipboard for later use. Paste this value into Notepad or some other temporary location.
20+
21+
:::image type="content" source="../../../articles/event-hub-messaging/includes/media/event-hub-create-namespace-portal/connection-string.png" alt-text="Screenshot shows an SAS policy called RootManageSharedAccessKey, which includes keys and connection strings.":::
22+
23+
You can use this page to copy primary key, secondary key, primary connection string, and secondary connection string.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: "include file"
3+
description: "include file"
4+
services: storage
5+
author: alexwolfmsft
6+
ms.service: storage
7+
ms.topic: include
8+
ms.date: 10/11/2022
9+
ms.author: alexwolf
10+
ms.custom: include file
11+
---
12+
13+
When developing locally, make sure that the user account that is accessing blob data has the correct permissions. You'll need **Storage Blob Data Contributor** to read and write blob data. To assign yourself this role, you'll need to be assigned the **User Access Administrator** role, or another role that includes the **Microsoft.Authorization/roleAssignments/write** action. You can assign Azure RBAC roles to a user using the Azure portal, Azure CLI, or Azure PowerShell. You can learn more about the available scopes for role assignments on the [scope overview](../../../articles/role-based-access-control/scope-overview.md) page.
14+
15+
In this scenario, you'll assign permissions to your user account, scoped to the storage account, to follow the [Principle of Least Privilege](../../../articles/active-directory/develop/secure-least-privileged-access.md). This practice gives users only the minimum permissions needed and creates more secure production environments.
16+
17+
The following example will assign the **Storage Blob Data Contributor** role to your user account, which provides both read and write access to blob data in your storage account.
18+
19+
> [!IMPORTANT]
20+
> In most cases it will take a minute or two for the role assignment to propagate in Azure, but in rare cases it may take up to eight minutes. If you receive authentication errors when you first run your code, wait a few moments and try again.
21+
22+
### [Azure portal](#tab/roles-azure-portal)
23+
24+
1. In the Azure portal, locate your storage account using the main search bar or left navigation.
25+
26+
2. On the storage account overview page, select **Access control (IAM)** from the left-hand menu.
27+
28+
3. On the **Access control (IAM)** page, select the **Role assignments** tab.
29+
30+
4. Select **+ Add** from the top menu and then **Add role assignment** from the resulting drop-down menu.
31+
32+
:::image type="content" source="../../../articles/storage/common/media/assign-role-system-identity.png" alt-text="A screenshot showing how to assign a storage account role.":::
33+
34+
5. Use the search box to filter the results to the desired role. For this example, search for *Storage Blob Data Contributor* and select the matching result and then choose **Next**.
35+
36+
6. Under **Assign access to**, select **User, group, or service principal**, and then choose **+ Select members**.
37+
38+
7. In the dialog, search for your Azure AD username (usually your *user@domain* email address) and then choose **Select** at the bottom of the dialog.
39+
40+
8. Select **Review + assign** to go to the final page, and then **Review + assign** again to complete the process.
41+
42+
### [Azure CLI](#tab/roles-azure-cli)
43+
44+
To assign a role at the resource level using the Azure CLI, you first must retrieve the resource ID using the `az storage account show` command. You can filter the output properties using the `--query` parameter.
45+
46+
```azurecli
47+
az storage account show --resource-group '<your-resource-group-name>' --name '<your-storage-account-name>' --query id
48+
```
49+
50+
Copy the output `Id` from the preceding command. You can then assign roles using the [az role](/cli/azure/role) command of the Azure CLI.
51+
52+
```azurecli
53+
az role assignment create --assignee "<user@domain>" \
54+
--role "Storage Blob Data Contributor" \
55+
--scope "<your-resource-id>"
56+
```
57+
58+
### [PowerShell](#tab/roles-powershell)
59+
60+
To assign a role at the resource level using Azure PowerShell, you first must retrieve the resource ID using the `Get-AzResource` command.
61+
62+
```azurepowershell
63+
Get-AzResource -ResourceGroupName "<yourResourceGroupname>" -Name "<yourStorageAccountName>"
64+
```
65+
66+
Copy the `Id` value from the preceding command output. You can then assign roles using the [New-AzRoleAssignment](/powershell/module/az.resources/new-azroleassignment) command in PowerShell.
67+
68+
```azurepowershell
69+
New-AzRoleAssignment -SignInName <user@domain> `
70+
-RoleDefinitionName "Storage Blob Data Contributor" `
71+
-Scope <yourStorageAccountId>
72+
```
73+
74+
---
77.5 KB
Loading
58 KB
Loading

includes/passwordless/service-bus/service-bus-passwordless-template-tabbed.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ A client can use the connection string to connect to the Service Bus namespace.
3535

3636
You can use this page to copy primary key, secondary key, primary connection string, and secondary connection string.
3737

38-
3938
---

0 commit comments

Comments
 (0)