【问题标题】:Non-root user not able to start w3svc service in docker非 root 用户无法在 docker 中启动 w3svc 服务
【发布时间】:2021-05-20 15:50:11
【问题描述】:

我正在使用 docker 映像“mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019”。我注意到 windowsservercore 的默认用户是 ContainerAdministrator。如果我尝试使用用户 ContainerUser (docker run -u ContainerUser mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019) 运行映像,则会收到以下错误:错误:无法停止或查询服务“w3svc”错误 [80070005]。 我认为该错误与用户运行ServiceMonitor所需的权限有关。那么,首先,假设windowsservercore镜像必须用ContainerAdministrator运行,不能用ContainerUser运行是否正确?

如果上述假设是正确的,我想确认使用 ContainerAdministrator 运行容器是否会使容器面临安全问题。据我了解,即使 ServiceMonitor.exe 是使用 ContainerAdministrator 启动的,面向外部的进程也是 IIS Windows 服务,它在 IIS_IUSRS 组中的本地帐户下运行。因此,即使攻击者可以破坏应用程序,它也不会拥有对容器的管理员访问权限。谁能确认这是否正确?

【问题讨论】:

    标签: asp.net .net docker iis


    【解决方案1】:

    ContainerAdministrator 是一个特殊的虚拟帐户。ContainerAdministrator 是您运行容器时的默认帐户 - 因此,如果您的 CMD 指令启动控制台应用程序,该应用程序将作为 ContainerAdministrator 运行。如果您的应用作为 Windows 服务在后台运行,则该帐户将是服务帐户,因此 ASP.NET 应用在应用程序池帐户下运行。

    您可以参考以下链接:

    Accessing the Docker host pipe inside windows container with non-admin user

    【讨论】:

      【解决方案2】:

      我和你一样。我无法证实您的假设(尽管我假设相同)。但我可以提供我们的 dockerfile,它使我们能够以非 root 身份运行(以遵守 AKS 政策)。

      dockerfile

      FROM mcr.microsoft.com/dotnet/framework/wcf:4.8-windowsservercore-ltsc2019
      
      SHELL ["cmd", "/S", "/C"]
      # username = '1000' so the k8s policy can verify it's a non-root user
      RUN net user /add 1000
      # We copy some config files in the actual startup.ps1 so we need write access here
      RUN icacls C:\inetpub\wwwroot\ /grant 1000:(OI)(CI)F /t
      # ServiceMonitor.exe puts some environment variables in the applicationHost.config
      RUN icacls C:\Windows\System32\inetsrv\Config\ /grant 1000:(OI)(CI)F /t /c
      
      # S-1-5-32-545 is group Builtin\Users which contains user 1000. Allows user to restart the w3svc service
      RUN sc.exe sdset w3svc D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)    (A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)(A;;RPWPDTLO;;;S-1-5-32-545)
      
      COPY startup.ps1 /
      
      WORKDIR /inetpub/wwwroot
      ARG source=obj/Docker/publish
      COPY ${source} .
      USER 1000
      
      ENTRYPOINT ["powershell", "/startup.ps1"]
      

      startup.ps1

      # ContainerAdministrators doesn't have these variables, but the
      # custom account does have them. If this gets put into the applicationHost.config
      # iis will try to write to the user specific temp directory, and fail (with an unrelated error)
      Remove-Item env:TMP
      Remove-Item env:TEMP
      C:/ServiceMonitor.exe w3svc
      

      【讨论】:

        猜你喜欢
        • 2015-04-29
        • 1970-01-01
        • 1970-01-01
        • 2023-01-04
        • 2022-12-16
        • 2018-01-13
        • 2018-04-20
        • 1970-01-01
        • 2020-06-30
        相关资源
        最近更新 更多