Condividi tramite

Azure SQL Database authentication fails when accessed from Azure Function (Login failed for user '<token-identified principal>')

Roberto Patuelli 0 Punti di reputazione
2026-06-30T14:39:12.6933333+00:00

Azure SQL Database authentication fails when accessed from Azure Function (Flex Consumption) using Azure AD Managed Identity (User Assigned).

The issue started suddenly after a period of correct operation, without any application or configuration changes.

Environment:

  • Azure Function App (Flex Consumption)
  • .NET 8 isolated worker
  • Microsoft.Data.SqlClient 7.0.0
  • Authentication: Active Directory Managed Identity (User Assigned)

Identity details:

  • Token AppId matches SQL EXTERNAL_USER SID
  • SQL user exists and is mapped via FROM EXTERNAL PROVIDER
  • Entra admin is correctly configured on the SQL server

Observed behavior:

  • Access token is successfully acquired from DefaultAzureCredential
  • Token is valid and contains correct tenant, appid and oid
  • Connection attempt fails with:

Login failed for user '<token-identified principal>' (Error 18456, State 1)

The same issue occurs both when:

  • Using SqlConnection.AccessToken manually
  • Using Authentication=Active Directory Managed Identity

Expected behavior:

  • Azure SQL should authenticate the Managed Identity successfully

Impact:

  • Production Azure Function cannot access Azure SQL Database
Database SQL di Microsoft Azure

Risposta

Le risposte possono essere contrassegnate come "Accettata" dall'autore della domanda e "Consigliata" dai moderatori, in modo da consentire agli utenti di sapere che la risposta ha risolto il problema dell'autore.