简体   繁体   English

将AWS凭证存储在ECS服务中的位置

[英]Where to store AWS credentials in ECS service

I have an ECS service, which requires AWS credentials. 我有一个ECS服务,该服务需要AWS凭证。 I use ECR to store docker images and jenkins visible only for VPN connections to build images. 我使用ECR来存储docker镜像和jenkins,这些镜像和镜像仅对VPN连接可见。

I see 2 possibilities to provide AWS credentials to the service 我看到两种向服务提供AWS凭证的可能性

  1. Store them as Jenkins secret and insert into the docker image during build 将它们存储为Jenkins机密并在构建期间插入docker映像
  2. Make them a part of the environment when creating ECS Task definition 创建ECS任务定义时使其成为环境的一部分

What is more secure? 什么更安全? Are there other possibilities? 还有其他可能性吗?

First thing, You should not use AWS credentials while working inside AWS, you should assign the role to Task definition or services instead of passing the credentials to docker build or task definition. 首先,在AWS内部工作时,请勿使用AWS凭证,而应将角色分配给Task定义或服务,而不是将凭证传递给docker build或task定义。

With IAM roles for Amazon ECS tasks, you can specify an IAM role that can be used by the containers in a task. 借助用于Amazon ECS任务的IAM角色,您可以指定任务中的容器可以使用的IAM角色。 Applications must sign their AWS API requests with AWS credentials, and this feature provides a strategy for managing credentials for your applications to use, similar to the way that Amazon EC2 instance profiles provide credentials to EC2 instances 应用程序必须使用AWS凭证对他们的AWS API请求进行签名,并且此功能提供了一种策略来管理您的应用程序使用的凭证,类似于Amazon EC2实例配置文件向EC2实例提供凭证的方式

So sometimes the underlying application is not designed in a way that can use role so in this I will recommend storing ENV in the task definition but again from where to get the value of ENV? 因此,有时底层应用程序的设计方式并不适合使用角色,因此在此我建议将ENV存储在任务定义中,但还是从哪里获取ENV的值呢?

Task definition support two methods to deal with ENV, 任务定义支持两种处理ENV的方法,

  • Plain text as direct value 纯文本作为直接值
  • Use 'valueFrom' attribute for ECS task definition 将'valueFrom'属性用于ECS任务定义

The following is a snippet of a task definition showing the format when referencing an Systems Manager Parameter Store parameter . 以下是任务定义的摘要,显示了引用Systems Manager参数存储参数时的格式。

{
  "containerDefinitions": [{
    "secrets": [{
      "name": "environment_variable_name",
      "valueFrom": "arn:aws:ssm:region:aws_account_id:parameter/parameter_name"
    }]
  }]
}

This is the most secure and recommended method by AWS documentation so this is the better way as compared to ENV in plain text inside Task definition or ENV in Dockerfile. 这是AWS文档中最安全和推荐的方法,因此,与Task Definition内的纯文本格式的ENV或Dockerfile中的ENV相比,这是更好的方法。

You can read more here and systems-manager-parameter-store . 您可以在此处systems-manager-parameter-store中阅读更多内容。

But to use these you will must provide permission to task definition to access systems-manager-parameter-store. 但是要使用这些功能,您必须提供对任务定义的访问权限,以访问systems-manager-parameter-store。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM