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

Enable SSL connection #152

Closed
wants to merge 11 commits into from
3 changes: 3 additions & 0 deletions 9.1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/*
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8

# auto generate a self-signed certificate in /etc/ssl/certs/ssl-cert-snakeoil.pem
RUN apt-get update && apt-get install -y ssl-cert && rm -rf /var/lib/apt/lists/*

RUN mkdir /docker-entrypoint-initdb.d

RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
Expand Down
33 changes: 31 additions & 2 deletions 9.1/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,38 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"
hostMethod=host
if [[ ! -z "$POSTGRES_ENABLE_SSL" && ! $POSTGRES_ENABLE_SSL =~ ^([nN][oO]|[nN]|[fF][aA][lL][sS][eE]|[fF]|0)$ ]] ; then
if [ ! -f "/etc/ssl/certs/postgresql.crt" ]; then
cat >&2 <<-'EOWARN'
****************************************************
WARNING: Using an auto-generated certificate for SSL.
Please consider using your own certificate
in production environments.

Use "-v /my/cert.crt:/etc/ssl/certs/postgresql.crt"
and "-v /my/cert.key:/etc/ssl/private/postgresql.key"
to mount your own certificate as a volume.
****************************************************
EOWARN
DEBIAN_FRONTEND=noninteractive make-ssl-cert generate-default-snakeoil --force-overwrite
cp /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/postgresql.crt
cp /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/postgresql.key
fi

cp /etc/ssl/certs/postgresql.crt "$PGDATA/server.crt"
cp /etc/ssl/private/postgresql.key "$PGDATA/server.key"
chown postgres "$PGDATA/server.crt"
chown postgres "$PGDATA/server.key"
chmod og-rwx "$PGDATA/server.key"

sed -i "s|#\?ssl \?=.*|ssl = on|g" "$PGDATA/postgresql.conf"
hostMethod=hostssl
fi

{ echo; echo "$hostMethod all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"

# internal start of server in order to allow set-up using psql-client
# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
gosu postgres pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
Expand Down
3 changes: 3 additions & 0 deletions 9.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/*
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8

# auto generate a self-signed certificate in /etc/ssl/certs/ssl-cert-snakeoil.pem
RUN apt-get update && apt-get install -y ssl-cert && rm -rf /var/lib/apt/lists/*

RUN mkdir /docker-entrypoint-initdb.d

RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
Expand Down
33 changes: 31 additions & 2 deletions 9.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,38 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"
hostMethod=host
if [[ ! -z "$POSTGRES_ENABLE_SSL" && ! $POSTGRES_ENABLE_SSL =~ ^([nN][oO]|[nN]|[fF][aA][lL][sS][eE]|[fF]|0)$ ]] ; then
if [ ! -f "/etc/ssl/certs/postgresql.crt" ]; then
cat >&2 <<-'EOWARN'
****************************************************
WARNING: Using an auto-generated certificate for SSL.
Please consider using your own certificate
in production environments.

Use "-v /my/cert.crt:/etc/ssl/certs/postgresql.crt"
and "-v /my/cert.key:/etc/ssl/private/postgresql.key"
to mount your own certificate as a volume.
****************************************************
EOWARN
DEBIAN_FRONTEND=noninteractive make-ssl-cert generate-default-snakeoil --force-overwrite
cp /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/postgresql.crt
cp /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/postgresql.key
fi

cp /etc/ssl/certs/postgresql.crt "$PGDATA/server.crt"
cp /etc/ssl/private/postgresql.key "$PGDATA/server.key"
chown postgres "$PGDATA/server.crt"
chown postgres "$PGDATA/server.key"
chmod og-rwx "$PGDATA/server.key"

sed -i "s|#\?ssl \?=.*|ssl = on|g" "$PGDATA/postgresql.conf"
hostMethod=hostssl
fi

{ echo; echo "$hostMethod all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"

# internal start of server in order to allow set-up using psql-client
# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
gosu postgres pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
Expand Down
3 changes: 3 additions & 0 deletions 9.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/*
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8

# auto generate a self-signed certificate in /etc/ssl/certs/ssl-cert-snakeoil.pem
RUN apt-get update && apt-get install -y ssl-cert && rm -rf /var/lib/apt/lists/*

RUN mkdir /docker-entrypoint-initdb.d

RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
Expand Down
33 changes: 31 additions & 2 deletions 9.3/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,38 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"
hostMethod=host
if [[ ! -z "$POSTGRES_ENABLE_SSL" && ! $POSTGRES_ENABLE_SSL =~ ^([nN][oO]|[nN]|[fF][aA][lL][sS][eE]|[fF]|0)$ ]] ; then
if [ ! -f "/etc/ssl/certs/postgresql.crt" ]; then
cat >&2 <<-'EOWARN'
****************************************************
WARNING: Using an auto-generated certificate for SSL.
Please consider using your own certificate
in production environments.

Use "-v /my/cert.crt:/etc/ssl/certs/postgresql.crt"
and "-v /my/cert.key:/etc/ssl/private/postgresql.key"
to mount your own certificate as a volume.
****************************************************
EOWARN
DEBIAN_FRONTEND=noninteractive make-ssl-cert generate-default-snakeoil --force-overwrite
cp /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/postgresql.crt
cp /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/postgresql.key
fi

cp /etc/ssl/certs/postgresql.crt "$PGDATA/server.crt"
cp /etc/ssl/private/postgresql.key "$PGDATA/server.key"
chown postgres "$PGDATA/server.crt"
chown postgres "$PGDATA/server.key"
chmod og-rwx "$PGDATA/server.key"

sed -i "s|#\?ssl \?=.*|ssl = on|g" "$PGDATA/postgresql.conf"
hostMethod=hostssl
fi

{ echo; echo "$hostMethod all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"

# internal start of server in order to allow set-up using psql-client
# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
gosu postgres pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
Expand Down
3 changes: 3 additions & 0 deletions 9.4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/*
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8

# auto generate a self-signed certificate in /etc/ssl/certs/ssl-cert-snakeoil.pem
RUN apt-get update && apt-get install -y ssl-cert && rm -rf /var/lib/apt/lists/*

RUN mkdir /docker-entrypoint-initdb.d

RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
Expand Down
33 changes: 31 additions & 2 deletions 9.4/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,38 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"
hostMethod=host
if [[ ! -z "$POSTGRES_ENABLE_SSL" && ! $POSTGRES_ENABLE_SSL =~ ^([nN][oO]|[nN]|[fF][aA][lL][sS][eE]|[fF]|0)$ ]] ; then
if [ ! -f "/etc/ssl/certs/postgresql.crt" ]; then
cat >&2 <<-'EOWARN'
****************************************************
WARNING: Using an auto-generated certificate for SSL.
Please consider using your own certificate
in production environments.

Use "-v /my/cert.crt:/etc/ssl/certs/postgresql.crt"
and "-v /my/cert.key:/etc/ssl/private/postgresql.key"
to mount your own certificate as a volume.
****************************************************
EOWARN
DEBIAN_FRONTEND=noninteractive make-ssl-cert generate-default-snakeoil --force-overwrite
cp /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/postgresql.crt
cp /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/postgresql.key
fi

cp /etc/ssl/certs/postgresql.crt "$PGDATA/server.crt"
cp /etc/ssl/private/postgresql.key "$PGDATA/server.key"
chown postgres "$PGDATA/server.crt"
chown postgres "$PGDATA/server.key"
chmod og-rwx "$PGDATA/server.key"

sed -i "s|#\?ssl \?=.*|ssl = on|g" "$PGDATA/postgresql.conf"
hostMethod=hostssl
fi

{ echo; echo "$hostMethod all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"

# internal start of server in order to allow set-up using psql-client
# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
gosu postgres pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
Expand Down
3 changes: 3 additions & 0 deletions 9.5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/*
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8

# auto generate a self-signed certificate in /etc/ssl/certs/ssl-cert-snakeoil.pem
RUN apt-get update && apt-get install -y ssl-cert && rm -rf /var/lib/apt/lists/*

RUN mkdir /docker-entrypoint-initdb.d

RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
Expand Down
33 changes: 31 additions & 2 deletions 9.5/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,38 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"
hostMethod=host
if [[ ! -z "$POSTGRES_ENABLE_SSL" && ! $POSTGRES_ENABLE_SSL =~ ^([nN][oO]|[nN]|[fF][aA][lL][sS][eE]|[fF]|0)$ ]] ; then
if [ ! -f "/etc/ssl/certs/postgresql.crt" ]; then
cat >&2 <<-'EOWARN'
****************************************************
WARNING: Using an auto-generated certificate for SSL.
Please consider using your own certificate
in production environments.

Use "-v /my/cert.crt:/etc/ssl/certs/postgresql.crt"
and "-v /my/cert.key:/etc/ssl/private/postgresql.key"
to mount your own certificate as a volume.
****************************************************
EOWARN
DEBIAN_FRONTEND=noninteractive make-ssl-cert generate-default-snakeoil --force-overwrite
cp /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/postgresql.crt
cp /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/postgresql.key
fi

cp /etc/ssl/certs/postgresql.crt "$PGDATA/server.crt"
cp /etc/ssl/private/postgresql.key "$PGDATA/server.key"
chown postgres "$PGDATA/server.crt"
chown postgres "$PGDATA/server.key"
chmod og-rwx "$PGDATA/server.key"

sed -i "s|#\?ssl \?=.*|ssl = on|g" "$PGDATA/postgresql.conf"
hostMethod=hostssl
fi

{ echo; echo "$hostMethod all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"

# internal start of server in order to allow set-up using psql-client
# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
gosu postgres pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
Expand Down
3 changes: 3 additions & 0 deletions 9.6/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/*
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8

# auto generate a self-signed certificate in /etc/ssl/certs/ssl-cert-snakeoil.pem
RUN apt-get update && apt-get install -y ssl-cert && rm -rf /var/lib/apt/lists/*

RUN mkdir /docker-entrypoint-initdb.d

RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
Expand Down
33 changes: 31 additions & 2 deletions 9.6/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,38 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"
hostMethod=host
if [[ ! -z "$POSTGRES_ENABLE_SSL" && ! $POSTGRES_ENABLE_SSL =~ ^([nN][oO]|[nN]|[fF][aA][lL][sS][eE]|[fF]|0)$ ]] ; then
if [ ! -f "/etc/ssl/certs/postgresql.crt" ]; then
cat >&2 <<-'EOWARN'
****************************************************
WARNING: Using an auto-generated certificate for SSL.
Please consider using your own certificate
in production environments.

Use "-v /my/cert.crt:/etc/ssl/certs/postgresql.crt"
and "-v /my/cert.key:/etc/ssl/private/postgresql.key"
to mount your own certificate as a volume.
****************************************************
EOWARN
DEBIAN_FRONTEND=noninteractive make-ssl-cert generate-default-snakeoil --force-overwrite
cp /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/postgresql.crt
cp /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/postgresql.key
fi

cp /etc/ssl/certs/postgresql.crt "$PGDATA/server.crt"
cp /etc/ssl/private/postgresql.key "$PGDATA/server.key"
chown postgres "$PGDATA/server.crt"
chown postgres "$PGDATA/server.key"
chmod og-rwx "$PGDATA/server.key"

sed -i "s|#\?ssl \?=.*|ssl = on|g" "$PGDATA/postgresql.conf"
hostMethod=hostssl
fi

{ echo; echo "$hostMethod all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"

# internal start of server in order to allow set-up using psql-client
# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
gosu postgres pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/*
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8

# auto generate a self-signed certificate in /etc/ssl/certs/ssl-cert-snakeoil.pem
RUN apt-get update && apt-get install -y ssl-cert && rm -rf /var/lib/apt/lists/*

RUN mkdir /docker-entrypoint-initdb.d

RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
Expand Down
33 changes: 31 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,38 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"
hostMethod=host
if [[ ! -z "$POSTGRES_ENABLE_SSL" && ! $POSTGRES_ENABLE_SSL =~ ^([nN][oO]|[nN]|[fF][aA][lL][sS][eE]|[fF]|0)$ ]] ; then
if [ ! -f "/etc/ssl/certs/postgresql.crt" ]; then
cat >&2 <<-'EOWARN'
****************************************************
WARNING: Using an auto-generated certificate for SSL.
Please consider using your own certificate
in production environments.

Use "-v /my/cert.crt:/etc/ssl/certs/postgresql.crt"
and "-v /my/cert.key:/etc/ssl/private/postgresql.key"
to mount your own certificate as a volume.
****************************************************
EOWARN
DEBIAN_FRONTEND=noninteractive make-ssl-cert generate-default-snakeoil --force-overwrite
cp /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/postgresql.crt
cp /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/postgresql.key
fi

cp /etc/ssl/certs/postgresql.crt "$PGDATA/server.crt"
cp /etc/ssl/private/postgresql.key "$PGDATA/server.key"
chown postgres "$PGDATA/server.crt"
chown postgres "$PGDATA/server.key"
chmod og-rwx "$PGDATA/server.key"

sed -i "s|#\?ssl \?=.*|ssl = on|g" "$PGDATA/postgresql.conf"
hostMethod=hostssl
fi

{ echo; echo "$hostMethod all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"

# internal start of server in order to allow set-up using psql-client
# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
gosu postgres pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
Expand Down