Search code examples
amazon-ecs

Best practice for getting RDS password to docker container on ECS


I am using Postgres Amazon RDS and Amazon ECS for running my docker containers. The question is. What is the best practice for getting the username and password for the RDS database into the docker container running on ECS?

I see a few options:

  • Build the credentials into docker image. I don't like this since then everyone with access to the image can get the password.
  • Put the credentials in the userdata of the launch configuration used by the autoscaling group for ECS. With this approach all docker images running on my ECS cluster has access to the credentials. I don't really like that either. That way if a blackhat finds a security hole in any of my services (even services that does not use the database) he will be able to get the credentials for the database.
  • Put the credentials in a S3 and control the limit the access to that bucket with a IAM role that the ECS server has. Same drawbacks as putting them in the userdata.
  • Put the credentials in the Task Definition of ECS. I don't see any drawbacks here.

What is your thoughts on the best way to do this? Did I miss any options?

regards, Tobias


Solution

  • Building it into the container is never recomended. Makes it hard to distribute and change.

    Putting it into the ECS instances does not help your containers to use it. They are isolated and you'd end up with them on all instances instead of just where the containers are that need them.

    Putting them into S3 means you'll have to write that functionality into your container. And it's another place to have configuration.

    Putting them into your task definition is the recommended way. You can use the environment portion for this. It's flexible. It's also how PaaS offerings like Heroku and Elastic Beanstalk use DB connection strings for Ruby on rails and other services. Last benefit is it makes it easy to use your containers against different databases (like dev, test, prod) without rebuilding containers or building weird functionality