How to fix CVEs in PostgreSQL container images
Short answer
PostgreSQL images get CVEs from the base OS, from PostgreSQL itself (fixed in minor releases, which are safe to apply within a major version), and from helper programs such as gosu, a Go binary built with an older Go release. Move to the newest minor of your major version, upgrade OS packages, and rebuild or replace the helper binaries.
Fix a PostgreSQL image now →
free, no sign-up; pre-filled with postgres:16, change it to yours
The steps
- 01Newest minor releaseMinor releases contain only fixes and need no dump and restore.
- 02Upgrade OS packagesIn a layer on top of the image you run.
- 03Rebuild helper binariesgosu carries the Go standard library CVEs of the release that built it.
- 04Keep the major versionMajor upgrades are a separate, planned migration.
By hand
FROM postgres:16 RUN apt-get update && apt-get upgrade -y && rm -rf /var/lib/apt/lists/*
Then rescan: the CVEs that remain are either without a released fix or in code the application never loads (the report marks both).
Traps that bring CVEs back
- gosu in database images is a common source of Go CVEs; OCImend rebuilds it from its source.
- A pinned minor tag never receives the next minor's fixes: follow the major tag and pin by digest.
PostgreSQL images in OCImend's reports
| Image | Grade | Known CVEs | |
|---|---|---|---|
| postgres:16.11-alpine3.21 | F | 162 exploited | Fix |
Questions
How do I fix CVEs in a PostgreSQL container image?
PostgreSQL images get CVEs from the base OS, from PostgreSQL itself (fixed in minor releases, which are safe to apply within a major version), and from helper programs such as gosu, a Go binary built with an older Go release. Move to the newest minor of your major version, upgrade OS packages, and rebuild or replace the helper binaries.
Is a minor PostgreSQL upgrade safe?
Yes: minor releases fix bugs and vulnerabilities only, with the same on-disk format.
Why are there Go CVEs in a PostgreSQL image?
From gosu, the small Go program the entrypoint uses to drop root.
Other image types
Python · Node.js · Java · Go · nginx · Alpine · Debian · Ubuntu · Red Hat UBI