0
votes

I'm trying to figure out how to secure an azure function (service func) that should only be called from another azure function (client func) in the same tenant.

Here's what I've tried in the azure portal:

  • created a windows function app on a consumption plan
  • added a hello-world http triggered function with authorization level of "Anonymous"
  • tested I'm able to call the function anonymously
  • on the blade for the service func, selected "Authentication"
    • selected "Add identity provider"
    • chose "Microsoft"
    • "Create new app registration"
    • "Current tenant - Single tenant"
    • "Require authentication", "HTTP 401"
  • created a new app registration for the client func, making a note of the client_id and client_secret

I then configured postman to acquire a token from the azure ad (using the only tenant id in play), passing the client_id and client_secret from the app registration of the client func. In the post to the /token endpoint, I gave a grant_type value of "client_credentials".

On posting the request from postman, I received a response containing an access_token. I copied this and pasted into https://jwt.ms to check that all looked ok.

I configured another request in postman to issue a get to the hello-world function. This contained a "Authorization" header with a value of "Bearer " + the access_token received in the previous step.

Despite passing what seems to be a valid access token, the function app (which has no authentication bindings) return a 401 Unauthorized error.

I don't need authorization, just authentication.

Can anyone spot where I went wrong?

1
Does the client App have the requisite API Permission assigned from the main app? Possibly that's one of the reasons why the error is seen.Srinath Menon

1 Answers

0
votes

I now have this working. I found the following page helpful: Microsoft Doc

Key points:

  • App roles declared on the app registration of the service app
  • I didn't manually enter anything into the "Expose an API" page
  • No authorized client applications listed on the "Expose an API" page
  • When getting the access token, the scope should be set to the Application ID URI of the target service app registration + "/.default"
  • API permissions set on the app registration of the client service - these are "Application permissions" NOT "Delegated permissions"
  • From the function app, select Authentication then edit the identity provider. The value for "Allowed token audiences" needs to be the api://guid value from the "Application ID URI" value of the app registration for the target app service. I noticed that I had problems when using a non-guid value for this