DevOps 部署后访问 wwwroot 被拒绝

Access denied on wwwroot after DevOps deployment

我已经使用 Azure DevOps 将 .Net Core Web 应用程序部署到 Azure App Service。现在,当我尝试使用 Kudu 在 'D:\home\site\wwwroot' 中创建文件时,它说:

409 Conflict: Could not write to local resource 'D:\home\site\wwwroot\anc' >due to error 'Could not find file 'D:\home\site\wwwroot\anc'.'.

我注意到 'D:\home\site\wwwroot' 目录的权限与我使用 Publish Profile

部署的类似 Web 应用程序不同

有问题的应用程序的 Get-Acl 结果:

PS D:\home\site\wwwroot> Get-Acl "D:\home\site\wwwroot"
Get-Acl "D:\home\site\wwwroot"




    Directory: D:\home\site





Path    Owner                   Access                                         

----    -----                   ------                                         

wwwroot IIS APPPOOL\luncher-dev NT AUTHORITY\SYSTEM Allow  FullControl...      


在其他类似应用程序上获取 Acl 结果:

PS D:\home\site\wwwroot> Get-Acl "D:\home\site\wwwroot"
Get-Acl "D:\home\site\wwwroot"




    Directory: D:\home\site





Path    Owner                  Access                                          

----    -----                  ------                                          

wwwroot BUILTIN\Administrators Everyone Allow  DeleteSubdirectoriesAndFiles,...


来自 Azure DevOps 的相应发布管道

如何使 wwwroot 目录可写?

Do not write

当你在云端时,任何文件到 wwwroot。 因为 Azure 可以更改您的 machine/server 并且他们只会移动您的发布 gfiles。不是您在发布后添加的文件。所以你会失去他们。

当您部署为 zip 时,您无法编辑文件系统。

下面引用自https://tomasherceg.com/blog/post/azure-app-service-cannot-create-directories-and-write-to-filesystem-when-deployed-using-azure-devops

我完全不知道这个功能,而且这个设置隐藏在VSTS任务中,所以我没有注意到。您需要展开 Additional Deployment Options 部分并单击 Select deployment method 复选框,默认情况下该复选框是未选中的。点了这两次之后,你就可以看到部署方式的下拉了——ZipDeploy是默认的。

我需要将其更改为使用 WebDeploy,这样应用程序文件将作为普通文件存储,并且应用程序可以像以前一样在文件系统中写入。

遇到了同样的问题,我花了很长时间才弄明白。

参见link:https://theazureissues.blogspot.com/2019/04/409-conflict-could-not-write-to-local.html

The application setting ‘WEBSITE_RUN_FROM_PACKAGE=1’ of the App Service makes the wwwroot folder of the application as read-only.

我只是将其设置为 0,重新启动我的应用程序,然后一切恢复正常。

我找到另一个 link: https://azureappservices.blogspot.com/2018/06/unable-to-editdelete-files-through-kudu.html 它处理特定的文件属性,但是,从 devops 部署后我什至无法编辑属性。所以我相信这是对被标记为只读的特定文件的修复。

检查此 link:https://tomasherceg.com/blog/post/azure-app-service-cannot-create-directories-and-write-to-filesystem-when-deployed-using-azure-devops 也可能是

WEBSITE_RUN_FROM_ZIP

应用设置。 (这不是我的问题)

更改此应用程序设置密钥

WEBSITE_RUN_FROM_PACKAGE = 1 to 0

此设置使 wwwroot 成为只读文件系统。

对于 运行 From Package,这是严格执行的,因为 wwwroot 文件夹变为只读