How can I pass secret data to a container

后端 未结 2 2057
自闭症患者
自闭症患者 2021-02-10 07:01

My Tomcat Container needs data that has to be well protected, i.e. passwords for database access and certificates and keys for Single Sign On t

相关标签:
2条回答
  • 2021-02-10 07:33

    Update January 2017

    Docker 1.13 now has the command docker secret with docker swarm.
    See also "Why is ARG in a DOCKERFILE not recommended for passing secrets?".


    Original answer (Sept 2015)

    The notion of docker vault, alluded to by Adrian Mouat in his previous answer, was actively discussed in issue 1030 (the discussion continues on issues 13490).

    It was for now rejected as being out of scope for docker, but also included:

    We've come up with a simple solution to this problem: A bash script that once executed through a single RUN command, downloads private keys from a local HTTP server, executes a given command and deletes the keys afterwards.

    Since we do all of this in a single RUN, nothing gets cached in the image. Here is how it looks in the Dockerfile:

    RUN ONVAULT npm install --unsafe-perm
    

    Our first implementation around this concept is available at dockito/vault.

    To develop images locally we use a custom development box that runs the Dockito Vault as a service.

    The only drawback is requiring the HTTP server running, so no Docker hub builds.

    0 讨论(0)
  • 2021-02-10 07:55

    Mount the encrypted keys into container, then pass the password via pipe. The difficulty comes with the detach mode, which will hang while reading the pipe within the container. Here is a trick to work around:

    cid=$(docker run -d -i alpine sh -c 'read A; echo "[$A]"; exec some-server')
    docker exec -i $cid sh -c 'cat > /proc/1/fd/0' <<< _a_secret_
    

    First, create the docker daemon with -i option, the command read A will hang waiting for the input from /proc/1/fd/0; Then run the second docker command, reading the secret from stdin and redirect to the last hanging process.

    0 讨论(0)
提交回复
热议问题