Http Trigger Azure Function in Docker with non anonymous authLevel

▼魔方 西西 提交于 2019-12-23 18:34:20

问题


I am playing around with an Http Triggered Azure Functions in a Docker container. Up to now all tutorials and guides I found on setting this up configure the Azure Function with the authLevel" set to anonymous.

After reading this blog carefully it seems possible (although tricky) to also configure other authentication levels. Unfortunately the promised follow up blogpost has not (yet) been written.

Can anyone help me clarify on how I would go about and set this up?


回答1:


To control the master key the Function host uses on startup - instead of generating random keys - prepare our own host_secrets.json file like

{
   "masterKey": {
   "name": "master",
   "value": "asGmO6TCW/t42krL9CljNod3uG9aji4mJsQ7==",
   "encrypted": false
},
"functionKeys": [
      {
         "name": "default",
         "value": "asGmO6TCW/t42krL9CljNod3uG9aji4mJsQ7==",
         "encrypted": false
      }
   ]
}

and then feed this file into the designated secrets folder of the Function host (Dockerfile):

for V1 Functions (assuming your runtime root is C:\WebHost):

...
ADD host_secrets.json C:\\WebHost\\SiteExtensions\\Functions\\App_Data\\Secrets\\host.json
...

for V2 Functions (assuming your runtime root is C:\runtime):

...
ADD host_secret.json C:\\runtime\\Secrets\\host.json

USER ContainerAdministrator
RUN icacls "c:\runtime\secrets" /t /grant Users:M
USER ContainerUser

ENV AzureWebJobsSecretStorageType=files
...

The function keys can be used to call protected functions like .../api/myfunction?code=asGmO6TCW/t42krL9CljNod3uG9aji4mJsQ7==.

The master key can be used to call Functions Admin API and Key management API.

In my blog I describe the whole journey of bringing V1 and later V2 Functions runtime into Docker containers and host those in Service Fabric.



来源:https://stackoverflow.com/questions/53126627/http-trigger-azure-function-in-docker-with-non-anonymous-authlevel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!