g3w-suite / g3w-suite-docker

Run G3W-SUITE stack with docker-compose
https://g3w-suite.readthedocs.io/en/latest/docker.html
31 stars 33 forks source link

Manage sensitive data with Docker secrets #71

Open Raruto opened 2 years ago

Raruto commented 2 years ago

As per v3.4, the following passwords are injected by the host as environment variables:


Ref: https://blog.diogomonica.com//2017/03/27/why-you-shouldnt-use-env-variables-for-secret-data/


When you store your secret keys in an environment variable, you are prone to accidentally exposing them—exactly what we want to avoid. Here are a few reasons why ENV variables are bad for secrets:

Overall, secrets in ENV variables break the principle of least surprise, are a bad practice, and will lead to the eventual leak of secrets.


Ref: https://docs.docker.com/engine/swarm/secrets/#use-secrets-in-compose


This example creates a simple WordPress site using two secrets in a compose file:

More information on short and long syntax for secrets can be found at Compose file version 3 reference.

version: "3.9"

services:
   db:
     image: mysql:latest
     volumes:
       - db_data:/var/lib/mysql
     environment:
       MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password   # <-- MYSQL_ROOT_PASSWORD
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD_FILE: /run/secrets/db_password             # <-- MYSQL_PASSWORD
     secrets:
       - db_root_password
       - db_password

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD_FILE: /run/secrets/db_password      # <-- WORDPRESS_DB_PASSWORD
     secrets:
       - db_password

secrets:
   db_password:
     file: db_password.txt
   db_root_password:
     file: db_root_password.txt

volumes:
    db_data: