Summary
CloudNativePG (CNPG) sets role passwords by interpolating the cleartext value into a utility statement (ALTER ROLE "x" WITH PASSWORD '<cleartext>') and executing it. Utility statements are not parameterised, so the literal is captured by pg_stat_statements when pg_stat_statements.track_utility is on.
In a deployment shape where a tenant-facing role can read those statistics, the tenant can recover the platform-managed superuser and application-owner passwords from pg_stat_statements on every rotation, reconnect as the superuser, and — where superuser TCP access is enabled — reach OS command execution inside the database pod via COPY ... PROGRAM.
The earlier mitigation in PR #9950 suppressed log_statement / log_min_error_statement only. pg_stat_statements is a separate subsystem and was not addressed by that change.
Severity and affected configurations
The full chain requires three conditions, none of which is present in a default CNPG installation:
pg_stat_statements in shared_preload_libraries (not loaded by default).
- A tenant role granted
pg_monitor or pg_read_all_stats (not provisioned by default).
- Superuser TCP access via
enableSuperuserAccess: true (disabled by default; the postgres role is not reachable over the network in a standard cluster).
A default CNPG cluster is therefore not an affected configuration. The issue is material for managed-DBaaS products built on CNPG that preload pg_stat_statements for query-insights UIs, grant pg_monitor to tenant roles and expose superuser credentials over TCP. Clusters that already supply a SCRAM-SHA-256 verifier in the managed-role Secret are not affected even before the fix, because the stored literal is a non-replayable hash rather than cleartext.
Scored against an affected configuration, the impact is High to Critical (CWE-256, CWE-522); see the CVSS metrics in the sidebar.
Affected and fixed versions
- Affected: all releases prior to the fixed versions below, in an affected configuration.
- Fixed in: 1.28.4, 1.29.2 and 1.30.0.
- Remediation: see PR #10724.
Root cause
The operator builds ALTER ROLE / CREATE ROLE statements with the password embedded as a SQL literal (SetUserPassword in pkg/management/postgres/utils/roles.go, and appendPasswordOption in internal/management/controller/roles/postgres.go). pq.QuoteLiteral makes the SQL parseable; it does not redact. The cleartext bytes are recorded by pg_stat_statements because utility statements are not parameterised.
These paths run on every secret-version change for postgres and the application owner, and on every reconciliation cycle that touches a managed role with a password. ExecWithSuppressedLogging (added in PR #9950) wraps the statement in SET LOCAL log_statement = 'none' plus SET LOCAL log_min_error_statement = 'PANIC', which covers server logs only; pg_stat_statements is governed by pg_stat_statements.track_utility and is unaffected.
Attack chain (on an affected configuration)
- Connect as a tenant role holding
pg_monitor / pg_read_all_stats.
- Read the cleartext credentials from
pg_stat_statements: SELECT query FROM pg_stat_statements WHERE query ILIKE 'ALTER ROLE%PASSWORD%', which returns rows such as ALTER ROLE "postgres" WITH PASSWORD '<cleartext>' for every rotation still in the ring buffer.
- Reconnect as
postgres using the recovered password (requires superuser TCP access to be enabled).
- Execute OS commands as
postgres in the pod via COPY ... FROM PROGRAM, reaching the pod ServiceAccount token. The subsequent blast radius is bounded by the RBAC granted to that ServiceAccount and any cloud workload identity.
Remediation
The fix (PR #10724) computes a SCRAM-SHA-256 verifier client-side and emits that as the password literal in SetUserPassword and appendPasswordOption. PostgreSQL accepts a pre-formatted verifier and stores it as-is; the verifier is not a directly replayable credential, so its appearance in pg_stat_statements, the on-disk stats file, observability pipelines or pg_stat_activity no longer yields a working password.
ExecWithSuppressedLogging is retained as defence-in-depth for the remaining cleartext paths and to guard against regressions.
Operators who cannot upgrade immediately can mitigate by supplying a SCRAM-SHA-256 verifier in managed-role Secrets, not granting pg_monitor / pg_read_all_stats to untrusted roles, and keeping enableSuperuserAccess disabled.
Credit
Reported by Mehmet Ince (mehmetince.net), @mdisec.
Summary
CloudNativePG (CNPG) sets role passwords by interpolating the cleartext value into a utility statement (
ALTER ROLE "x" WITH PASSWORD '<cleartext>') and executing it. Utility statements are not parameterised, so the literal is captured bypg_stat_statementswhenpg_stat_statements.track_utilityis on.In a deployment shape where a tenant-facing role can read those statistics, the tenant can recover the platform-managed superuser and application-owner passwords from
pg_stat_statementson every rotation, reconnect as the superuser, and — where superuser TCP access is enabled — reach OS command execution inside the database pod viaCOPY ... PROGRAM.The earlier mitigation in PR #9950 suppressed
log_statement/log_min_error_statementonly.pg_stat_statementsis a separate subsystem and was not addressed by that change.Severity and affected configurations
The full chain requires three conditions, none of which is present in a default CNPG installation:
pg_stat_statementsinshared_preload_libraries(not loaded by default).pg_monitororpg_read_all_stats(not provisioned by default).enableSuperuserAccess: true(disabled by default; thepostgresrole is not reachable over the network in a standard cluster).A default CNPG cluster is therefore not an affected configuration. The issue is material for managed-DBaaS products built on CNPG that preload
pg_stat_statementsfor query-insights UIs, grantpg_monitorto tenant roles and expose superuser credentials over TCP. Clusters that already supply a SCRAM-SHA-256 verifier in the managed-role Secret are not affected even before the fix, because the stored literal is a non-replayable hash rather than cleartext.Scored against an affected configuration, the impact is High to Critical (CWE-256, CWE-522); see the CVSS metrics in the sidebar.
Affected and fixed versions
Root cause
The operator builds
ALTER ROLE/CREATE ROLEstatements with the password embedded as a SQL literal (SetUserPasswordinpkg/management/postgres/utils/roles.go, andappendPasswordOptionininternal/management/controller/roles/postgres.go).pq.QuoteLiteralmakes the SQL parseable; it does not redact. The cleartext bytes are recorded bypg_stat_statementsbecause utility statements are not parameterised.These paths run on every secret-version change for
postgresand the application owner, and on every reconciliation cycle that touches a managed role with a password.ExecWithSuppressedLogging(added in PR #9950) wraps the statement inSET LOCAL log_statement = 'none'plusSET LOCAL log_min_error_statement = 'PANIC', which covers server logs only;pg_stat_statementsis governed bypg_stat_statements.track_utilityand is unaffected.Attack chain (on an affected configuration)
pg_monitor/pg_read_all_stats.pg_stat_statements:SELECT query FROM pg_stat_statements WHERE query ILIKE 'ALTER ROLE%PASSWORD%', which returns rows such asALTER ROLE "postgres" WITH PASSWORD '<cleartext>'for every rotation still in the ring buffer.postgresusing the recovered password (requires superuser TCP access to be enabled).postgresin the pod viaCOPY ... FROM PROGRAM, reaching the pod ServiceAccount token. The subsequent blast radius is bounded by the RBAC granted to that ServiceAccount and any cloud workload identity.Remediation
The fix (PR #10724) computes a SCRAM-SHA-256 verifier client-side and emits that as the password literal in
SetUserPasswordandappendPasswordOption. PostgreSQL accepts a pre-formatted verifier and stores it as-is; the verifier is not a directly replayable credential, so its appearance inpg_stat_statements, the on-disk stats file, observability pipelines orpg_stat_activityno longer yields a working password.ExecWithSuppressedLoggingis retained as defence-in-depth for the remaining cleartext paths and to guard against regressions.Operators who cannot upgrade immediately can mitigate by supplying a SCRAM-SHA-256 verifier in managed-role Secrets, not granting
pg_monitor/pg_read_all_statsto untrusted roles, and keepingenableSuperuserAccessdisabled.Credit
Reported by Mehmet Ince (mehmetince.net), @mdisec.