Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a better way to pass the password to the container #111

Closed
bladnor opened this issue Jan 2, 2016 · 8 comments
Closed

Provide a better way to pass the password to the container #111

bladnor opened this issue Jan 2, 2016 · 8 comments

Comments

@bladnor
Copy link

bladnor commented Jan 2, 2016

I don't like setting the password with an environment variable because environment variables can be viewed with 'docker inspect'. Can you provide a way to pass the password by mounting a file to the container and read the password from that file?

For example something like this:
$cat secret
export POSTGRES_PASSWORD=mysecretpostgrespassword
$ sudo docker run -v $(pwd):/tmp --name some-postgres -d postgres

and then in docker-entrypoint.sh read/source the password from /tmp/secret .

Thank you

PS:
I tried to do something like this:
$sudo docker run -v $(pwd):/tmp --entrypoint /bin/bash --name some-postgres -d postgres "source /tmp/secret >> docker-entrypoint.sh"

but this resulted in:
/bin/bash: source /tmp/secret >> docker-entrypoint.sh: No such file or directory

@jdmarshall
Copy link

I'm having the same concern.

Unfortunately in researching it I think I have learned that this issue was formally identified in Docker itself back in May of last year and is still not a solved problem.

@mmarzantowicz
Copy link
Contributor

Allowing malicious users to run docker inspect (or generally docker ...) command is already a security breach so there is no gain in hiding password form environment other than over-engineering.

PostgreSQL supports GSSAPI and Kerberos authentication which can be used if you really need more complex access management.

@tianon
Copy link
Member

tianon commented Aug 29, 2016

I think it would be worthwhile to add a note to the documentation for POSTGRES_PASSWORD pointing out that users concerned about security ought to change this initial password after the database is initialized, perhaps with a short example of the easiest/quickest way to do so.

@jdmarshall
Copy link

jdmarshall commented Aug 29, 2016

There are other applications besides Postgres that need credentials.

Postgres is sort of a touchy subject from a Docker standpoint anyway. The combined awkwardness of the data volume solution, lazy initialization of the database which ensues, avoiding nuking your data, especially in dev and integration, race conditions caused by this with docker-compose and a handful of others that I'm forgetting...

I ended up creating my own initialization scripts which I ran offline that would spool up just psql, initialize the database, create my users (read and read-write), change the default password and optionally import a database backup, which I run separately from my code-build-test and build-deploy-test cycles. (this was a godsend when it came time to test migration scripts)

@tianon
Copy link
Member

tianon commented Jan 19, 2017

I think #225 should be helpful here.

@phs
Copy link

phs commented Apr 10, 2017

TL;DR If you are using a swarm:

version: "3.1"
services:

  database:
    image: postgres:9.6
    environment:
      POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
    secrets:
      - postgres_password

secrets:
  postgres_password:
    external: true

@tianon
Copy link
Member

tianon commented Apr 10, 2017

Ah, thanks for the prod (and the example config), @phs! I'm going to close since this was implemented in #225 with the _FILE environment variables. 👍

@shadiakiki1986
Copy link

@phs example works without swarm too in docker-compose.yml, e.g.

secrets:
  postgres_password:
    file: ./docker_postgres_password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants