使用 gMSA 运行容器
适用于:Windows Server 2025、Windows Server 2022、Windows Server 2019
若要使用组托管服务帐户(gMSA)运行容器,请向 docker run的 --security-opt
参数提供凭据规范文件:
docker run --security-opt "credentialspec=file://contoso_webapp01.json" --hostname webapp01 -it mcr.microsoft.com/windows/server:ltsc2022 powershell
重要
在 Windows Server 2016 版本 1709 和 1803 上,容器的主机名必须与 gMSA 短名称匹配。
在前面的示例中,gMSA SAM 帐户名称 webapp01,因此容器主机名也 webapp01命名。
在 Windows Server 2019 及更高版本中,不需要主机名字段,但容器仍会通过 gMSA 名称而不是主机名来标识自身,即使显式提供其他名称也是如此。
若要检查 gMSA 是否正常工作,请在容器中运行以下 cmdlet:
# Replace contoso.com with your own domain
PS C:\> nltest /sc_verify:contoso.com
Flags: b0 HAS_IP HAS_TIMESERV
Trusted DC Name \\dc01.contoso.com
Trusted DC Connection Status Status = 0 0x0 NERR_Success
Trust Verification Status = 0 0x0 NERR_Success
The command completed successfully
如果受信任的 DC 连接状态和信任验证状态不是 NERR_Success
,请按照 故障排除说明 来调试问题。
可以通过运行以下命令并检查客户端名称,从容器中验证 gMSA 标识:
PS C:\> klist get webapp01
Current LogonId is 0:0xaa79ef8
A ticket to krbtgt has been retrieved successfully.
Cached Tickets: (2)
#0> Client: webapp01$ @ CONTOSO.COM
Server: krbtgt/webapp01 @ CONTOSO.COM
KerbTicket Encryption Type: AES-256-CTS-HMAC-SHA1-96
Ticket Flags 0x40a10000 -> forwardable renewable pre_authent name_canonicalize
Start Time: 3/21/2019 4:17:53 (local)
End Time: 3/21/2019 14:17:53 (local)
Renew Time: 3/28/2019 4:17:42 (local)
Session Key Type: AES-256-CTS-HMAC-SHA1-96
Cache Flags: 0
Kdc Called: dc01.contoso.com
[...]
若要以 gMSA 帐户的形式打开 PowerShell 或其他控制台应用,可以要求容器在网络服务帐户下运行,而不是普通 ContainerAdministrator(或 ContainerUser for NanoServer)帐户:
# NOTE: you can only run as Network Service or SYSTEM on Windows Server 1709 and later
docker run --security-opt "credentialspec=file://contoso_webapp01.json" --hostname webapp01 --user "NT AUTHORITY\NETWORK SERVICE" -it mcr.microsoft.com/windows/servercore:ltsc2019 powershell
当你以网络服务身份运行时,可以通过尝试以 gMSA 身份在域控制器上连接到 SYSVOL 来测试网络身份验证。
# This command should succeed if you're successfully running as the gMSA
PS C:\> dir \\contoso.com\SYSVOL
Directory: \\contoso.com\sysvol
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----l 2/27/2019 8:09 PM contoso.com
相关内容
除了运行容器之外,还可以使用 gMSA 来:
如果在安装过程中遇到任何问题,请查看我们的 故障排除指南 以获得可能的解决方案。