Skip to content

Commit 3b1d842

Browse files
committed
New auth/auth concept content
1 parent 993e7af commit 3b1d842

File tree

7 files changed

+1088
-0
lines changed

7 files changed

+1088
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Authenticate with Azure Active Directory
3+
titleSuffix: Azure IoT Hub
4+
description: Understand how Azure IoT Hub uses Azure Active Directory to authenticate IoT hubs and devices.
5+
author: kgremban
6+
ms.service: iot-hub
7+
services: iot-hub
8+
ms.author: kgremban
9+
ms.topic: conceptual
10+
ms.date: 05/01/2023
11+
ms.custom: ['Role: Cloud Development', 'Role: IoT Device', 'Role: System Architecture']
12+
---
13+
14+
# Authenticate with Azure Active Directory
15+
16+
Intro
17+
18+
## Next steps
19+
20+
Use the Device Provisioning Service to [Provision multiple X.509 devices using enrollment groups](../iot-dps/tutorial-custom-hsm-enrollment-group-x509.md).
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Authentication overview
3+
titleSuffix: Azure IoT Hub
4+
description: Understand the authentication options available to Azure IoT Hub.
5+
author: kgremban
6+
ms.service: iot-hub
7+
services: iot-hub
8+
ms.author: kgremban
9+
ms.topic: overview
10+
ms.date: 05/01/2023
11+
ms.custom: ['Role: Cloud Development', 'Role: IoT Device', 'Role: System Architecture']
12+
---
13+
14+
# Authentication overview
15+
16+
This article defines authentication and provides an overview of available options you can use for authentication in IoT Hub.
17+
18+
## What is authentication?
19+
20+
*Authentication* is the process of proving that you are who you say you are. This is achieved by verification of the identity of a user or device to IoT Hub. It's sometimes shortened to *AuthN*. Authentication is separate from *authorization*, which is the process of confirming permissions for an authenticated user or device on IoT Hub. For more information about authorization, see [Authorization overview](authorize-overview.md).
21+
22+
## Authentication options
23+
24+
There are three different ways for handling authentication in IoT Hub:
25+
26+
- **Azure Active Directory (Azure AD) integration** for service APIs. Azure provides identity-based authentication with AAD and fine-grained authorization with Azure role-based access control (Azure RBAC). Azure AD and RBAC integration is supported for IoT hub service APIs only. To learn more, see [Authenticate with Azure Active Directory](authenticate-azure-ad.md).
27+
- **Shared access signatures** lets you group permissions and grant them to applications using access keys and signed security tokens. To learn more, see [Authenticate with shared access signatures](authenticate-sas.md).
28+
- **X.509 certificates**. Each IoT Hub contains an [identity registry](iot-hub-devguide-identity-registry.md) For each device in this identity registry, you can configure security credentials that grant DeviceConnect permissions scoped to the that device's endpoints. To learn more, see [Authenticate with X.509 certificates](authenticate-x509.md).
29+
30+
## Next steps
31+
32+
Read more about [authorization options available to IoT Hub](authorize-overview.md)
33+
34+
Use the Device Provisioning Service to [Provision multiple X.509 devices using enrollment groups](../iot-dps/tutorial-custom-hsm-enrollment-group-x509.md).

articles/iot-hub/authenticate-sas.md

Lines changed: 425 additions & 0 deletions
Large diffs are not rendered by default.

articles/iot-hub/authenticate-x509.md

Lines changed: 173 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
title: Control access to IoT Hub by using Azure Active Directory
3+
description: This article describes how to control access to IoT Hub for back-end apps by using Azure AD and Azure RBAC.
4+
title: Authorize access with Azure Active Directory
5+
titleSuffix: Azure IoT Hub
6+
description: Understand how Azure IoT Hub uses Azure Active Directory to authorize access to IoT hubs and devices.
7+
author: kgremban
8+
9+
ms.author: kgremban
10+
ms.service: iot-hub
11+
ms.topic: concept-article
12+
ms.date: 01/18/2023
13+
ms.custom: ['Role: Cloud Development', devx-track-azurecli]
14+
services: iot-hub
15+
ms.author: kgremban
16+
ms.topic: conceptual
17+
ms.date: 05/01/2023
18+
ms.custom: ['Role: Cloud Development', 'Role: IoT Device', 'Role: System Architecture']
19+
---
20+
21+
# Control access to IoT Hub by using Azure Active Directory
22+
# Authorize access with Azure Active Directory
23+
24+
## Control access to IoT Hub by using Azure Active Directory
25+
26+
You can use Azure Active Directory (Azure AD) to authenticate requests to Azure IoT Hub service APIs, like create device identity and invoke direct method. You can also use Azure role-based access control (Azure RBAC) to authorize those same service APIs. By using these technologies together, you can grant permissions to access IoT Hub service APIs to an Azure AD security principal. This security principal could be a user, group, or application service principal.
27+
28+
Authenticating access by using Azure AD and controlling permissions by using Azure RBAC provides improved security and ease of use over [security tokens](iot-hub-dev-guide-sas.md). To minimize potential security issues inherent in security tokens, we recommend that you [use Azure AD with your IoT hub whenever possible](#azure-ad-access-and-shared-access-policies).
29+
> [!NOTE]
30+
> Authentication with Azure AD isn't supported for the IoT Hub *device APIs* (like device-to-cloud messages and update reported properties). Use [symmetric keys](iot-hub-dev-guide-sas.md#use-a-symmetric-key-in-the-identity-registry) or [X.509](iot-hub-x509ca-overview.md) to authenticate devices to IoT Hub.
31+
## Authentication and authorization
32+
When an Azure AD security principal requests access to an IoT Hub service API, the principal's identity is first *authenticated*. For authentication, the request needs to contain an OAuth 2.0 access token at runtime. The resource name for requesting the token is `https://iothubs.azure.net`. If the application runs in an Azure resource like an Azure VM, Azure Functions app, or Azure App Service app, it can be represented as a [managed identity](../active-directory/managed-identities-azure-resources/how-managed-identities-work-vm.md).
33+
After the Azure AD principal is authenticated, the next step is *authorization*. In this step, IoT Hub uses the Azure AD role assignment service to determine what permissions the principal has. If the principal's permissions match the requested resource or API, IoT Hub authorizes the request. So this step requires one or more Azure roles to be assigned to the security principal. IoT Hub provides some built-in roles that have common groups of permissions.
34+
## Manage access to IoT Hub by using Azure RBAC role assignment
35+
With Azure AD and RBAC, IoT Hub requires the principal requesting the API to have the appropriate level of permission for authorization. To give the principal the permission, give it a role assignment.
36+
- If the principal is a user, group, or application service principal, follow the guidance in [Assign Azure roles by using the Azure portal](../role-based-access-control/role-assignments-portal.md).
37+
- If the principal is a managed identity, follow the guidance in [Assign a managed identity access to a resource by using the Azure portal](../active-directory/managed-identities-azure-resources/howto-assign-access-portal.md).
38+
To ensure least privilege, always assign the appropriate role at the lowest possible [resource scope](#resource-scope), which is probably the IoT Hub scope.
39+
IoT Hub provides the following Azure built-in roles for authorizing access to IoT Hub service APIs by using Azure AD and RBAC:
40+
| Role | Description |
41+
| ---- | ----------- |
42+
| [IoT Hub Data Contributor](../role-based-access-control/built-in-roles.md#iot-hub-data-contributor) | Allows full access to IoT Hub data plane operations. |
43+
| [IoT Hub Data Reader](../role-based-access-control/built-in-roles.md#iot-hub-data-reader) | Allows full read access to IoT Hub data plane properties. |
44+
| [IoT Hub Registry Contributor](../role-based-access-control/built-in-roles.md#iot-hub-registry-contributor) | Allows full access to the IoT Hub device registry. |
45+
| [IoT Hub Twin Contributor](../role-based-access-control/built-in-roles.md#iot-hub-twin-contributor) | Allows read and write access to all IoT Hub device and module twins. |
46+
You can also define custom roles to use with IoT Hub by combining the [permissions](#permissions-for-iot-hub-service-apis) that you need. For more information, see [Create custom roles for Azure role-based access control](../role-based-access-control/custom-roles.md).
47+
### Resource scope
48+
Before you assign an Azure RBAC role to a security principal, determine the scope of access that the security principal should have. It's always best to grant only the narrowest possible scope. Azure RBAC roles defined at a broader scope are inherited by the resources beneath them.
49+
This list describes the levels at which you can scope access to IoT Hub, starting with the narrowest scope:
50+
- **The IoT hub.** At this scope, a role assignment applies to the IoT hub. There's no scope smaller than an individual IoT hub. Role assignment at smaller scopes, like individual device identity or twin section, isn't supported.
51+
- **The resource group.** At this scope, a role assignment applies to all IoT hubs in the resource group.
52+
- **The subscription.** At this scope, a role assignment applies to all IoT hubs in all resource groups in the subscription.
53+
- **A management group.** At this scope, a role assignment applies to all IoT hubs in all resource groups in all subscriptions in the management group.
54+
## Permissions for IoT Hub service APIs
55+
The following table describes the permissions available for IoT Hub service API operations. To enable a client to call a particular operation, ensure that the client's assigned RBAC role offers sufficient permissions for the operation.
56+
| RBAC action | Description |
57+
|-|-|
58+
| `Microsoft.Devices/IotHubs/devices/read` | Read any device or module identity. |
59+
| `Microsoft.Devices/IotHubs/devices/write` | Create or update any device or module identity. |
60+
| `Microsoft.Devices/IotHubs/devices/delete` | Delete any device or module identity. |
61+
| `Microsoft.Devices/IotHubs/twins/read` | Read any device or module twin. |
62+
| `Microsoft.Devices/IotHubs/twins/write` | Write any device or module twin. |
63+
| `Microsoft.Devices/IotHubs/jobs/read` | Return a list of jobs. |
64+
| `Microsoft.Devices/IotHubs/jobs/write` | Create or update any job. |
65+
| `Microsoft.Devices/IotHubs/jobs/delete` | Delete any job. |
66+
| `Microsoft.Devices/IotHubs/cloudToDeviceMessages/send/action` | Send a cloud-to-device message to any device. |
67+
| `Microsoft.Devices/IotHubs/cloudToDeviceMessages/feedback/action` | Receive, complete, or abandon a cloud-to-device message feedback notification. |
68+
| `Microsoft.Devices/IotHubs/cloudToDeviceMessages/queue/purge/action` | Delete all the pending commands for a device. |
69+
| `Microsoft.Devices/IotHubs/directMethods/invoke/action` | Invoke a direct method on any device or module. |
70+
| `Microsoft.Devices/IotHubs/fileUpload/notifications/action` | Receive, complete, or abandon file upload notifications. |
71+
| `Microsoft.Devices/IotHubs/statistics/read` | Read device and service statistics. |
72+
| `Microsoft.Devices/IotHubs/configurations/read` | Read device management configurations. |
73+
| `Microsoft.Devices/IotHubs/configurations/write` | Create or update device management configurations. |
74+
| `Microsoft.Devices/IotHubs/configurations/delete` | Delete any device management configuration. |
75+
| `Microsoft.Devices/IotHubs/configurations/applyToEdgeDevice/action` | Apply the configuration content to an edge device. |
76+
| `Microsoft.Devices/IotHubs/configurations/testQueries/action` | Validate the target condition and custom metric queries for a configuration. |
77+
> [!TIP]
78+
> - The [Bulk Registry Update](/rest/api/iothub/service/bulkregistry/updateregistry) operation requires both `Microsoft.Devices/IotHubs/devices/write` and `Microsoft.Devices/IotHubs/devices/delete`.
79+
> - The [Twin Query](/rest/api/iothub/service/query/gettwins) operation requires `Microsoft.Devices/IotHubs/twins/read`.
80+
> - [Get Digital Twin](/rest/api/iothub/service/digitaltwin/getdigitaltwin) requires `Microsoft.Devices/IotHubs/twins/read`. [Update Digital Twin](/rest/api/iothub/service/digitaltwin/updatedigitaltwin) requires `Microsoft.Devices/IotHubs/twins/write`.
81+
> - Both [Invoke Component Command](/rest/api/iothub/service/digitaltwin/invokecomponentcommand) and [Invoke Root Level Command](/rest/api/iothub/service/digitaltwin/invokerootlevelcommand) require `Microsoft.Devices/IotHubs/directMethods/invoke/action`.
82+
> [!NOTE]
83+
> To get data from IoT Hub by using Azure AD, [set up routing to a separate event hub](iot-hub-devguide-messages-d2c.md#event-hubs-as-a-routing-endpoint). To access the [the built-in Event Hubs compatible endpoint](iot-hub-devguide-messages-read-builtin.md), use the connection string (shared access key) method as before.
84+
## Azure AD access and shared access policies
85+
By default, IoT Hub supports service API access through both Azure AD and [shared access policies and security tokens](iot-hub-dev-guide-sas.md). To minimize potential security vulnerabilities inherent in security tokens, disable access with shared access policies.
86+
1. Ensure that your service clients and users have [sufficient access](#manage-access-to-iot-hub-by-using-azure-rbac-role-assignment) to your IoT hub. Follow the [principle of least privilege](../security/fundamentals/identity-management-best-practices.md).
87+
1. In the [Azure portal](https://portal.azure.com), go to your IoT hub.
88+
1. On the left pane, select **Shared access policies**.
89+
1. Under **Connect using shared access policies**, select **Deny**, and review the warning.
90+
:::image type="content" source="media/iot-hub-dev-guide-azure-ad-rbac/disable-local-auth.png" alt-text="Screenshot that shows how to turn off IoT Hub shared access policies." border="true":::
91+
> [!WARNING]
92+
> By denying connections using shared access policies, all users and services that connect using this method lose access immediately. Notably, since Device Provisioning Service (DPS) only supports linking IoT hubs using shared access policies, all device provisioning flows will fail with "unauthorized" error. Proceed carefully and plan to replace access with Azure AD role based access. **Do not proceed if you use DPS**.
93+
Your IoT Hub service APIs can now be accessed only through Azure AD and RBAC.
94+
## Azure AD access from the Azure portal
95+
When you try to access IoT Hub, the Azure portal first checks whether you've been assigned an Azure role with `Microsoft.Devices/iotHubs/listkeys/action`. If you have, the Azure portal uses the keys from shared access policies to access IoT Hub. If not, the Azure portal tries to access data by using your Azure AD account.
96+
To access IoT Hub from the Azure portal by using your Azure AD account, you need permissions to access IoT Hub data resources (like devices and twins). You also need permissions to go to the IoT Hub resource in the Azure portal. The built-in roles provided by IoT Hub grant access to resources like devices and twin. But they don't grant access to the IoT Hub resource. So access to the portal also requires the assignment of an Azure Resource Manager role like [Reader](../role-based-access-control/built-in-roles.md#reader). The Reader role is a good choice because it's the most restricted role that lets you navigate the portal. It doesn't include the `Microsoft.Devices/iotHubs/listkeys/action` permission (which provides access to all IoT Hub data resources via shared access policies).
97+
To ensure an account doesn't have access outside of the assigned permissions, don't include the `Microsoft.Devices/iotHubs/listkeys/action` permission when you create a custom role. For example, to create a custom role that can read device identities but can't create or delete devices, create a custom role that:
98+
- Has the `Microsoft.Devices/IotHubs/devices/read` data action.
99+
- Doesn't have the `Microsoft.Devices/IotHubs/devices/write` data action.
100+
- Doesn't have the `Microsoft.Devices/IotHubs/devices/delete` data action.
101+
- Doesn't have the `Microsoft.Devices/iotHubs/listkeys/action` action.
102+
Then, make sure the account doesn't have any other roles that have the `Microsoft.Devices/iotHubs/listkeys/action` permission, like [Owner](../role-based-access-control/built-in-roles.md#owner) or [Contributor](../role-based-access-control/built-in-roles.md#contributor). To allow the account to have resource access and navigate the portal, assign [Reader](../role-based-access-control/built-in-roles.md#reader).
103+
## Azure IoT extension for Azure CLI
104+
Most commands against IoT Hub support Azure AD authentication. You can control the type of authentication used to run commands by using the `--auth-type` parameter, which accepts `key` or `login` values. The `key` value is the default.
105+
- When `--auth-type` has the `key` value, as before, the CLI automatically discovers a suitable policy when it interacts with IoT Hub.
106+
- When `--auth-type` has the `login` value, an access token from the Azure CLI logged in the principal is used for the operation.
107+
For more information, see the [Azure IoT extension for Azure CLI release page](https://github.com/Azure/azure-iot-cli-extension/releases/tag/v0.10.12).
108+
## SDK samples
109+
- [.NET Microsoft.Azure.Devices SDK sample](https://aka.ms/iothubaadcsharpsample)
110+
- [Java SDK sample](https://github.com/Azure/azure-iot-service-sdk-java/tree/main/service/iot-service-samples/role-based-authorization-sample)
111+
## Next steps
112+
113+
- For more information on the advantages of using Azure AD in your application, see [Integrating with Azure Active Directory](../active-directory/develop/how-to-integrate.md).
114+
- For more information on requesting access tokens from Azure AD for users and service principals, see [Authentication scenarios for Azure AD](../active-directory/develop/authentication-vs-authorization.md).
115+
116+
Use the Device Provisioning Service to [Provision multiple X.509 devices using enrollment groups](../iot-dps/tutorial-custom-hsm-enrollment-group-x509.md).
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Authorization overview
3+
titleSuffix: Azure IoT Hub
4+
description: Understand the authorization options available to Azure IoT Hub.
5+
author: kgremban
6+
ms.service: iot-hub
7+
services: iot-hub
8+
ms.author: kgremban
9+
ms.topic: overview
10+
ms.date: 05/01/2023
11+
ms.custom: ['Role: Cloud Development', 'Role: IoT Device', 'Role: System Architecture']
12+
---
13+
14+
# Authorization overview
15+
16+
This article defines authorization and provides an overview of available options you can use for authorization in IoT Hub.
17+
18+
## What is authorization?
19+
20+
*Authorization* is the process of confirming permissions for an authenticated user or device on IoT Hub. It specifies what resources and commands you're allowed to access, and what you can do with those resources and commands. Authorization is sometimes shortened to *AuthZ*. Authorization is separate from *authentication*, which is the process of proving that you are who you say you are. For more information about authentication, see [Authentication overview](authenticate-overview.md).
21+
22+
## Authorization options
23+
24+
There are two different ways for handling authorization in IoT Hub:
25+
26+
- **Azure Active Directory (Azure AD) integration** for service APIs. Azure provides identity-based authentication with AAD and fine-grained authorization with Azure role-based access control (Azure RBAC). Azure AD and RBAC integration is supported for IoT hub service APIs only. To learn more, see [Authorize access with Azure Active Directory](authorize-azure-ad.md).
27+
- **Shared access signatures** lets you group permissions and grant them to applications using access keys and signed security tokens. To learn more, see [Authorize access with shared access signatures](authorize-sas.md).
28+
29+
> [!TIP]
30+
> You can enable a lock on your IoT resources to prevent them being accidentally or maliciously deleted. To learn more about Azure Resource locks, please visit, [Lock your resources to protect your infrastructure](../azure-resource-manager/management/lock-resources.md?tabs=json)
31+
32+
## Next steps
33+
34+
Read more about [authentication options available to IoT Hub](authenticate-overview.md)
35+
36+
Use the Device Provisioning Service to [Provision multiple X.509 devices using enrollment groups](../iot-dps/tutorial-custom-hsm-enrollment-group-x509.md).

0 commit comments

Comments
 (0)