Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ jobs:
cache-to: type=gha,mode=max

# Gate: a build whose PostGIS is vulnerable to CVE-2026-73514 /
# CVE-2026-73515 must never reach a tag. The PR job runs it on the loaded
# CVE-2026-73515, or whose server predates 18.7 (CVE-2026-6460), must
# never reach a tag. The PR job runs it on the loaded
# image; the push job below runs it on the pushed digest before the
# manifest job can move `latest`/`18` onto it.
- name: Verify PostGIS security (PR, amd64)
Expand All @@ -90,6 +91,7 @@ jobs:
docker run -d --name postgis-verify -e POSTGRES_PASSWORD=test "$tag"
until docker exec postgis-verify pg_isready -U postgres -q; do sleep 1; done

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Add timeout to the pg_isready wait loops

The until docker exec postgis-verify pg_isready -U postgres -q; do sleep 1; done loops in both the PR and push gate steps have no timeout (.github/workflows/docker.yml:92). A container whose Postgres never becomes ready — bad entrypoint, crashed initdb — hangs the job until the 360-minute default job timeout. This wastes runner minutes and delays the real signal that the gate failed; the same unbounded loop appears at line 117.

📋 Prompt for AI Agents

In .github/workflows/docker.yml, in the 'Verify PostGIS security (PR, amd64)' step (around line 92) and the 'Verify PostGIS security (pushed digest)' step (around line 117), replace the unbounded until docker exec postgis-verify pg_isready -U postgres -q; do sleep 1; done loop with a bounded wait, e.g. a counter that exits 1 after 300 seconds and prints docker logs postgis-verify. This prevents a 6-hour CI hang when the container fails to start.

./scripts/verify-postgis-security.sh postgis-verify
./scripts/verify-postgres-security.sh postgis-verify

- name: Build & push by digest
if: github.event_name != 'pull_request'
Expand All @@ -114,6 +116,7 @@ jobs:
docker run -d --name postgis-verify -e POSTGRES_PASSWORD=test "$image"
until docker exec postgis-verify pg_isready -U postgres -q; do sleep 1; done
./scripts/verify-postgis-security.sh postgis-verify
./scripts/verify-postgres-security.sh postgis-verify

- name: Export digest
if: github.event_name != 'pull_request'
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ test: build
CREATE EXTENSION pg_partman; \
SELECT 'all extensions OK';"
@./scripts/verify-postgis-security.sh $(CONTAINER_NAME)-test
@./scripts/verify-postgres-security.sh $(CONTAINER_NAME)-test
@docker stop $(CONTAINER_NAME)-test > /dev/null
@docker rm $(CONTAINER_NAME)-test > /dev/null

# Assert the running $(CONTAINER_NAME) is not a PostGIS build vulnerable to
# CVE-2026-73514 / CVE-2026-73515.
# CVE-2026-73514 / CVE-2026-73515, nor a server older than 18.7 (CVE-2026-6460).
verify-security:
@./scripts/verify-postgis-security.sh $(CONTAINER_NAME)
@./scripts/verify-postgres-security.sh $(CONTAINER_NAME)

clean: stop
docker rmi $(IMAGE_NAME):$(IMAGE_TAG) || true
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ on the pushed digest before the `latest`/`18` manifests move.
Drop the patches when a PostGIS release contains all four fixes; the gate's
`POSTGIS_MIN_VERSION` floor and manifest check are what to update then.

## PostgreSQL security floor

The base image is `postgres:18-alpine`, so each build takes the newest 18.x
minor and compiles every extension from source against it. 18.7 (CVE-2026-6460
and the rest of the 2026-11-12 release) changed the server ABI: an extension
built against 18.6 fails to load on 18.7 with `undefined symbol`, which is why
the extensions are never copied in prebuilt.

`scripts/verify-postgres-security.sh <container>` is the gate: it fails when the
running server is below `server_version_num` 180007, when the
`composite_type_mismatch` check that fix added is missing or not `error`, and
when any bundled extension does not load. CI runs it next to the PostGIS gate.
Raise `PG_MIN_VERSION_NUM` when a later minor is the floor.

## Building manually

```bash
Expand Down
39 changes: 39 additions & 0 deletions scripts/verify-postgres-security.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Fails if the image's PostgreSQL server predates the 18.7 security release
# (CVE-2026-6460 and the other fixes shipped with it).
#
# The base image is the floating `postgres:18-alpine` tag, so a rebuild picks up
# whatever minor that tag points at; this asserts against the *running* server,
# not the Dockerfile ARG. `composite_type_mismatch` is the server parameter the
# CVE-2026-6460 fix introduced, so its presence proves that fix is compiled in.
#
# Usage: verify-postgres-security.sh <container-name>
set -euo pipefail

container="${1:?usage: verify-postgres-security.sh <container>}"
psql() { docker exec -i "$container" psql -U postgres -X -q -At "$@"; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 bug · high

Set ON_ERROR_STOP for every psql call

The psql wrapper runs without ON_ERROR_STOP, so psql -c exits 0 even when the SQL statement fails (scripts/verify-postgres-security.sh:14). The || fail guards on the version probe, the SHOW composite_type_mismatch check, and the CREATE EXTENSION loop are therefore inert for SQL-level failures: an extension dying with an undefined symbol ABI mismatch prints to stderr while the script reports "PostgreSQL security verification passed". A build with an incompatible or unpatched server ABI passes the security gate and reaches a tag.

📋 Prompt for AI Agents

In scripts/verify-postgres-security.sh line 14, change the wrapper to psql() { docker exec -i "$container" psql -U postgres -X -q -At -v ON_ERROR_STOP=1 "$@"; } so server-side SQL errors (failed CREATE EXTENSION, unrecognized SHOW parameter) make psql exit non-zero and trigger the existing || fail guards. Then run the script against a built image: if CREATE EXTENSION pg_stat_statements fails with "must be loaded via shared_preload_libraries", confirm the image preloads it before keeping it in the loop.


# 18.7 — lowest minor carrying the 2026-11-12 security fixes.
PG_MIN_VERSION_NUM="${PG_MIN_VERSION_NUM:-180007}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 bug · high

Wrong PG_MIN_VERSION_NUM floor lets 18.1–18.6 pass

The default floor PG_MIN_VERSION_NUM=180007 decodes to 18.0.7, not 18.7: server_version_num is major*10000 + minor*100 + patch, so 18.7 is 180700 (scripts/verify-postgres-security.sh:17). The gate therefore accepts any 18.x server above 18.0.6 — including vulnerable 18.1–18.6 builds that predate the CVE-2026-6460 fix — defeating the stated purpose of the check. The gate runs from make test, make verify-security, and both CI verify steps, so an image built from a stale postgres:18-alpine pin passes verification and is tagged.

📋 Prompt for AI Agents

In scripts/verify-postgres-security.sh line 17, change the default from 180007 to 180700. PostgreSQL encodes minor releases in the hundreds digit of server_version_num (18.7 = 1810000 + 7100 = 180700), so 180007 actually means 18.0.7 and the current gate passes vulnerable 18.1–18.6 servers. Keep the env-overridable form.


fail() { echo "FAIL: $*" >&2; exit 1; }
ok() { echo "ok: $*"; }

version_num="$(psql -c 'SHOW server_version_num')"
[ "$version_num" -ge "$PG_MIN_VERSION_NUM" ] \
|| fail "server_version_num $version_num is below the patched floor $PG_MIN_VERSION_NUM"
ok "postgres $(psql -c 'SHOW server_version') >= $PG_MIN_VERSION_NUM"

mismatch="$(psql -c 'SHOW composite_type_mismatch' 2>&1)" \
|| fail "composite_type_mismatch is unknown — server lacks the CVE-2026-6460 fix"
[ "$mismatch" = "error" ] || fail "composite_type_mismatch is '$mismatch', expected 'error'"
ok "composite_type_mismatch = error (CVE-2026-6460 check active)"

# Every C extension must load against this server's ABI: an extension built
# against an older minor fails here with "undefined symbol".
for ext in vector postgis pg_textsearch pg_partman pg_stat_statements; do
psql -c "CREATE EXTENSION IF NOT EXISTS $ext" >/dev/null || fail "CREATE EXTENSION $ext failed"
done
ok "vector, postgis, pg_textsearch, pg_partman, pg_stat_statements load"

echo "PostgreSQL security verification passed"
Loading