Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Vault with docker-compose file

Currently I am using docker-compose file to setup my dev/prod environments. I am using environment variables to store secrets, database credentials etc. After some search, I found out that Vault can be used to secure the credentials. I tried couple of basic examples with vault, but still I have no idea of how to use Vault with a docker-compose file. Can someone point me to a correct way. If Vault is not a good solution with docker-compose, what are the mechanisms I could use to secure credentials rather than storing them in environment as plain text.

like image 259
Rumesh Eranga Hapuarachchi Avatar asked Jul 18 '17 15:07

Rumesh Eranga Hapuarachchi


People also ask

What can I do with Docker compose file?

The Compose file provides a way to document and configure all of the application's service dependencies (databases, queues, caches, web service APIs, etc). Using the Compose command line tool you can create and start one or more containers for each dependency with a single command ( docker-compose up ).

How do you run a vault container?

Running the Vault container with no arguments will give you a Vault server in development mode. The provided entry point script will also look for Vault subcommands and run vault with that subcommand. For example, you can execute docker run vault status and it will run the vault status command inside the container.

Do you need Dockerfiles with Docker compose?

Docker compose uses the Dockerfile if you add the build command to your project's docker-compose. yml. Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.


1 Answers

This is my current docker-compose config for using Vault in dev, but I use dedicated servers (not Docker) in production.

# docker_compose.yml version: '2' services:     myvault:         image: vault         container_name: myvault         ports:           - "127.0.0.1:8200:8200"         volumes:           - ./file:/vault/file:rw           - ./config:/vault/config:rw         cap_add:           - IPC_LOCK         entrypoint: vault server -config=/vault/config/vault.json 

The volume mounts ensure the vault config is saved if you have to rebuild the container.

To use the 'file' backend, to make this setup portable for Docker/Git, you will also need to create a directory called config and put this file into it, named vault.json:

# config/vault.json {   "backend": {"file": {"path": "/vault/file"}},   "listener": {"tcp": {"address": "0.0.0.0:8200", "tls_disable": 1}},   "default_lease_ttl": "168h",   "max_lease_ttl": "0h" } 

Notes:
Although the ROOT_TOKEN is static in this configuration (will not change between container builds), any generated VAULT_TOKEN issued for an app_role will be invalidated every time the vault has to be unsealed.

I have found the Vault sometimes becomes sealed when the container is restarted.

like image 200
StampyCode Avatar answered Sep 21 '22 17:09

StampyCode