Summary
CloudNativePG generated PostgreSQL role-management statements containing cleartext passwords, allowing sensitive credentials to be recorded by pg_stat_statements under certain monitoring configurations. An untrusted tenant with pg_monitor or pg_read_all_stats access could recover managed passwords and, where superuser TCP access was enabled, use them to execute operating system commands in the database pod.
Affected context
The issue occurs in CloudNativePG clusters where platform-managed passwords are applied through generated ALTER ROLE or CREATE ROLE statements, pg_stat_statements is preloaded with track_utility enabled, and an untrusted tenant has access to statistics views through pg_monitor or pg_read_all_stats. Clusters using SCRAM-SHA-256 verifiers in managed-role Secrets are not affected by this exposure path.
Exploit preconditions
- Attack surface: PostgreSQL statistics and role-management activity within a CloudNativePG-managed cluster
- Required access: An untrusted tenant must hold pg_monitor or pg_read_all_stats privileges
- Trigger point: A managed role password is set or changed while pg_stat_statements tracks utility statements
- Why exploitation is possible: Generated SQL includes the cleartext password, which may be retained in query statistics and exposed to authorized statistics readers
- Additional condition for command execution: Recovered credentials must permit a connection with sufficient database privileges, and superuser TCP access must be enabled
Why this happens
The underlying bug is the inclusion of cleartext credentials in SQL statements generated for role management. When utility statements are tracked, these credentials can become observable through PostgreSQL statement statistics to principals that were not intended to receive the password.
This behavior maps primarily to CWE-256: Plaintext Storage of a Password, because a secret is exposed in a recoverable cleartext form, and secondarily to CWE-522: Insufficiently Protected Credentials, because access to monitoring data can disclose credentials with elevated privileges.
Potential impact
- Managed superuser or application-owner passwords could be disclosed.
- An attacker could authenticate to PostgreSQL using recovered credentials.
- Database contents and configuration could be accessed or modified.
- An attacker could execute operating system commands in the database pod where database privileges and server configuration permit it.
- The database pod or surrounding Kubernetes environment could be compromised.
General mitigation guidance
Mitigation generally focuses on preventing secrets from appearing in observable SQL text and reducing the privileges that can view database telemetry.
Common defensive patterns include:
- Applying role passwords through mechanisms that do not place cleartext credentials in tracked SQL statements.
- Using verifier-based secret handling, such as SCRAM-SHA-256 verifiers, where compatible with the deployment.
- Restricting pg_monitor and pg_read_all_stats privileges to trusted operators and services.
- Disabling or tightly controlling utility-statement tracking when it is not required.
- Limiting superuser network access and avoiding unnecessary database-to-operating-system execution capabilities.
- Running database pods with least-privilege identities, restricted capabilities, and strong network policies.
- Rotating credentials that may have been exposed through statement statistics or related telemetry.
How teams detect issues like this
Detection can combine configuration review, telemetry inspection, and source analysis:
- Search PostgreSQL statistics data and exported observability systems for role-management statements containing password material.
- Review whether pg_stat_statements is preloaded with track_utility enabled in clusters containing sensitive managed roles.
- Audit membership in pg_monitor and pg_read_all_stats, especially for tenant-facing roles.
- Inspect application and controller code for string construction that embeds secrets in ALTER ROLE or CREATE ROLE statements.
- Use static-analysis rules and code-review checks to flag credentials interpolated into SQL, logging, metrics, or tracing paths.
- Enforce policies that prevent sensitive values from appearing in query text and restrict superuser TCP access.

