Skip to content

Commit 5472e76

Browse files
author
Jan Lieskovsky
committed
[KEYCLOAK-15633] Add "s2i" subdirectory to hold an example
on how to enable SSL/TLS for PostgreSQL 10 SQL database server container image. It will be later used in S2I (re)builds of the PostgreSQL 10 SQL database server container image in the available PostgreSQL templates for Red Hat Single Sign-On 7.5 for OpenJDK / OpenJ9 on OpenShift container images Signed-off-by: Jan Lieskovsky <[email protected]>
1 parent 2e4da85 commit 5472e76

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

s2i/postgresql/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SSL/TLS support for PostgreSQL SQL database server container image
2+
3+
The [PostgreSQL 10 SQL database server](https://catalog.redhat.com/software/containers/rhscl/postgresql-10-rhel7/5aa63541ac3db95f196086f1)
4+
doesn't support SSL/TLS encryption by default. In order to enable the
5+
SSL/TLS encryption, the PostgreSQL server container image needs to be
6+
extended using the [source-to-image](https://github.com/openshift/source-to-image)
7+
method. Refer to [_*Extending image*_](https://catalog.redhat.com/software/containers/rhscl/postgresql-10-rhel7/5aa63541ac3db95f196086f1)
8+
and primarily to [the available example](https://github.com/sclorg/postgresql-container/tree/master/examples/enable-ssl)
9+
for additional details.
10+
11+
This (sub)directory contains all the information needed to enable SSL/TLS
12+
support for the [PostgreSQL 10 SQL database server](https://catalog.redhat.com/software/containers/rhscl/postgresql-10-rhel7/5aa63541ac3db95f196086f1)
13+
used in the available PostgreSQL [templates](https://github.com/jboss-container-images/redhat-sso-7-openshift-image/tree/sso75-dev/templates)
14+
for [Red Hat Single Sign-On 7.5 for OpenJDK / OpenJ9 on OpenShift container images](https://github.com/jboss-container-images/redhat-sso-7-openshift-image/tree/sso75-dev).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Example to enable SSL/TLS for the PostgreSQL SQL database server container image
2+
3+
Inspired by the ["enable-ssl"](https://github.com/sclorg/postgresql-container/tree/master/examples/enable-ssl)
4+
example from the Red Hat Software Collections PostgreSQL container images repository.
5+
6+
Compared to the original, this example does NOT store the TLS certificate & private
7+
key files directly in the repository. Instead of that, those files are generated
8+
on the fly by the PostgreSQL OpenShift service using the OpenShift's service serving
9+
certificate secrets mechanism based on the corresponding annotation applied to the
10+
definition of the PostgreSQL service.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ssl = on
2+
# The TLS certificate & key are generated using the OpenShift's service serving
3+
# certificate secrets via corresponding annotation of the PostgreSQL service
4+
# and stored into a read-only persistent volume, corresponding to the OpenShift
5+
# secret.
6+
#
7+
# Later the 'postgresql-pre-start/enable_ssl.sh' script, present in this
8+
# repository, copies the generated TLS certificate & key to by current UID
9+
# writable "/var/run/postgresql/pki" directory, so it's possible to correct
10+
# the permissions of the TLS private key to mode required by PostgreSQL server
11+
ssl_cert_file = '/var/run/postgresql/pki/tls.crt' # PostgreSQL server certificate
12+
ssl_key_file = '/var/run/postgresql/pki/tls.key' # PostgreSQL server private key
13+
ssl_ca_file = '/run/secrets/kubernetes.io/serviceaccount/ca.crt' # OpenShift CA
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
# Copy the TLS certificate & key generated by the OpenShift's service serving
6+
# certificate secrets from "/etc/pki/postgresql" (which is mounted read-only,
7+
# since coming from secret) to "/var/run/postgresql/pki", so it's possible to
8+
# correct the permissions of the TLS private key as required below
9+
SOURCE_DIR="/etc/pki/postgresql"
10+
DESTINATION_DIR="/var/run/postgresql/pki"
11+
if [ ! -d "${DESTINATION_DIR}" ]; then
12+
mkdir -p "${DESTINATION_DIR}"
13+
fi
14+
cp "${SOURCE_DIR}"/tls.{crt,key} "${DESTINATION_DIR}"
15+
16+
# PostgreSQL will fail to start and throw an error like:
17+
#
18+
# FATAL: private key file "/path/to/key" has group or world access
19+
# File must have permissions u=rw (0600) or less if owned by the database user, or permissions u=rw,g=r (0640) or less if owned by root.
20+
#
21+
# if the permissions of the TLS private key are incorrect.
22+
#
23+
# Thus correct the permissions so PostgreSQL server can start successfully
24+
chmod 0600 "${DESTINATION_DIR}/tls.key"

0 commit comments

Comments
 (0)