TMAegis
Plus de règles pour postgres

TMA-POSTGRES-4.8

Ensure the set_user extension is installed

MoyenneNiveau 1Automatiséepostgres

Description

PostgreSQL access to the superuser database role must be controlled and audited to prevent unauthorized access. Note: Prior to performing this audit you must create a roletree view. Passes when set_user is available and no login role is a superuser directly or through role membership (the benchmark sets postgres NOLOGIN; then run the scan with PGUSER set to a DBA role). Runs psql as ${PGUSER:-postgres} against ${PGDATABASE:-postgres}; set PGHOST/PGPORT and use ~/.pgpass (not PGPASSWORD, see 1.6/1.7) when peer authentication is not available.

Méthode de vérification

Méthode d'audit: Requête SQL

sql_query
out=$(psql -X -U "${PGUSER:-postgres}" -d "${PGDATABASE:-postgres}" -tAc "SELECT CASE WHEN EXISTS (SELECT 1 FROM pg_available_extensions WHERE name = 'set_user') AND NOT EXISTS (WITH RECURSIVE m(member, roleid) AS (SELECT member, roleid FROM pg_auth_members UNION SELECT m.member, a.roleid FROM m JOIN pg_auth_members a ON a.member = m.roleid) SELECT 1 FROM pg_roles r WHERE r.rolcanlogin AND (r.rolsuper OR EXISTS (SELECT 1 FROM m JOIN pg_roles s ON s.oid = m.roleid WHERE m.member = r.oid AND s.rolsuper))) THEN 'compliant' ELSE 'noncompliant' END" 2>/dev/null) || exit 1; printf '%s\n' "$out"
Sortie attendue
compliant

Méthode de correction

Méthode de correction: Recommandation ou correctif d'infrastructure

Install set_user (dnf install set_user_18), add set_user to shared_preload_libraries, restart, CREATE EXTENSION set_user; GRANT EXECUTE ON FUNCTION set_user(text) to DBA login roles, then ALTER ROLE postgres NOLOGIN; and remove SUPERUSER/LOGIN or superuser role memberships from other login roles.

Propriétés

Systèmes d'exploitation
Tous
Étiquettes
postgresdatabaseauthorizationsuperuser
Référence
CIS PostgreSQL 18 Benchmark v1.0.0 - 4.8 Ensure the set_user extension is installed

Vérifier cet hôte

Exécutez cette commande sur une machine que vous êtes autorisé à auditer. L'analyse est en lecture seule.

shell
tmaegis scan --target postgres