I am trying to follow this https://azure.microsoft.com/en-us/blog/simplifying-security-for-serverless-and-web-apps-with-azure-functions-and-app-service/ to securely get my secret from my key-vault when using azure functions.
My key vault has an access policy that allows getting secrets by the SYSTEM MANAGED IDENTITY
of the functions app.
Here's the relevant app setting as shown in the advanced editor (does not matter if slotSetting is true or false, already tried it. Not sure what it does btw)
{
"name": "ultrasecret",
"value": "@Microsoft.KeyVault(SecretUri=https://<vault-name>.vault.azure.net/secrets/<secret-name>/<version>)",
"slotSetting": true
}
Here's the scaffolded version of my one and only function, have a look at the IF block below to see me querying the key-vault, indirectly via the environment variable that exposes the key vault secret.
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
$name = $Request.Body.Name
}
if ($name) {
$status = [HttpStatusCode]::OK
$secret = $env:ultrasecret
$body = "Hello $name $secret"
}
else {
$status = [HttpStatusCode]::BadRequest
$body = "Please pass a name on the query string or in the request body."
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $status
Body = $body
})
When I make a GET request to
https://<function-app-name>.azurewebsites.net/api/HttpTrigger1?name=john
this is what is returned
Hello john @Microsoft.KeyVault(SecretUri=https://<vault-name>.vault.azure.net/secrets/<secret-name>/<version>)
So basically I am returning the literal setting's value, instead of the secret. Is this because Powershell support is in preview? Anyone else got it working?
Any help is greatly appreciated.