diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index c3b9b76..a19c0e3 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -92,6 +92,7 @@ jobs: 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 + ./scripts/verify-pgvector-security.sh postgis-verify - name: Build & push by digest if: github.event_name != 'pull_request' @@ -117,6 +118,7 @@ jobs: 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 + ./scripts/verify-pgvector-security.sh postgis-verify - name: Export digest if: github.event_name != 'pull_request' diff --git a/Dockerfile b/Dockerfile index 2f8940c..4569a26 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # Multi-stage build - all toolchains discarded, only artifacts kept ARG PG_VERSION=18 -ARG PGVECTOR_VERSION=0.8.2 +ARG PGVECTOR_VERSION=0.8.7 ARG POSTGIS_VERSION=3.6.4 ARG PG_TEXTSEARCH_VERSION=1.5.1 ARG PG_PARTMAN_VERSION=5.4.3 diff --git a/Makefile b/Makefile index fa2eb91..ff7d3b1 100644 --- a/Makefile +++ b/Makefile @@ -43,14 +43,17 @@ test: build SELECT 'all extensions OK';" @./scripts/verify-postgis-security.sh $(CONTAINER_NAME)-test @./scripts/verify-postgres-security.sh $(CONTAINER_NAME)-test + @./scripts/verify-pgvector-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, nor a server older than 18.7 (CVE-2026-6460). +# CVE-2026-73514 / CVE-2026-73515, a server older than 18.7 (CVE-2026-6460), +# nor a pgvector older than 0.8.7 (CVE-2026-103484). verify-security: @./scripts/verify-postgis-security.sh $(CONTAINER_NAME) @./scripts/verify-postgres-security.sh $(CONTAINER_NAME) + @./scripts/verify-pgvector-security.sh $(CONTAINER_NAME) clean: stop docker rmi $(IMAGE_NAME):$(IMAGE_TAG) || true diff --git a/README.md b/README.md index 3429b8d..44d2bf7 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Lean PostgreSQL 18 image with essential extensions for modern applications. | Extension | Version | Description | |-----------|---------|-------------| -| [pgvector](https://github.com/pgvector/pgvector) | 0.8.2 | Vector similarity search for embeddings | +| [pgvector](https://github.com/pgvector/pgvector) | 0.8.7 | Vector similarity search for embeddings | | [PostGIS](https://postgis.net/) | 3.6.4 (+ security patches) | Spatial and geographic data | | [pg_textsearch](https://github.com/timescale/pg_textsearch) | 1.5.1 | BM25 full-text search | | [pg_partman](https://github.com/pgpartman/pg_partman) | 5.4.3 | Partition management | @@ -50,7 +50,7 @@ CREATE EXTENSION pg_stat_statements; ```bash make build # Build image -make test # Build, verify extensions, and run the PostGIS security gate +make test # Build, verify extensions, and run the security gates make verify-security # Run the security gate against an already-running container make run # Run container make shell # psql into container @@ -97,6 +97,19 @@ running server is below `server_version_num` 180007, when the 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. +## pgvector security floor + +pgvector is built from the `v0.8.7` tag, the release that fixes CVE-2026-103484 +([pgvector#1036](https://github.com/pgvector/pgvector/issues/1036)): an +out-of-bounds write during an IVFFlat index build, affecting 0.8.6 and below. + +`scripts/verify-pgvector-security.sh ` is the gate: it fails when the +extension's default or installed version is below 0.8.7, and when `vector.so` +does not export `sparsevec_vector_dims`, the symbol the fix commit added, so a +library older than its SQL metadata is caught too. It builds no index. CI runs +it next to the other two gates. Raise `PGVECTOR_MIN_VERSION` when a later +release is the floor. + ## Building manually ```bash diff --git a/scripts/verify-pgvector-security.sh b/scripts/verify-pgvector-security.sh new file mode 100755 index 0000000..0b78474 --- /dev/null +++ b/scripts/verify-pgvector-security.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# Fails if the image ships a pgvector build that is vulnerable to +# CVE-2026-103484 (out-of-bounds write during an IVFFlat index build, +# https://github.com/pgvector/pgvector/issues/1036 — affected <= 0.8.6, +# fixed in 0.8.7). +# +# Asserted against the *installed* extension and the *loaded* library, never +# against a Dockerfile ARG or a tag. The extension version is only SQL +# metadata, so the library is checked too: 0.8.7 is the first release whose +# vector.so exports `sparsevec_vector_dims`, added by the same commit as the +# fix (ee00d39), and binding a C function to that symbol fails on any older +# build. Nothing here builds an index or writes out of bounds. +# +# Usage: verify-pgvector-security.sh +set -euo pipefail + +container="${1:?usage: verify-pgvector-security.sh }" +psql() { docker exec -i "$container" psql -U postgres -X -q -At -v ON_ERROR_STOP=1 "$@"; } + +PGVECTOR_MIN_VERSION="${PGVECTOR_MIN_VERSION:-0.8.7}" + +fail() { echo "FAIL: $*" >&2; exit 1; } +ok() { echo "ok: $*"; } + +below_floor() { + [ "$(printf '%s\n%s\n' "$PGVECTOR_MIN_VERSION" "$1" | sort -V | head -1)" != "$PGVECTOR_MIN_VERSION" ] +} + +# 1. the version the image installs by default +available="$(psql -c "SELECT default_version FROM pg_available_extensions WHERE name = 'vector'")" +[ -n "$available" ] || fail "pgvector is not available in this image" +if below_floor "$available"; then + fail "pgvector default_version $available is below the patched floor $PGVECTOR_MIN_VERSION" +fi + +# 2. the version a database actually gets +psql -c 'CREATE EXTENSION IF NOT EXISTS vector' >/dev/null +installed="$(psql -c "SELECT extversion FROM pg_extension WHERE extname = 'vector'")" +if below_floor "$installed"; then + fail "pgvector extension $installed is below the patched floor $PGVECTOR_MIN_VERSION" +fi +ok "pgvector $installed >= $PGVECTOR_MIN_VERSION" + +# 3. the library itself carries the fix commit +psql >/dev/null 2>&1 <<'SQL' || fail "vector.so does not export sparsevec_vector_dims — library predates the CVE-2026-103484 fix" +BEGIN; +CREATE FUNCTION pg_temp.pgvector_fix_probe(sparsevec) RETURNS integer + AS '$libdir/vector', 'sparsevec_vector_dims' LANGUAGE C IMMUTABLE STRICT; +ROLLBACK; +SQL +ok "vector.so exports sparsevec_vector_dims (CVE-2026-103484 fix compiled in)" + +echo "pgvector security verification passed"