|
| 1 | +--- |
| 2 | +title: Use Managed Identity for SQL Database authentication in Azure HDInsight |
| 3 | +description: Learn how to use managed identity for SQL Database authentication in Azure HDInsight. |
| 4 | +ms.service: azure-hdinsight |
| 5 | +ms.topic: how-to |
| 6 | +ms.date: 12/26/2024 |
| 7 | +--- |
| 8 | + |
| 9 | +# Use Managed Identity for SQL Database authentication in Azure HDInsight |
| 10 | + |
| 11 | + |
| 12 | +HDInsight has added the Managed Identity option for authenticating SQL databases within its cluster offerings and providing a more secure authentication mechanism. |
| 13 | + |
| 14 | +This article outlines the process of using the Managed Identity (MSI) option for SQL Database authentication when creating a HDInsight cluster. |
| 15 | + |
| 16 | +The Managed Identity option is available for the following Databases: |
| 17 | + |
| 18 | + |
| 19 | +| Databases | Host on Behalf of (HoBo) DB | Bring Your Own (BYO) DB | |
| 20 | +|-|-|-| |
| 21 | +|Ambari|✅ |✅ | |
| 22 | +|Hive |✅| ✅| |
| 23 | +|Oozie |✅ |✅ | |
| 24 | +|Ranger (ESP)|N | N | |
| 25 | + |
| 26 | +> [!NOTE] |
| 27 | +> MSI option is presently unavailable for ESP clusters configured with the HoBo setup. |
| 28 | +
|
| 29 | +## Create Managed Identity |
| 30 | + |
| 31 | +1. During cluster creation, navigate to the Storage section and select the SQL database for Ambari, Hive, Oozie, or Ranger. Choose Managed Identity as the Authentication method. |
| 32 | + :::image type="content" source="./media/use-managed-identity-for-sql-database-authentication-in-azure-hdinsight/basic-tab.png" alt-text="Screenshot showing the basic tab." border="true" lightbox="./media/use-managed-identity-for-sql-database-authentication-in-azure-hdinsight/basic-tab.png"::: |
| 33 | + |
| 34 | +1. Select the Managed Identity to authenticate with SQL Database. |
| 35 | + :::image type="content" source="./media/use-managed-identity-for-sql-database-authentication-in-azure-hdinsight/storage-tab.png" alt-text="Screenshot showing the storage tab." border="true" lightbox="./media/use-managed-identity-for-sql-database-authentication-in-azure-hdinsight/storage-tab.png"::: |
| 36 | +1. Create a contained user with the Managed identity (contosoMSI) in the corresponding SQL database. |
| 37 | +1. Follow these steps in the Azure SQL database query editor to create a database user and grant it read-write permissions. Perform these steps for each SQL Database you're going to use for different services such as Ambari, Hive, Oozie, or Ranger. |
| 38 | +1. User name must contain the original MSI name extended by a user-defined suffix. As best practice, the suffix can include an initial part of its Object ID. |
| 39 | +Object ID of managed identity can be obtained from portal on the managed identity portal page. |
| 40 | + |
| 41 | + For example: |
| 42 | + MSI Name: contosoMSI |
| 43 | + Object ID: `2ba6c-1111-2222-3333-cccccccccccc` |
| 44 | + |
| 45 | + |
| 46 | + user_name could be `contosoMSI-2ba6c` |
| 47 | + |
| 48 | + ``` |
| 49 | + CREATE USER {user_name} FROM EXTERNAL PROVIDER WITH OBJECT_ID={object id of cluster managed identity}; |
| 50 | + |
| 51 | + ALTER ROLE db_datareader ADD MEMBER {user_name}; |
| 52 | + ALTER ROLE db_ddladmin ADD MEMBER {user_name}; |
| 53 | + ALTER ROLE db_datawriter ADD MEMBER {user_name}; |
| 54 | + ``` |
| 55 | + > [!NOTE] |
| 56 | + > If the roles `db_executor`, `db_view_def`, and `db_view_state` are already defined in your database, there is no need to proceed with the subsequent step. |
| 57 | + |
| 58 | + ``` |
| 59 | + CREATE ROLE db_executor; |
| 60 | + GRANT EXECUTE TO db_executor; |
| 61 | + ALTER ROLE db_executor ADD MEMBER {user_name}; |
| 62 | + |
| 63 | + CREATE ROLE db_view_def; |
| 64 | + GRANT VIEW DEFINITION TO db_view_def; |
| 65 | + ALTER ROLE db_view_def ADD MEMBER {user_name}; |
| 66 | + CREATE ROLE db_view_db_state; |
| 67 | + |
| 68 | + GRANT VIEW DATABASE STATE TO db_view_db_state; |
| 69 | + |
| 70 | + ALTER ROLE db_view_def ADD MEMBER {user_name}; |
| 71 | + ``` |
| 72 | + |
| 73 | +1. After entering the necessary details, proceed with Cluster creation on the portal. |
| 74 | + |
| 75 | + > [!NOTE] |
| 76 | + > If you’re using managed identity as Entra admin in SQL DB, you have to execute the above commands via SDK/Powershell. |
0 commit comments