How to configure Managed Identity in Azure Function for SQL Database

hampton123 870 Reputation points
2023-11-14T19:24:26.4433333+00:00

Currently I am sending queries to a SQL database using an Azure Function. For debugging purposes, right now my configuration in my function consists of my login information for the SQL database, inserting the username and password into the function. I want to allow the Azure Function to access the SQL database without requiring my username and password in the code, so I want to add a managed identity (similar to Azure Storage Blob Contributor) to the Azure Function. That way, no credentials would be needed for the Azure Function to interact with the database. What role would I give it, and are there any extra steps I need to perform? Thank you in advance. Also for reference, I'm using Nodejs.

Azure SQL Database
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
3,724 questions
0 comments No comments
{count} votes

Accepted answer
  1. AirGordon 6,775 Reputation points
    2023-11-14T21:07:13.69+00:00

    There's really good documentation here that you can follow : https://learn.microsoft.com/en-us/azure/azure-functions/functions-identity-access-azure-sql-with-managed-identity#grant-sql-database-access-to-the-managed-identity

    The key steps

    1. Enable Managed Identity on the Function App
    2. Add the appropriate SQL Roles. CREATE USER [<identity-name>] FROM EXTERNAL PROVIDER; ALTER ROLE db_datareader ADD MEMBER [<identity-name>];
    3. Save the connection string in your Function App AppSettings.
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful