Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http Trigger Azure Function in Docker with non anonymous authLevel

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?

like image 686
Maurits van Beusekom Avatar asked Nov 02 '18 22:11

Maurits van Beusekom


People also ask

Can you trigger an Azure function using an HTTP request?

The HTTP trigger lets you invoke a function with an HTTP request. You can use an HTTP trigger to build serverless APIs and respond to webhooks. The default return value for an HTTP-triggered function is: HTTP 204 No Content with an empty body in Functions 2.

How do I trigger an Azure function?

Determine which trigger works best for your business needs. Create a timer trigger to invoke a function on a consistent schedule. Create an HTTP trigger to invoke a function when an HTTP request is received. Create a blob trigger to invoke a function when a blob is created or updated in Azure Storage.

How do you pass parameters by post to Azure function?

To pass value in the function route in Azure function, we would have to modify the route parameter as “Hello/{valueName}”. Then add a parameter with the same name as the valueName in the Run method to use this value in your azure function. But adding {valueName} makes it a mandatory value to be passed.


1 Answers

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.

for V3 Functions on Windows:

ENV FUNCTIONS_SECRETS_PATH=C:\Secrets
ENV AzureWebJobsSecretStorageType=Files
ADD host_secrets.json C:\\Secrets\\host.json

for V3 Functions on Linux:

RUN mkdir /etc/secrets/
ENV FUNCTIONS_SECRETS_PATH=/etc/secrets
ENV AzureWebJobsSecretStorageType=Files
ADD host_secrets.json /etc/secrets/host.json
like image 184
Kai Walter Avatar answered Sep 27 '22 23:09

Kai Walter