azure-functions-sql-extension icon indicating copy to clipboard operation
azure-functions-sql-extension copied to clipboard

Managed identity authentication during local development

Open siddharth-krishna opened this issue 3 years ago • 2 comments

I'm able to use the Python preview to access my SQL DB using Managed Identity authentication on a deployed function app, following the code samples in this repository (thank you!). However, I'm unable to run the function locally and access the DB, as I get the following error:

System.Private.CoreLib: Exception while executing function: Functions.GetPieces. Microsoft.Data.SqlClient: ManagedIdentityCredential authentication unavailable. No response received from the managed identity endpoint. Azure.Core: The operation was canceled.

Here's my local.settings.json with my server and db redacted:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "SqlConnectionString": "Server=<my-server>.windows.net; Database=<my-db>; Authentication=Active Directory Managed Identity",
    "Sp_SelectCost": "SelectProductsCost",
    "ProductCost": 100,
    "PYTHON_ISOLATE_WORKER_DEPENDENCIES": "1"
  }
}

Am I missing some configuration step, or is this feature not yet available for local dev?

siddharth-krishna avatar Jul 20 '22 11:07 siddharth-krishna

Using managed identity auth in local development is supported - this article might help with the configuration steps: https://docs.microsoft.com/en-us/azure/app-service/tutorial-connect-msi-sql-database?tabs=cli%2Cef%2Cdotnet#2-set-up-your-dev-environment

dzsquared avatar Jul 28 '22 20:07 dzsquared

@dzsquared thanks for the pointer. I've logged into Azure both on Visual Studio Code, as well as the terminal. I still get the same error when I run the func: host start task and try to curl -i http://localhost:7071/api/pieces (which is my API). The deployed function is able to connect to SQL and return the items from my DB.

More context: I'm using VS Code Remote - Containers and the Docker container setup from https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-python. In fact, my code is pretty much the same as the samples, except that I'm querying my DB and returning all the rows.

siddharth-krishna avatar Aug 04 '22 12:08 siddharth-krishna