Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

mysql - Hide/obfuscate environmental parameters in docker

I'm using the mysql image as an example, but the question is generic.

The password used to launch mysqld in docker is not visible in docker ps however it's visible in docker inspect:

sudo docker run --name mysql-5.7.7 -e MYSQL_ROOT_PASSWORD=12345 -d mysql:5.7.7

CONTAINER ID        IMAGE               COMMAND                   CREATED             STATUS              PORTS               NAMES
b98afde2fab7        mysql:5.7.7         "/entrypoint.sh mysq   6 seconds ago       Up 5 seconds        3306/tcp            mysql-5.7.7

sudo docker inspect b98afde2fab75ca433c46ba504759c4826fa7ffcbe09c44307c0538007499e2a

"Env": [
        "MYSQL_ROOT_PASSWORD=12345",
        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
        "MYSQL_MAJOR=5.7",
        "MYSQL_VERSION=5.7.7-rc"
    ]

Is there a way to hide/obfuscate environment parameters passed when launching containers. Alternatively, is it possible to pass sensitive parameters by reference to a file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Weirdly, I'm just writing an article on this.

I would advise against using environment variables to store secrets, mainly for the reasons Diogo Monica outlines here; they are visible in too many places (linked containers, docker inspect, child processes) and are likely to end up in debug info and issue reports. I don't think using an environment variable file will help mitigate any of these issues, although it would stop values getting saved to your shell history.

Instead, you can pass in your secret in a volume e.g:

$ docker run -v $(pwd)/my-secret-file:/secret-file ....

If you really want to use an environment variable, you could pass it in as a script to be sourced, which would at least hide it from inspect and linked containers (e.g. CMD source /secret-file && /run-my-app).

The main drawback with using a volume is that you run the risk of accidentally checking the file into version control.

A better, but more complicated solution is to get it from a key-value store such as etcd (with crypt), keywhiz or vault.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...