【问题标题】:Obtain credentials to an ECS with IAM role获取具有 IAM 角色的 ECS 的凭证
【发布时间】:2021-11-01 19:18:02
【问题描述】:

尝试使用 IAM 角色测试一种无需硬编码凭据即可获取 ECS 任务凭据的方法

创建了一个虚拟 python 应用程序来检索秘密并返回它,例如:

{
username: "x",
password: "x",
engine: "postgres",
host: "x",
port: 5432,
dbInstanceIdentifier: "x"
}

Dockerfile(要求添加)

FROM python:3.8-slim-buster
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY app2.py .
RUN chmod +x /app/app2.py
CMD [ "python3", "/app/app2.py"]

我得到错误:

当我 ssh 任务 ec2 并记录容器时,每个任务都会立即失败:

standard_init_linux.go:211: exec user process caused "exec format error"

创建了任务定义并使用了正确的任务角色

Task role
devops-TestRole

IAM 角色(AWS 服务:ecs-tasks):

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ecr:GetAuthorizationToken",
                "ecr:BatchCheckLayerAvailability",
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": "*"
        }

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "secretsmanager:GetSecretValue",
                "kms:Decrypt"
            ],
            "Resource": [
                "arn:aws:secretsmanager:x:x:secret:x",
                "arn:aws:kms:x:x:key/x"
            ]
        }
    ]
}

谢谢!!

【问题讨论】:

  • 你能分享你用来构建镜像的 Dockerfile 吗?
  • 确定!生病将它添加到我的问题。只是为了清楚,它在向我添加卷时在本地工作 ~/.aws/credentials 文件夹

标签: python amazon-web-services amazon-iam amazon-ecs aws-secrets-manager


【解决方案1】:

找到了解决办法。

正如这里提到的 Link,可能是不同芯片造成的(使用arm64-M1)

二手

docker build --platform linux/amd64 -t devops-tests .

它修复了它!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-07
    • 2016-05-20
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    相关资源
    最近更新 更多