For example, an application may need to connect to a database. Instead of storing the connection string in the code, it is better to store it securely in Key Vault.
To authenticate to Azure Key Vault is possible to use shared secret or a certificate, but they should be stored in configuration files or code which make it not so secure. To make access to the Key Vault more secure is possible to use managed identity and AD authentication.
- To get access to Key Vault from function application and to read keys and secrets using user-assigned managed identity, first of all a user-assigned managed identity must be created.
- Then it must be assigned to the function application at Identity settings to grant app rights to use this identity.
- At the next step by the Key Vault application at Access Policies, needed permissions for manipulating with the Key Vault data must be granted to user-assigned managed identity.
- At the end, AzureServicesAuthConnectionString with user-assigned managed identity ClientId must be added into Application settings of function application .
- Using AzureServicesAuthConnectionString, function requests authorization token from active directory.
- Active directory validates received in connection string user-assigned managed identity and if it was successfully validated, sends authorization token as a response.
- Function sends request with authentication token to KeyVault.
- KeyVault automatically sends request to active directory to validate token.
- Active directory validates token and send response.
- If token was successfully validated by active directory and managed identity has permission for requested action (for example to read secret), KeyVault executes this action (sends secret to the function).