Skip to content

gfs-postgres offers TLS on every start - #188

Open
medazizktata25 wants to merge 4 commits into
Guepard-Corp:mainfrom
medazizktata25:feat/postgres-offers-tls-on-every-start
Open

medazizktata25 wants to merge 4 commits into
Guepard-Corp:mainfrom
medazizktata25:feat/postgres-offers-tls-on-every-start

Conversation

@medazizktata25

Copy link
Copy Markdown
Contributor

Extracted unchanged from a larger branch about bootstrapping the lazy clone in-pod over loopback. The TLS change does not depend on any of that work and should not wait for it. Authored by khalil tbini; I cherry-picked it, so the author is preserved and the diff is byte-identical to the original commit's.

What it does

A wrapper entrypoint starts Postgres with ssl=on and either a mounted cert pair (GFS_TLS_CERT_FILE/GFS_TLS_KEY_FILE, defaulting to /etc/gfs-tls/tls.{crt,key}) or a per-container self-signed pair, then execs the stock docker-entrypoint.sh. Clients can then use sslmode=require.

TLS is offered, not forced, and the script says why: kube-proxy SNATs NodePort traffic, so pg_hba cannot distinguish an internet client from an in-cluster one. Encryption is enforced on the client side, through the connection string.

No private key is baked into the image — the self-signed pair is generated per container, so there is no shared key across deployments.

Verified against the built image

Built from this branch and exercised directly, not reasoned about:

Default start, self-signed

show ssl                                    -> on
show ssl_cert_file                          -> /var/lib/gfs-tls/server.crt
psql '...?sslmode=require' -c 'select 1'    -> 1
select ssl from pg_stat_ssl ... backend     -> t      (actually encrypted, not merely offered)
stat server.key                             -> 600 postgres
pg_available_extensions where name='gfs'     -> 1      (the extension still loads)

A mounted pair must win over the self-signed one — mounted a throwaway cert with CN=mounted-wins:

openssl x509 -subject -in server.crt        -> subject=CN=mounted-wins
psql '...?sslmode=require' -c 'select 1'    -> 1

Other commands must pass through, not be swallowed by the wrapper

docker run <image> psql --version           -> psql (PostgreSQL) 17.11

The script also parses cleanly under dash, which is /bin/sh on the Debian base — worth checking separately because it is written for sh, not bash, and runs under set -eu.

What is NOT verified

  • The Kubernetes path. Everything above is plain docker run. The NodePort/SNAT reasoning in the script's comment is the stated rationale for offering rather than forcing TLS, and I did not exercise it on a cluster.
  • sslmode=verify-full against a real CA-issued wildcard. The mounted-cert path is verified to take effect; whether a given CA chain satisfies a verifying client is a deployment question.
  • Non-root containers. The script branches on id -u for both the certificate directory and the chown, and the image runs as root here, so that branch was not taken. I checked separately that the [ "$(id -u)" = 0 ] && chown ... line does not abort the script under set -e on dash — it does not, so the non-root path should reach the exec — but it is untested on an actual non-root start.

The entrypoint starts Postgres with ssl=on and a mounted cert pair, or a
per-container self-signed one, so clients can use sslmode=require.

TLS is offered rather than forced: kube-proxy SNATs NodePort traffic, so pg_hba
cannot tell internet clients from in-cluster ones.

Extracted unchanged from a larger branch about in-pod lazy-clone bootstrap, which
it does not depend on and which should not gate it.
Conflict in crates/extensions/gfs/Dockerfile with 59e3244 (Guepard-Corp#184), which appended
LABEL run.guepard.gfs.pg_major at the same spot this branch appended the TLS
entrypoint. The two are independent; both are kept, the label first, then
COPY gfs-tls-entrypoint.sh / ENTRYPOINT / CMD.

This branch is waiting to be deployed

1 waiting deployment
pr-validation — 08748448 Waiting Oct 27, 2026 by medazizktata25 via build-and-test (ubuntu-latest) #299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants