Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better handling of Postgres pg_hba.conf
skoranda committed May 11, 2017
1 parent 84a633d commit fd68db6
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion comanage-registry-postgres/Dockerfile
@@ -40,4 +40,4 @@ ENV COMANAGE_REGISTRY_POSTGRES_USER_PASSWORD ${COMANAGE_REGISTRY_POSTGRES_USER_P

ENTRYPOINT ["/usr/local/bin/comanage-registry-postgres-entrypoint.sh"]

CMD ["-c", "hba_file=/etc/postgres/pg_hba.conf"]
CMD ["postgres"]
28 changes: 21 additions & 7 deletions comanage-registry-postgres/create-pg_hba.conf.sh
@@ -21,21 +21,35 @@

set -e

mkdir -p /etc/postgres

if [ -n "$COMANAGE_REGISTRY_POSTGRES_USER_PASSWORD" ]
# Measure the existing pg_hba.conf file to see if it is the default.
# The default version written will depend on whether or not passwords
# have been injected.
CHECKSUM=`md5sum /var/lib/postgresql/data/pg_hba.conf | awk '{print $1}'`
if [ "$CHECKSUM" = "d3cf011ed2c2f5ff9b7664911969c0f5" ] || [ "$CHECKSUM" = "42f44484c701461a44b713b1b6c0b901" ]
then
PG_HBA_DEFAULT="1"
else
PG_HBA_DEFAULT="0"
fi

# If the pg_hba.conf file is the default overwrite a more restrictive
# version.

cat >> /etc/postgres/pg_hba.conf <<EOF
if [ "$PG_HBA_DEFAULT" = "1" ]
then
# If a password has been injected require it, otherwise just use samenet trust.
if [ -n "$COMANAGE_REGISTRY_POSTGRES_USER_PASSWORD" ]
then
cat > /var/lib/postgresql/data/pg_hba.conf <<EOF
local all postgres peer
host $COMANAGE_REGISTRY_POSTGRES_DATABASE $COMANAGE_REGISTRY_POSTGRES_USER 127.0.0.1/32 md5
host $COMANAGE_REGISTRY_POSTGRES_DATABASE $COMANAGE_REGISTRY_POSTGRES_USER samenet md5
EOF

else
cat >> /etc/postgres/pg_hba.conf <<EOF
else
cat > /var/lib/postgresql/data/pg_hba.conf <<EOF
local all postgres peer
host $COMANAGE_REGISTRY_POSTGRES_DATABASE $COMANAGE_REGISTRY_POSTGRES_USER samenet trust
EOF

fi
fi

0 comments on commit fd68db6

Please sign in to comment.