Have a deployed azure functions with docker compose locally using net6.0.
Need to call the function from another local api service, adding the x-functions-key in the header.
The function has the auth attribute: AuthorizationLevel.Function
How do i find the default or master key for the locally deployed azure function?
I have tried various dummy keys and all sent 401 unauthorized back. I have also found a folder called DataProtection-Keys with a xml file containing keys, but these did not work either.
You have two ways to get the key:
Set a master key of your own and pass it into the container, so that the container will always accept that key.
Step 1: Create a test_host_keys.json
file locally with the following contents:
{
"masterKey": {
"name": "master",
"value": "test", <-- this will be the host key you use
"encrypted": false
},
"functionKeys": []
}
Step 2: Invoke docker with two extra parameters:
-e AzureWebJobsSecretStorageType=files
to make it use local auth keys-v path/to/your/test_host_keys.json:/azure-functions-host/Secrets/host.json
to set the custom host keys(This is an improvement on this answer, since with this you can use the same Dockerfile for local testing and for production)
In the container, look inside the /azure-functions-host/Secrets/
folder for a .json file
Read that file to find the default key. It'll look something like the following:
> cat /azure-functions-host/Secrets/[thefile].json
root@5b9250f41cc6:/# cat /azure-functions-host/Secrets/some_trigger.json
{
"keys": [
{
"name": "default",
"value": "buoxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==", <-- your key
"encrypted": false
}
],
"hostName": null,
"instanceId": "000000000000000000000000xxxxxxxx",
"source": "runtime",
"decryptionKeyId": ""
}