Skip to content

Using Service Principal to perform git operation

Suwat Ch edited this page Apr 9, 2018 · 1 revision

Currently, we don't support setting the deployment credential for Service Principal (likely in the future). As a work around, you can perform git operation using Service Principal's bearer token directly.

  • Login with Service Principal
az login --service-principal --username <app_id>  --password <secret_or_path_to_pfx_cert> --tenant <tenant>

See this for details.

  • Get bearer token of Service Principal
az account get-access-token --resource https://management.core.windows.net/

See this for details. The bearer token is returned in accessToken property. I suggest to store accessToken to ACCESS_TOKEN env for later use (set ACCESS_TOKEN=ey...).

  • Pass the bearer token to Git operations
git -c http.extraheader="Authorization: Bearer %ACCESS_TOKEN%"  push https://mysite.scm.azurewebsites.net master
Clone this wiki locally