Skip to content

POSTGRES_PASSWORD changes authentication settings unexpectedly #580

Closed
@Andrew-Morozko

Description

@Andrew-Morozko

I believe that current authentication configuration in docker-entrypoint.sh is less secure than it should be. I have a problem with $POSTGRES_PASSWORD changing the authentication settings and not adequately warning user about it.

Currently if the password is not supplied host all all all trust is added to pg_hba.conf , disabling the password checks for all users. I think this goes way too far:

  1. I honestly believe that there should be no way for the line host all all all trust to appear in configuration unless user explicitly sets ACCEPT_ANY_PASSWORD_FOR_ANY_USER=true
  2. Currently any mistake in configuration (for example misspelling POSTGRES_PASSWORD) results in disabled authentication
  3. Disabled authentication is completely silent. User could believe that password authentication is working, since the DB accepts the password.
  4. Warning displayed if POSTGRES_PASSWORD wasn't set does not convey that password checks were disabled altogether.

No password has been set for the database. This will allow anyone with access to the Postgres port to access your database.

Sounds like you can fix it by setting the password, but the password would be just ignored.

I had an unpleasant experience of discovering my development DB for a personal project consuming 100% of server's CPU because someone was mining some kind of crypto coin on it.
Initially I was using POSTGRES_PASSWORD, but later I decided to move password configuration for "postgres" user together with creating additional, less privileged users into an init SQL file in /docker-entrypoint-initdb.d/ (amazing feature, btw). As you might imagine, I did not believe that this would disable all password checks altogether, and since my server continued to grant access with my password I had no idea that I was completely insecure.

I did not expect (and didn't need) high security from DB with an exposed port and without SSL, but having literally no security is a really strange decision.

I've read issues about security of this image (#3 #29 #31), and it seems like "security is annoying and not our problem" argument is winning. I'd much rather have official images be more secure by default, but I feel like this fight is futile. So here are my suggestions, from less bothersome to more secure:

  1. Change the warning to clearly state "all authentication is disabled, any password is valid for any user, change pg_hba.conf or set $POSTGRES_PASSWORD if this behavior is undesirable" or something like that. Add this warning to readme.
  2. If POSTGRES_PASSWORD is not set (better yet, if ALLOW_EMPTY_PASSWORD is set), then set it to an empty string and keep the md5 authentication always enabled. That way developers can still easily connect to a DB with empty password, but changing the password would never be silently ignored, like it was in my case.
  3. If POSTGRES_PASSWORD is not set (better yet, if GENERATE_RANDOM_PASSWORD is set), then set password to a random string and print it on initial launch.

Official MySQL image allows to get second or third behavior by setting MYSQL_ALLOW_EMPTY_PASSWORD or MYSQL_RANDOM_ROOT_PASSWORD environment variables. Alternatively, you can set MYSQL_ROOT_PASSWORD directly. One of the three variables must be set explicitly, or MySQL container fails to launch.

For backwards compatibility ACCEPT_ANY_PASSWORD_FOR_ANY_USER or similarly explicitly named environment variable could be added. If it is set to true then host all all all trust is added to the config.

I'm willing to write the necessary code, but I'd like to know beforehand which approach would be accepted. IMHO MySQL's approach is the correct one, it is both flexible and explicit, but it's up to the maintainers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    RequestRequest for image modification or feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions