我正在寻找一种将机密/证书注入 Amazon ECS 容器的方法。就我而言,它是一个简单的 nginx 容器。
我一直在使用 AWS Parameter Store 关注这篇文章:https://aws.amazon.com/blogs/compute/managing-secrets-for-amazon-ecs-applications-using-parameter-store-and-iam-roles-for-tasks/ https://aws.amazon.com/blogs/compute/managing-secrets-for-amazon-ecs-applications-using-parameter-store-and-iam-roles-for-tasks/
这是基本要点:
- 在我的 Dockerfile 上,我附加了一个脚本入口点它会安装 AWS 客户端并从 AWS 参数存储中获取密钥。
Dockerfile
FROM nginx:1.16.0
...
ENTRYPOINT ["/var/run/fetch.sh", "nginx", "-g", "daemon off;"]
fetch.sh
aws ssm get-parameter \
--name ${key} \
--with-decryption \
--region us-east-1 \
--output text \
--query Parameter.Value
- 任务定义假定有权访问所需服务(kms + 参数存储)的 IAM 角色。我可以验证它是否有效,因为如果我通过 ssh 连接到服务器并在容器上运行脚本,我就可以从 Parameter Store 中获取密钥。
{
"portMappings": [
{
"hostPort": 0,
"protocol": "tcp",
"containerPort": 443
}
],
"cpu": 0,
"environment": [],
"mountPoints": [],
"memoryReservation": 256,
"memory": 512,
"volumesFrom": [],
"image": "url/some_image:latest",
"essential": true,
"name": "my-container"
}
- 当 ECS 运行此任务时,它应该会命中入口点它从参数存储中获取密钥并保存它们。
我可以通过 docker exec 手动运行来获取正在运行的任务的密钥,但在启动任务时无法获取它们(特别是当我将脚本附加到入口点时,如上面的代码所示)。
ECS 任务是否有权访问入口点的 IAM 角色?它何时真正承担 IAM 角色?