Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(401) Unauthorized Error While Running KUDU zipdeploy from VSTS #2826

Closed
joshidp opened this issue Aug 6, 2018 · 9 comments
Closed

(401) Unauthorized Error While Running KUDU zipdeploy from VSTS #2826

joshidp opened this issue Aug 6, 2018 · 9 comments

Comments

@joshidp
Copy link

joshidp commented Aug 6, 2018

Hi There,

I am using VSTS Azure Powershell task to deploy my AspNetCore zip package. Below is the REST call

$kuduApiUrl = "https://$webAppName.scm.azurewebsites.net/api/zipdeploy"

where $webAppName is my app service name

Invoke-RestMethod -Uri $kuduApiUrl -Headers @{Authorization = ("Basic {0}" -f $kuduApiAuthorisationToken) } -Method POST -InFile $ZipPackageFile -ContentType "multipart/form-data"

All input data are valid but still, I am getting 401 UnAuthorised error.

Please suggest what could be the reason?

Let me know if you need more info.

@davidebbo
Copy link
Member

Likely explanation is that your kuduApiAuthorisationToken is not valid. So you're hitting auth issue that is not specifically related to VSTS nor to zipdeploy. Any attempt to access scm site with that token would likely fail.

@joshidp
Copy link
Author

joshidp commented Aug 6, 2018

Hi David,

Thanks for the response.

I am using below code snippets for generating token and it is generating the token perfectly. So still I am not sure what could be the reason for 401

function Get-PublishingProfileCredentials($resourceGroupName, $webAppName) {

    $resourceType = "Microsoft.Web/sites/config"
    $resourceName = "$webAppName/publishingcredentials"

    $publishingCredentials = Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType $resourceType -ResourceName $resourceName -Action list -Force

   	return $publishingCredentials
}

function Get-KuduApiAuthorisationHeaderValue($resourceGroupName, $webAppName) {

    Write-Host "Generating access token for web app $webAppName in $resourceGroupName Resource Group"

    $publishingCredentials = Get-PublishingProfileCredentials $resourceGroupName $webAppName

    Write-Host "publishingCredentials"
    Write-Host $publishingCredentials.Properties.PublishingUserName
    Write-Host $publishingCredentials.Properties.PublishingPassword

    return [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $publishingCredentials.Properties.PublishingUserName, $publishingCredentials.Properties.PublishingPassword)))
}

@davidebbo
Copy link
Member

As a test, try going to https://$webAppName.scm.azurewebsites.net/basicauth (in a clean Incognito windows), and check that the username & password that you are getting are working when you type them manually in the browser.

@joshidp
Copy link
Author

joshidp commented Aug 6, 2018

Tried and it's working fine.

image

image

@davidebbo
Copy link
Member

Then next step is to use F12 tools to see exactly what header is being sent in the working case, and compare it to what you send in your non-working case. You can also try to base64 decode each, and see what you end up with. There must be some difference at some level.

@joshidp
Copy link
Author

joshidp commented Aug 6, 2018

base64 tokens generated in VSTS release step and in-browser header are exactly matching

@davidebbo
Copy link
Member

And what happens if you use the same PowerShell logic locally? If it repros there, at least you'll have eliminated VSTS from the equation.

@joshidp
Copy link
Author

joshidp commented Aug 6, 2018

in the local same script works fine. No issues in local.

Also, in VSTS if I hardcode all the variable it works there too. But with variables, it doesn't work. Even though the variables have the correct values.

@davidebbo
Copy link
Member

I can't explain that, but I think at this point it's best to look at this as a VSTS issue rather than a Kudu issue. You can try opening issue on https://github.com/Microsoft/vsts-tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants