7

I have my app inside a container and it's reading environment variables for passwords and API keys to access services. If I run the app on my machine (not inside docker), I just export SERVICE_KEY='wefhsuidfhda98' and the app can use it.

What's the standard approach to this? I was thinking of having a secret file which would get added to the server with export commands and then run a source on that file.

I'm using docker & fig.

duality_
  • 17,738
  • 23
  • 77
  • 95

2 Answers2

5

The solution I settled on was the following: save the environment variables in a secret file and pass those on to the container using fig.

  • have a secret_env file with secret info, e.g.

    export GEO_BING_SERVICE_KEY='98hfaidfaf'
    export JIRA_PASSWORD='asdf8jriadf9'
    
  • have secret_env in my .gitignore
  • have a secret_env.template file for developers, e.g.

    export GEO_BING_SERVICE_KEY=''  # can leave empty if you wish
    export JIRA_PASSWORD=''  # write your pass
    
  • in my fig.yml I send the variables through:

    environment:
     - GEO_BING_SERVICE_KEY
     - JIRA_PASSWORD
    
  • call source secret_env before building
duality_
  • 17,738
  • 23
  • 77
  • 95
4

docker run provides environment variables:

docker run -e SERVICE_KEY=wefsud your/image

Then your application would read SERVICE_KEY from the environment.
https://docs.docker.com/reference/run/

In fig, you'd use

environment:
  - SERVICE_KEY: wefsud

in your app spec. http://www.fig.sh/yml.html

From a security perspective, the former solution is no worse than running it on your host if your docker binary requires root access. If you're allowing 'docker' group users to run docker, it's less secure, since any docker user could docker inspect the running container. Running on your host, you'd need to be root to inspect the environment variables of a running process.

seanmcl
  • 9,740
  • 3
  • 39
  • 45
  • I would add a note that since your fig.yml is normally checked into source control and you should not commit secrets into source control it may be good to generate your fig.yml on the fly from a template. – Usman Ismail Dec 18 '14 at 15:00