Check if managed identity is configured from .NET Core application

Viewed 88

I want to know if application has managed identity configured(let's say App Service, but really does not matter). So far I see next options:

  • Manually check if some environment variable defined, for example: IDENTITY_ENDPOINT
  • Add flag to config, which I will set during deployment to specify if MI is configured or not
  • If I connecting to Azure SQL, check if connection string has no User ID specified

All those seems to work for me, but I am wondering if something built-in Azure.Identity SDK exists.

1 Answers

The package Azure.Identity just provides some credentials to do Azure AD auth and require AD token to access resource projected by Azure AD. We cannot use it to check if Azure resource has enabled MSI. For more details, please refer to here.

Regarding the issue, I suggest you use Azure rest API to get the resource then check if the property identity has value.

Related