This document covers authentication methods other than OpenID Connect (OIDC) for the Azure Functions GitHub Action. OIDC is the recommended method — see Use OIDC in the main README.
The methods documented here are kept for users who cannot adopt OIDC. They store long-lived secrets and are less secure.
You can alternatively use a service principal, which requires you to manage secrets. You must configure the workflow with these secrets, and then it can use them to authenticate with Azure.
Important
When possible, you should use OIDC for authentication instead of service principal-based authentication.
To configure your workflow to use a service principal for authentication:
-
If you don't already have it installed, download Azure CLI and run
az loginto sign in with your Azure credentials. -
Run this Azure CLI command:
az ad sp create-for-rbac --name "myApp" --role "Website Contributor" \ --scopes /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.Web/sites/<APP_NAME> \ --json-authIn this example, Replace
<SUBSCRIPTION_ID>,<RESOURCE_GROUP>, and<APP_NAME>with the names of your subscription, resource group, and Azure function app. The command should return JSON output like this:{ "clientId": "<GUID>", "clientSecret": "<GUID>", "subscriptionId": "<GUID>", "tenantId": "<GUID>", (...) } -
Copy this JSON response output, which is the credential you provide to GitHub for authentication.
Warning
Keep this credential safe. It provides Website Contributor role access to your function app.
-
In your GitHub Repository, select Settings > Secrets > Add a new secret, name the secret something like
AZURE_RBAC_CREDENTIALS, and paste in JSON credentials of the service principal. -
Add the
azure/loginaction as a step prior to the Azure Functions action:- Make sure to include the parameter
cred-id, which maps to your recently created repository secretAZURE_RBAC_CREDENTIALS. - Make sure you don't also have any publish profiles in your workflow, which would be in the
publish-profileparameter of the Azure Functions action.
- Make sure to include the parameter
When you use a service principal with RBAC, the jobs section of your workflow looks something like this:
# Deploy to an app on the Flex Consumption plan using a service principal with RBAC as authentication
jobs:
build:
runs-on: ubuntu-latest
steps:
# ...checkout your repository
# ...required build steps for your language
# ...upload your build artifact
deploy:
runs-on: ubuntu-latest
needs: build
steps:
# ...download your build artifact
- name: 'Log in to Azure with AZ CLI'
uses: azure/login@v3
with:
cred-id: ${{ secrets.AZURE_RBAC_CREDENTIALS }}
- name: 'Run the Azure Functions action'
uses: Azure/functions-action@v1
id: deploy-to-function-app
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: '${{ env.AZURE_FUNCTIONAPP_PROJECT_PATH }}' A publish profile contains plain-text secrets that authenticate with your function app using basic authentication with the scm HTTP endpoint.
Warning
Publish profile authentication uses a shared secret which you must manage. It also requires you to enable publishing credential access to the app, which is off by default and is not recommended. You should instead use a more secure option like OIDC authentication.
To configure your workflow using the publish profile:
-
In the Azure portal, locate your function app.
-
Make sure that Basic authentication is enabled in the
scmendpoint in your app under Settings > Configuration > SCM Basic Auth Publishing Credentials. -
In the Overview blade, select Get publish profile and download the .PublishSettings file, which contains the plain-text publishing credentials for your
scmendpoint. -
Open the .PublishSettings file and copy the XML file contents. Delete or secure this secrets file when you're done.
-
In your GitHub Repository, select Settings > Secrets > Add a new secret, name the secret AZURE_FUNCTIONAPP_PUBLISH_PROFILE, and paste in the XML profile file contents.
-
Make sure that your workflow isn't using the
azure/loginaction. -
Include the
publish-profileparameter in the Azure Functions action, referencing the AZURE_FUNCTIONAPP_PUBLISH_PROFILE secret.When using a publish profile, the
jobssection of your workflow looks something like this:# Deploy to an app on the Flex Consumption plan using a publish profile as authentication jobs: build: runs-on: ubuntu-latest steps: # ...checkout your repository # ...required build steps for your language # ...upload your build artifact deploy: runs-on: ubuntu-latest needs: build steps: # ...download your build artifact - name: 'Run the Azure Functions action' uses: Azure/functions-action@v1 id: deploy-to-function-app with: app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }} package: '${{ env.AZURE_FUNCTIONAPP_PROJECT_PATH }}' sku: `flexconsumption` # Parameter required when using a publish profile with Flex Consumption publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}