TMAegis
More rules for postgres

TMA-POSTGRES-1.7

Verify That the 'PGPASSWORD' Environment Variable is Not in Use

MediumLevel 1Automatedpostgres

Description

PostgreSQL can read a default database password from an environment variable called PGPASSWORD. Run as root; counts processes whose environment contains PGPASSWORD (including the scanner itself if it was given PGPASSWORD).

How it is checked

Audit method: Shell command

shell
[ "$(id -u)" -eq 0 ] || exit 1; n=$(grep -lsaz '^PGPASSWORD=' /proc/[0-9]*/environ 2>/dev/null | wc -l); echo "$n"
Expected output
0

How it is fixed

Fix method: Guidance or infrastructure patch

Find the processes (grep -lsaz ^PGPASSWORD= /proc/*/environ) and change the users or scripts that export PGPASSWORD to use ~/.pgpass or another secure method.

Properties

Operating systems
Any
Tags
postgresdatabasecredentials
Reference
CIS PostgreSQL 18 Benchmark v1.0.0 - 1.7 Verify That the 'PGPASSWORD' Environment Variable is Not in Use

Check this host

Run this on a machine you are allowed to audit. The scan is read-only.

shell
tmaegis scan --target postgres