projectkudu / kudu

Kudu is the engine behind git/hg deployments, WebJobs, and various other features in Azure Web Sites. It can also run outside of Azure.
Apache License 2.0
3.13k stars 652 forks source link

Zip API returns "Access to path 'D:\\applicationHost.xdt' #2179

Closed camerow closed 7 months ago

camerow commented 8 years ago

scm.mysite.azurewebsites.net/api/zip/site/ PUT with a .zip file won't work for me. Seems to be trying to put to the root D: directory or something. Me and some colleagues are a bit stumped as to why this is not working. Any pointers in the right direction are appreciated! Also if there is a gitter community or something this conversation would be more appropriate in, let me know.

Full console output:

Invoke-RestMethod : {"Message":"An error has occurred.","ExceptionMessage":"Access to the path
'D:\\applicationHost.xdt' is denied.","ExceptionType":"System.UnauthorizedAccessException","StackTrace":" at
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n at System.IO.FileStream.Init(String path,
FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions
options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)\r\n
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)\r\n at
System.IO.FileInfo.Open(FileMode mode, FileAccess access)\r\n at System.IO.Abstractions.FileInfoWrapper.Open(FileMode
mode, FileAccess access)\r\n at Kudu.Core.Infrastructure.ZipArchiveExtensions.Extract(ZipArchive archive, String
directoryName)\r\n at Kudu.Services.Zip.ZipController.d__3.MoveNext()\r\n--- End of stack trace from previous location
where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
System.Threading.Tasks.TaskHelpersExtensions.d__3`1.MoveNext()\r\n--- End of stack trace from previous location where
exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous
location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where
exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack
trace from previous location where exception was thrown ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()\r\n--- End of stack trace from previous location where
exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where
exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack
trace from previous location where exception was thrown ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()\r\n--- End of stack trace from previous location where
exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where
exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
System.Web.Http.Controllers.ExceptionFilterResult.d__0.MoveNext()\r\n--- End of stack trace from previous location
where exception was thrown ---\r\n at System.Web.Http.Controllers.ExceptionFilterResult.d__0.MoveNext()\r\n--- End of
stack trace from previous location where exception was thrown ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}
At W:\EmergencyReporting\Build\deploy\deployzipapi.ps1:37 char:1
+ Invoke-RestMethod -Uri $apiUrl -DisableKeepAlive -TimeoutSec 600 -Headers @{Auth ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
davidebbo commented 8 years ago

That's odd. Does the same work if you just drag and drop your same zip into Kudu console (in the special zip drop area) while under d:\home\site?

camerow commented 8 years ago

Drag and drop works. So we must be making our request improperly. I notice the form headers on DnD are x-www-url-formencoded while ours is multipart-form-data. Could that explain odd behavior?

On Fri, Oct 14, 2016, 2:35 PM David Ebbo notifications@github.com wrote:

That's odd. Does the same work if you just drag and drop your same zip into Kudu console (in the special zip drop area) while under d:\home\site?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/projectkudu/kudu/issues/2179#issuecomment-253925289, or mute the thread https://github.com/notifications/unsubscribe-auth/AD9k4mVe6eBc3LE1ra2_EJExxo4A7hgeks5qz_V6gaJpZM4KXcsw .

davidebbo commented 8 years ago

I'm not sure if the content type matters here, as Kudu likely ignores it.

But the fact that it works for you in DnD but not PowerShell makes it sound a lot like #1448, except in that case it was download and you're doing upload.

Can you check whether upload works for you with curl? Not the curl Posh alias, but the real curl.

davidebbo commented 8 years ago

Although the specific error that you get really doesn't make sense and looks unrelated to that other issue. Does it happen if you go to a different folder? What about with a trivial zip file? Maybe there are other difference in the way you make your request?

camerow commented 8 years ago

(EDIT: Wrote in browser for markdown support) Here's our current rest call just in case that helps:

$apiURL =  "https://oursite.scm.azurewebsites.net/api/zip/site"
$filePath = "./path/to/myzip.zip"
Invoke-RestMethod -Uri $apiURL -DisableKeepAlive -TimeoutSec 600 -Headers
@{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method PUT -InFile
$filePath -ContentType "application/zip"

I'll work on trying different folders, trivial zip file etc.

davidebbo commented 8 years ago

We actually have a sample on https://github.com/projectkudu/kudu/wiki/REST-API#sample-of-using-rest-api-with-powershell as well if you want to compare.

camerow commented 8 years ago

So far I've tried:

It seems to be a destination problem, though I could definitely be wrong on that. Nothing with this path: "https://{site-slot}.scm.azurewebsites.net/api/zip/site" stands out as invalid to me though. I'm not super great with Powershell so I'm sure there is some user error happening here as well, but struggling to find it.

Thanks for your help so far!

ivesovanes commented 4 years ago

Getting a similar issue when I do a POST

Function d3-JoinParts { param ([string[]] $Parts, [string] $Separator = '/')

        $search = '(?<!:)' + [regex]::Escape($Separator) + '+'  #Replace multiples except in front of a colon for URLs.
        $replace = $Separator
        ($Parts | ? {$_ -and $_.Trim().Length}) -join $Separator -replace $search, $replace
        }

$destinationPath = "/site/wwwroot" $baseUrl = "https://" + $siteName + ".scm.azurewebsites.net" $apiUrl = d3-JoinParts ($baseUrl, "api/zip", $destinationPath) '/'

        Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method PUT -InFile $sourceZipFile -ContentType "multipart/form-data" -TimeoutSec $timeOutSec

[error]Invoke-RestMethod : {"Message":"An error has occurred.","ExceptionMessage":"Access to the path is

denied.","ExceptionType":"System.UnauthorizedAccessException","StackTrace":" at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)\r\n at System.IO.FileStream.FlushWrite(Boolean calledFromFinalizer)\r\n at System.IO.FileStream.Dispose(Boolean

disposing)\r\n at System.IO.Stream.Close()\r\n at System.IO.Stream.Dispose()\r\n at

Kudu.Core.Infrastructure.ZipArchiveExtensions.Extract(ZipArchive archive, String directoryName, ITracer tracer,

Boolean doNotPreserveFileTime) in C:\Kudu

Files\Private\src\master\Kudu.Core\Infrastructure\ZipArchiveExtensions.cs:line 155\r\n at

Kudu.Services.Zip.ZipController.d__3.MoveNext() in C:\Kudu

Files\Private\src\master\Kudu.Services\Zip\ZipController.cs:line 67\r\n--- End of stack trace from previous

location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task

task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at

System.Threading.Tasks.TaskHelpersExtensions.d__3`1.MoveNext()\r\n--- End of stack trace from previous location where

exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at

System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at

System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous

location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task

task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at

System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where

exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack

trace from previous location where exception was thrown ---\r\n at

System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at

System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at

System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()\r\n--- End of stack trace from previous location where

exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at

System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at

System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where

exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack

trace from previous location where exception was thrown ---\r\n at

System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at

System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at

System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()\r\n--- End of stack trace from previous location where

exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at

System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at

System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where

exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at

System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at

System.Web.Http.Controllers.ExceptionFilterResult.d__0.MoveNext()\r\n--- End of stack trace from previous location

where exception was thrown ---\r\n at System.Web.Http.Controllers.ExceptionFilterResult.d__0.MoveNext()\r\n--- End

of stack trace from previous location where exception was thrown ---\r\n at

System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at

System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at

System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}

At D:\releases_temp\25f82d5e-c028-4963-bb72-19067cfc9188.ps1:75 char:5

suwatch commented 4 years ago

try with curl to isolate whether this is powershell specific or site issue.

jckeme-rs commented 2 years ago

Is there any indication as to why access to the applicationHost.xdt file is being denied? I seem to be in a similar situation

 sandboxproc.exe Elapsed = 123.00 ms failed with System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.UnauthorizedAccessException: Access to the path 'C:\home\site\applicationHost.xdt' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
jvano commented 7 months ago

Hi

If the problem persists and is related to running it on Azure App Service, please open a support incident in Azure: https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request

This way we can better track and assist you on this case

Thanks,

Joaquin Vano Azure App Service