-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unreachable network (169.254.169.254:80) to request Access Token outside Azure #1005
Comments
Hi @johan-v-r Managed Identity based authentication only applies to Azure resources that support Managed Identities. This isn't a breaking change but a newly added support in Microsoft.Data.SqlClient. AzureServiceTokenProvider on the other hand uses various other token providers under the hood: Managed Identity is one of them: Related discussion: #730 (comment) |
Thanks @cheenamalhotra - I'll implement as suggested, although still unclear as to why it's only accessible in Azure..? I get that the managed identity only applies to Azure (like my Azure SQL) resources, but now I can't host my API (running under a Managed Identity) on premise or anywhere other than inside Azure, because it can't hit that IP. Wouldn't making that endpoint "public" also solve our issues here? |
That endpoint is only available in Azure environments, read more: Azure IMDS Service
|
Well that's unfortunate. So effectively this authentication has a hard dependency on apps being hosted in the Azure network, with the only alternative to implement your own custom auth provider to bypass all your work... Maybe worth a note in the docs..? Are there any discussions on changing this going forward? |
That's actually what this mode was meant to do, support only Managed Identities in Azure. Docs are everywhere (2.1 release notes), we never mentioned it's going to support anything else but Managed Identities in Azure. What gets confusing is when you somehow associate it to 'AzureServiceTokenProvider' which is actually doing multiple authentication modes at a time. Yes it works with Managed Identity, but that's only one part of the story. It does not change meaning of Managed Identity either. Why should 'ActiveDirectoryManagedIdentity' ever do everything else, when it's purposely designed to authenticate with Azure's Managed Identities? Both libraries have different behaviours and so do their APIs. Neither of them tend to mislead, but they're not comparable that way. Also, this is consistent design in all SQL Client Drivers that support Identity based authentication (JDBC, ODBC, PHP, etc.) with ActiveDirectoryManagedIdentity or ActiveDirectoryMSI keywords. It's another federated authentication mode, and is not meant to do anything else. |
Yup you're right. My fundamental understanding of the Azure accounts were wrong. Apologies for the confusion, but I really appreciate this feedback. |
What you could try is DefaultAzureCredential with Azure.Identity library that offers exact experience you're looking for, as I mentioned in the alternative above. We will be adding the same support very soon internally with a new mode so your transition to our new authentication mode will become much easier and you will be able to work seamlessly without changing your environments or connection string in future. |
Describe the bug
Trying to Authenticate Using Active Directory Managed Identity authentication from local machine (or any other environment outside Azure) gives the below exception.
Initially I created this SO issue that lead me to this breaking change/bug.
To reproduce
Executing this whilst logged in with AAD
Expected behavior
Get the token... This should be possible from outside Azure right?
The following works 100% like the original tutorial suggested.
Further technical details
Microsoft.Data.SqlClient version: 2.1.0
.NET target: 5.0
SQL Server version: Azure SQL
Operating system: Windows 10
Additional context
The environment is fully connected to Azure SQL using AAD, but not running in Azure.
The text was updated successfully, but these errors were encountered: