From eaa8ee9bcea4988f8aee9725bf815f1e81a23151 Mon Sep 17 00:00:00 2001 From: Greg Fausak Date: Fri, 6 Feb 2015 17:29:27 +0000 Subject: [PATCH 1/3] added trust on samenet in pg_hba --- start | 1 + 1 file changed, 1 insertion(+) diff --git a/start b/start index 6193522..d745d12 100755 --- a/start +++ b/start @@ -29,6 +29,7 @@ EOF # allow remote connections to postgresql database cat >> ${PG_CONFDIR}/pg_hba.conf < Date: Sat, 7 Feb 2015 15:30:44 +0000 Subject: [PATCH 2/3] make the trust samenet behavior triggered by the PSQL_TRUST_LOCALNET environment variable --- README.md | 17 +++++++++++++++++ start | 12 +++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99dfc97..1a42ede 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,23 @@ docker run --name postgresql -d \ , will create a user *dbuser* with the password *dbpass*. It will also create a database named *dbname* and the *dbuser* user will have full access to the *dbname* database. +The PSQL_TRUST_LOCALNET environment variable can be used to configure postgres to trust connections on the same network. This +is handy for other containers to connect without authentication. To enable this behavior, set PSQL_TRUST_LOCALNET to Y. + +For example, + +```bash +docker run --name postgresql -d \ + -e 'PSQL_TRUST_LOCALNET=Y' \ + sameersbn/postgresql:9.4 +``` + +This has the effect of adding the following to the pg_hba.conf file: + +``` +host all all samenet trust +``` + # Configuration ## Data Store diff --git a/start b/start index d745d12..6a0ae90 100755 --- a/start +++ b/start @@ -6,6 +6,11 @@ PG_CONFDIR="/etc/postgresql/${PG_VERSION}/main" PG_BINDIR="/usr/lib/postgresql/${PG_VERSION}/bin" PG_DATADIR="${PG_HOME}/${PG_VERSION}/main" +# set this env variable to Y to enable a line in the +# pg_hba.conf file to trust samenet. this can be used to connect +# from other containers on the same host without authentication +PSQL_TRUST_LOCALNET="N" + DB_NAME=${DB_NAME:-} DB_USER=${DB_USER:-} DB_PASS=${DB_PASS:-} @@ -27,9 +32,14 @@ cat >> ${PG_CONFDIR}/postgresql.conf <> ${PG_CONFDIR}/pg_hba.conf +fi + # allow remote connections to postgresql database cat >> ${PG_CONFDIR}/pg_hba.conf < Date: Sat, 7 Feb 2015 19:27:20 +0000 Subject: [PATCH 3/3] oops, got the environment var wrong --- start | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start b/start index 6a0ae90..35ee784 100755 --- a/start +++ b/start @@ -9,7 +9,7 @@ PG_DATADIR="${PG_HOME}/${PG_VERSION}/main" # set this env variable to Y to enable a line in the # pg_hba.conf file to trust samenet. this can be used to connect # from other containers on the same host without authentication -PSQL_TRUST_LOCALNET="N" +PSQL_TRUST_LOCALNET=${PSQL_TRUST_LOCALNET:N} DB_NAME=${DB_NAME:-} DB_USER=${DB_USER:-}