我正在使用docker镜像"mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019".我注意到windowsservercore的默认用户是ContainerAdministrator。如果我尝试使用用户ContainerUser (docker run -u ContainerUser w3svc)运行镜像,我会得到以下错误:错误:无法停止或查询服务'w3svc‘的状态错误80070005。我认为该错误与用户运行ServiceMonitor所需的权限有关。那么,首先,假设windowsservercore镜像必须在ContainerAdministrator上运行,而不能在ContainerUser上运行,这样的假设是正确的吗?
如果上面的假设是正确的,我想确认一下,使用ContainerAdministrator运行容器是否会使容器暴露在安全问题中。据我所知,即使ServiceMonitor.exe是用ContainerAdministrator启动的,面向外部的进程也是IIS Windows服务,它在IIS_IUSRS组中的本地帐户下运行。因此,即使攻击者可以破坏应用程序,它也不会拥有容器的管理员访问权限。有没有人能确认这是否正确?
发布于 2021-02-18 17:51:05
ContainerAdministrator是一个特殊的虚拟account.ContainerAdministrator,是你运行容器时的默认账号--所以如果你的命令启动了一个控制台应用,该应用就会以ContainerAdministrator的身份运行。如果你的应用程序在后台作为Windows服务运行,那么该帐户将是服务帐户,因此ASP.NET应用程序在应用程序池帐户下运行。
您可以参考以下链接:
Accessing the Docker host pipe inside windows container with non-admin user
发布于 2021-05-12 18:54:51
我和你处在同样的位置。我不能确认你的假设(尽管我也是这样假设的)。但我可以提供我们的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
https://stackoverflow.com/questions/66247334
复制相似问题