I am trying to get the default function key for a function.
Both the Azure PowerShell tools and the listSecrets function in an ARM template provide an invalid key.
Please provide the following:
We are using the new "breaking changes" V2 beta (Runtime version: 2.0.12050.0)
Provide the steps required to reproduce the problem:
First, make sure you have set up a resource group and function app with a function.
I have observed the same problem with all the resource groups/apps/functions I have tested it on.
The names used below are for an example that no longer exists, so you need supply your own values in the relevant places.
With the Azure PowerShell module you can reproduce the problem like this:
Invoke-AzureRmResourceAction -ApiVersion '2018-02-01' -ResourceGroupName 'sandbox39284732' -ResourceType "Microsoft.Web/sites/functions" -ResourceName 'functionapp39284732/GetKommuner' -Action listsecrets -Force
This will return a key and trigger_url.
You can use the following ARM template.
ARM template:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"functionApp": {"type": "string", "defaultValue": "functionapp39284732"},
"functionName": {"type": "string", "defaultValue": "GetKommuner"}
},
"variables": {
"functionAppId": "[resourceId('Microsoft.Web/sites', parameters('functionApp'))]",
"functionId": "[resourceId('Microsoft.Web/sites/functions', parameters('functionApp'), parameters('functionName'))]"
},
"resources": [
],
"outputs": {
"functionAppId": {
"type": "string",
"value": "[variables('functionAppId')]"
},
"functionId": {
"type": "string",
"value": "[variables('functionId')]"
},
"functionkeys": {
"type": "object",
"value": "[listSecrets(variables('functionId'), '2018-02-01')]"
}
}
}
You can deploy the ARM template with this command (assuming it is saved in GetKeys.json) and you supply your own -ResourceGroupName
New-AzureRmResourceGroupDeployment -name foo -TemplateFile .\GetKeys.json -ResourceGroupName nameofyourresourcegroup -Verbose
The outputs contain the function key and the related trigger_url with code. They do not match the value seen in the portal.
Provide a description of the expected behavior.
I would expect the default function key for the function to be returned.
This was the behaviour last week, before the breaking changes.
Provide a description of the actual behavior observed.
Both ARM and PowerShell return a key that is not recognized as a function key.
I have verified the following:
Perhaps the new release is still reading keys from the file system rather than the associated StorageAccount?
Also note that the Azure web portal shows a valid value.
The behaviour is the same if I add additional function keys.
Provide a description of any known workarounds.
None.
None.
For general 2.0.12050 issues see #3363
@mjul I wrote a wiki page to try to explain the current state of things. I dont have a great solution for you right this second, but we are working to get things into a good state. Take a read, and give me your feedback here so I can augment the document with additional answers as required:
https://github.com/Azure/azure-functions-host/wiki/Changes-to-Key-Management-in-Functions-V2
This announcement said:
if you relied on direct file access or SCM APIs to manage those secrets, that will no longer work.
And your doc said this:
The end result is that working with function keys over ARM when running on functions 2.0.12050.0-alpha or later is currently problematic. We are working on a solution to the issue.
So does that mean SCM API is deprecated whereas the ARM API is just temporarily not working?
Also I read the article @justinyoo mentioned here: https://github.com/Azure/app-service-announcements-discussions/issues/64#issuecomment-417977791. Should we be using the admin api instead of the ARM api? I don't see secrets listed in the docs...but @justinyoo said it was working for him
Some quick answers:
In order to elaborate @EricJizbaMSFT 's comment, I'd rather make something a bit clear.
Invoke-RestMethod cmdlet (in a generic way) but not through Invoke-AzureRmResourceAction as it doesn't seem to be implemented or exposed.Invoke-AzureRmResourceAction, which I'm expecting @paulbatum 's second statement, in terms of "TBD" ;-)Hope this helps.
@justinyoo To be clear, #3381 is not going to be merged as is. We're still working to find the right solution.
@paulbatum Thanks for the useful wiki description, it would be helpful with an example of how to use the recommended admin API to get the correct keys for now.
@mjul I wrote a wiki page to try to explain the current state of things. I dont have a great solution for you right this second, but we are working to get things into a good state. Take a read, and give me your feedback here so I can augment the document with additional answers as required:
https://github.com/Azure/azure-functions-host/wiki/Changes-to-Key-Management-in-Functions-V2
Do you know if there's a newer API for ARM Templates that support fetching keys from the blobs yet ?
@irajbalakrish not yet but we are actively working on this. Its part of an effort to address several issues with working with function apps through ARM. The scope is somewhat large, so I expect its still a few months away.
@paulbatum Any news on this?
I'm trying to create Azure Event Grid subscription with ARM template, but this blocks it:(
Addressed via https://github.com/Azure/azure-functions-host/issues/3994 - the new key management APIs are now live. Rather than the old "listsecrets" API if you now use the new "listkeys" APIs as described in the issue above,
Most helpful comment
@mjul I wrote a wiki page to try to explain the current state of things. I dont have a great solution for you right this second, but we are working to get things into a good state. Take a read, and give me your feedback here so I can augment the document with additional answers as required:
https://github.com/Azure/azure-functions-host/wiki/Changes-to-Key-Management-in-Functions-V2