Docker的Windows容器文件访问权限问题

Windows Server 2016主机,通过默认的MSFTdocker提供程序运行Docker EE。

Docker版本17.06.2-ee-5,build 508bb92

docker-compose版本1.17.1,build 6d101fb0

我有一个基于microsoft/windowsservercore:latest的Windows容器microsoft/windowsservercore:latest ,并试图为Bamboo服务器设置图像。 在创build构build计划的过程中,服务器生成一个密码来在Bamboo和Bitbucket之间进行通信。 在运行的容器中,密码文件夹/文件生成失败,出现以下错误:

 java.nio.file.AccessDeniedException: C:\bamboo-home\xml-data\configuration\cipher\cipher.key_0 

我已经尝试了卷C:\bamboo-home这两个附加到我的Windows主机,并完全包含在容器内。 两次同样的错误。

Windows容器以名为“containeradministrator”的pipe理员帐户运行; 在默认图像和使用入口点时都是如此,如下所示。

标准图像运行:

 PS C:\> docker run -it microsoft/windowsservercore:latest powershell Windows PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved. PS C:\> whoami user manager\containeradministrator 

并在定制的图像上testing入口点:

 PS C:\test> docker-compose build Building testentrypoint Step 1/2 : FROM microsoft/windowsservercore:latest ---> 2cddde20d95d Step 2/2 : ENTRYPOINT whoami ---> Running in 7fe31f02e45f ---> 60822e1907f1 Removing intermediate container 7fe31f02e45f Successfully built 60822e1907f1 Successfully tagged test/entrypoint:latest PS C:\test> docker-compose up Creating network "test_default" with the default driver Creating test_testentrypoint_1 ... Creating test_testentrypoint_1 ... done Attaching to test_testentrypoint_1 testentrypoint_1 | user manager\containeradministrator test_testentrypoint_1 exited with code 0 

这个用户是pipe理员的一个别名,我可以告诉他,虽然有趣的是它不会在net user显示为这个名字:

 PS C:\> net user User accounts for \\ ------------------------------------------------------------------------------- Administrator DefaultAccount Guest The command completed with one or more errors. 

所以这可能是一个问题,但是无论如何,用户具有完全的pipe理权限,我可以告诉:

 PS C:\> $user = [Security.Principal.WindowsIdentity]::GetCurrent() PS C:\> $user AuthenticationType : Negotiate ImpersonationLevel : None IsAuthenticated : True IsGuest : False IsSystem : False IsAnonymous : False Name : User Manager\ContainerAdministrator Owner : S-1-5-93-2-1 User : S-1-5-93-2-1 Groups : {S-1-1-0, S-1-5-32-545, S-1-5-6, S-1-2-1...} Token : 3052 AccessToken : Microsoft.Win32.SafeHandles.SafeAccessTokenHandle UserClaims : {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: User Manager\ContainerAdministrator, http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid: S-1-5-93-2-1, http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-1-0, http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-5-32-545...} DeviceClaims : {} Claims : {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: User Manager\ContainerAdministrator, http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid: S-1-5-93-2-1, http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-1-0, http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-5-32-545...} Actor : BootstrapContext : Label : NameClaimType : http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name RoleClaimType : http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid PS C:\> (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) True 

所以我已经尝试了以下内容:

  1. 在容器中运行构build步骤,将文件夹权限设置为“Everyone – 完全访问”

  2. 在启动时,在运行的容器中手动运行该脚本,执行相同的操作

  3. 运行时连接到容器,然后手动运行powershell来执行相同的操作

每次尝试生成密文文件之前,权限如下所示:

 PS C:\> Get-ACL C:\bamboo-home\xml-data\configuration\ | fl Path : Microsoft.PowerShell.Core\FileSystem::C:\bamboo-home\xml-data\configuration\ Owner : User Manager\ContainerAdministrator Group : User Manager\ContainerAdministrator Access : Everyone Allow FullControl NT AUTHORITY\SYSTEM Allow FullControl BUILTIN\Administrators Allow FullControl S-1-5-21-2465844383-291681238-1546083700-500 Allow FullControl Audit : Sddl : O:S-1-5-93-2-1G:S-1-5-93-2-1D:AI(A;OICIID;FA;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;S-1-5-21-2465844383-291681238-1546083700-500) 

上面的错误发生在尝试生成后,权限更改为:

 PS C:\> Get-ACL C:\bamboo-home\xml-data\configuration\ | fl Path : Microsoft.PowerShell.Core\FileSystem::C:\bamboo-home\xml-data\configuration\ Owner : User Manager\ContainerAdministrator Group : User Manager\ContainerAdministrator Access : Everyone Allow FullControl Audit : Sddl : O:S-1-5-93-2-1G:S-1-5-93-2-1D:AI(A;OICI;FA;;;WD) 

为什么默认帐户(大概是名为containeradministrator的pipe理员)在似乎表明它拥有所有权时,将无法访问此目录? 为什么不能创build文件(或文件夹,首先,因为在这两种情况下,“每个人”应该有完全的访问?

我没有确定主机/容器权限之间的问题,但我提出容器的方式允许问题发生。 通过改变我的设置过程,我能够纠正这一点。

初始创build(在创build的文件夹上失败的权限):

  1. 在主机上创build空白文件夹。
  2. 作为容量链接到容器的内部文件夹(在这种情况下,所有C:\ bamboo-home)。 这是Bamboo将放置所有configuration/工作区内容的文件夹。
  3. 设置容器内的产品,除密码文件夹失败外,一切正常。 直到这一步才注意到问题。

新的创作(工作正常):

  1. 在主机上创build空白文件夹。
  2. 链接成卷与容器内部文件夹(C:\ empty,在这种情况下)。 这不会链接到C:\ bamboo-home,它将根据需要在正在运行的容器内部生成。
  3. 在容器中设置产品。 完成后,将容器文件夹中的所有文件复制到新build的空白文件夹中。 这样,在容器内部以一致的方式设置权限,减轻了之前的问题。