Hi @Srishti Purohit,
The 403 Forbidden
error during the Kudu Zip Deploy indicates that the token or credentials used in your PowerShell deployment command no longer have sufficient access to perform the operation.
This may be due to:
- Expired or incorrectly scoped access token.
- Recent changes to App Service authentication or publishing settings.
- Use of a service principal or managed identity lacking the Contributor role.
- Use this format when acquiring the access token:
However, the Kudu API requires a token scoped for$resource = "https://management.azure.com/" $token = (Get-AzAccessToken -ResourceUrl $resource).Token
https://{appname}.scm.azurewebsites.net
. But Azure AD does not issue tokens directly for Kudu. So instead, use Basic Auth with Publishing Credentials, or use the Kudu Web Deploy profile. - Use Basic Auth with Publishing Profile
https://learn.microsoft.com/en-us/azure/app-service/deploy-zip?tabs=cli#deploy-using-curl# Get publishing profile XML from Azure (manual or via pipeline secure variable) $creds = ConvertTo-SecureString "<your-publishing-password>" -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ("$username", $creds) Invoke-RestMethod -Uri $kuduApiUrl -Credential $credential -Method POST -InFile $ZipPackageFile -ContentType "application/zip"
- Use
Publish-AzWebApp
instead (simpler & secure)
https://learn.microsoft.com/en-us/powershell/module/az.websites/publish-azwebapp?view=azps-14.1.0Publish-AzWebApp -ResourceGroupName "<RGName>" -Name "<AppName>" -ArchivePath "<PathToZip>"
- If using Managed Identity or Service Principal, check that it has Contributor role on the App Service or Resource Group:
https://learn.microsoft.com/en-us/azure/app-service/deploy-configure-credentials?tabs=cli#use-rbac-rulesaz role assignment list --assignee <principalId> --scope /subscriptions/<subId>/resourceGroups/<rg>/providers/Microsoft.Web/sites/<appname>
Hope this helps, if you have any further concerns or queries, please feel free to reach out to us.