为 Windows 容器使用 gMSA
Amazon ECS 通过组 Managed Service Account (gMSA )的特殊服务帐户支持 Windows 容器的 Active Directory 身份验证。
基于 Windows 的网络应用程序(例如 .NET 应用程序)通常使用 Active Directory 来促进用户和服务之间的身份验证和授权管理。开发人员通常将其应用程序设计为与 Active Directory 集成,并为此在加入域的服务器上运行。由于 Windows 容器无法加入域,因此必须将 Windows 容器配置为使用 gMSA 运行。
使用 gMSA 运行的 Windows 容器依赖于其主机 Amazon EC2 实例从 Active Directory 域控制器检索 gMSA 凭据并将其提供给容器实例。有关详细信息,请参阅为 Windows 容器创建 gMSA
注意
Fargate 上的 Windows 容器不支持此功能。
注意事项
为 Windows 容器使用 gMSA 时,应考虑以下因素:
-
为容器实例使用经 Amazon ECS 优化的 Windows Server 2016 Full AMI 时,容器主机名必须与凭证规范文件中定义的 gMSA 账户名相同。要为容器指定主机名,请使用
hostname
容器定义参数。有关更多信息,请参阅Network settings (网络设置)。
先决条件
以下是在 Amazon ECS 上为 Windows 容器使用 gMSA 功能的先决条件。
-
您的 Amazon ECS Windows 容器实例可以加入的 Active Directory。Amazon ECS 支持以下内容:
-
Amazon Directory Service,托管在 Amazon EC2 上的 Amazon 托管 Active Directory。有关更多信息,请参阅 Amazon Directory Service 管理指南中的 Amazon 托管 Microsoft AD 入门。
-
本地部署的 Active Directory,只要 Amazon ECS Windows 容器实例可以加入域。有关更多信息,请参阅Amazon Direct Connect。
-
-
Active Directory 中的现有 gMSA 账户。有关详细信息,请参阅为 Windows 容器创建 gMSA
。 -
托管 Amazon ECS 任务的 Amazon ECS Windows 容器实例必须是加入到 Active Directory 的域,并且是有权访问 gMSA 账户的 Active Directory 安全组的成员。
在 Amazon ECS 上设置支持 gMSA 的 Windows 容器
Amazon ECS 使用一个凭证规范文件,该文件包含用于将 gMSA 账户上下文传播到 Windows 容器的 gMSA 元数据。您可以生成凭证规范文件并在任务定义的 dockerSecurityOptions
字段中引用该文件。凭证规范文件不包含任何密钥。
下面是一个示例凭证规范文件:
{
"CmsPlugins": [
"ActiveDirectory"
],
"DomainJoinConfig": {
"Sid": "S-1-5-21-2554468230-2647958158-2204241789",
"MachineAccountName": "WebApp01",
"Guid": "8665abd4-e947-4dd0-9a51-f8254943c90b",
"DnsTreeName": "example.com",
"DnsName": "example.com",
"NetBiosName": "example"
},
"ActiveDirectoryConfig": {
"GroupManagedServiceAccounts": [
{
"Name": "WebApp01",
"Scope": "example.com"
}
]
}
}
在任务定义中引用凭证规范文件
Amazon ECS 支持使用以下方法在任务定义的 dockerSecurityOptions
字段中引用文件路径。
Amazon S3 存储桶
将凭证规范添加到 Amazon S3 存储桶,然后在任务定义的 dockerSecurityOptions
字段中引用 Amazon S3 存储桶的 Amazon Resource Name (ARN)。
{ "family": "", "executionRoleArn": "", "containerDefinitions": [ { "name": "", ... "dockerSecurityOptions": [ "credentialspec:arn:aws:s3:::
${BucketName}/${ObjectName}
" ], ... } ], ... }
为了让您的任务可以访问 Amazon S3 存储桶,您还必须将以下权限作为内联策略添加到 Amazon ECS 任务执行 IAM 角色。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor", "Effect": "Allow", "Action": [ "s3:Get*", "s3:List*" ], "Resource": [ "arn:aws:s3:::
{bucket_name}
", "arn:aws:s3:::{bucket_name}/{object}
" ] } ] }
SSM Parameter Store 参数
将凭证规范添加到 SSM Parameter Store 参数,然后在任务定义的 dockerSecurityOptions
字段中引用 SSM Parameter Store 参数的 Amazon Resource Name (ARN)。
{ "family": "", "executionRoleArn": "", "containerDefinitions": [ { "name": "", ... "dockerSecurityOptions": [ "credentialspec:arn:aws:ssm:
region
:111122223333
:parameter/parameter_name
" ], ... } ], ... }
为了让您的任务可以访问 SSM Parameter Store 参数,您还必须将以下权限作为内联策略添加到 Amazon ECS 任务执行 IAM 角色。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ssm:GetParameters" ], "Resource": [ "arn:aws:ssm:
region
:111122223333
:parameter/parameter_name
" ] } ] }
本地文件
使用本地文件中的凭证规范详细信息,在任务定义的 dockerSecurityOptions
字段中引用文件路径。引用的文件路径必须是相对于 C:\ProgramData\Docker\CredentialSpecs
目录的路径。
{ "family": "", "executionRoleArn": "", "containerDefinitions": [ { "name": "", ... "dockerSecurityOptions": [ "credentialspec:file://
CredentialSpecFile.json
" ], ... } ], ... }