October 25, 2026

Automating PostgreSQL Security: CloudNativePG 1.31 Introduces Native Password Generation and Automated Rotation

automating-postgresql-security-cloudnativepg-1-31-introduces-native-password-generation-and-automated-rotation

automating-postgresql-security-cloudnativepg-1-31-introduces-native-password-generation-and-automated-rotation

SAN FRANCISCO & MILAN — In the rapidly evolving landscape of Kubernetes-native database administration, managing secrets securely has long remained a friction point for DevOps and platform engineering teams. Today, the CloudNativePG open-source project announced a major architectural enhancement set to debut in version 1.31: native, automated generation and scheduled rotation of PostgreSQL user passwords directly within the operator.

Engineered in collaboration with EnterpriseDB (EDB) and community contributors, this feature resolves a long-standing request from enterprise operators who previously relied on external tooling or manual interventions to manage database role credentials. Although currently merged into the development trunk and slated for an official release in the fourth quarter of 2026, the feature is already available for testing via development snapshots.


Main Facts: What CloudNativePG 1.31 Changes for Database Credentials

The upcoming release of CloudNativePG 1.31 fundamentally transforms how declarative roles handle authentication. Previously, the introduction of the DatabaseRole resource in version 1.30 simplified declarative user management and passwordless TLS. However, it left a glaring gap: if a PostgreSQL role required a password, administrators were forced to pre-create and manage the underlying Kubernetes Secret manually. The operator would ingest the password, but its origin, complexity, and lifecycle remained entirely external to the database cluster’s declarative definition.

The new feature closes this gap by allowing the DatabaseRole resource to natively handle its own credential lifecycle. Key capabilities include:

  • Automated Password Generation: The operator can automatically generate strong, cryptographically secure passwords without requiring pre-existing secrets.
  • Scheduled Rotation: Administrators can define explicit lifecycles using duration and renewBefore parameters, automating periodic credential updates.
  • Database-Enforced Lifetimes: PostgreSQL directly enforces the credential expiration using the native VALID UNTIL clause, ensuring that expired passwords fail immediately at the connection layer.
  • Integrated Secret Management: The operator automatically provisions a Kubernetes Secret of type kubernetes.io/basic-auth complete with a pre-formatted .pgpass string for seamless libpq integration.

Chronology: From Declarative Roles to Native Lifecycle Automation

The journey toward comprehensive declarative role management in CloudNativePG has been deliberate, driven by enterprise requirements and community feedback.

July 2026: The Foundation (CloudNativePG 1.30)

When CloudNativePG 1.30 was released, it introduced the DatabaseRole resource, establishing a declarative method for managing database identities and passwordless TLS certificates. While this reduced configuration drift, it retained the security headache of out-of-band password creation. Administrators still had to manage static secrets or integrate complex external tools to handle rotation.

August – September 2026: Identifying the Gap and Engineering a Solution

Enterprise customers at EDB and community contributors repeatedly flagged issue #3788 on GitHub, emphasizing the need for native password management. Development began on bridging the gap between Kubernetes Custom Resources and PostgreSQL’s internal authentication mechanics.

Late October 2026: Pull Request #11337 Merged

On October 24, 2026, Pull Request #11337 was officially merged into the CloudNativePG trunk. This integration introduced the password stanza and the generate mode to the DatabaseRole specification. Although not yet bundled in a stable release, the feature became immediately accessible via development snapshots.

Q4 2026 (Expected): Stable Release

CloudNativePG 1.31 is projected to hit general availability later this quarter, bringing native password generation, rotation, and advanced policy shaping into production-ready environments.


Supporting Data: Technical Implementation and Architecture

To understand how CloudNativePG 1.31 alters the security posture of cloud-native PostgreSQL clusters, it is vital to examine the mechanics of the new password stanza, password shaping parameters, and operational workflows.

The New password Stanza

The DatabaseRole specification now features a dedicated password block requiring an explicit mode field. To eliminate ambiguity—where a misconfigured state might inadvertently create or delete credentials—there is no default mode. Administrators must choose between explicit modes: generate, secret, and setNull (the latter two serving as the explicit equivalents of deprecated parameters).

CNPG Recipe 28 - Generated and rotating PostgreSQL user passwords in CloudNativePG 1.31

When configured for automated generation, a typical resource manifest appears as follows:

apiVersion: postgresql.cnpg.io/v1
kind: DatabaseRole
metadata:
  name: angus
spec:
  cluster:
    name: acdc
  name: angus
  login: true
  password:
    mode: generate
    duration: 720h
    renewBefore: 24h
  databaseRoleReclaimPolicy: delete

In this configuration, a duration of 720 hours establishes a 30-day credential lifecycle. The renewBefore parameter instructs the operator to initiate a rotation 24 hours prior to expiration, resulting in an effective 29-day rotation cadence. This strikes a balance between limiting the blast radius of a compromised credential and avoiding operational fatigue from overly aggressive rotation schedules.

Secret Provisioning and .pgpass Integration

Upon deployment, the operator provisions a Kubernetes Secret named <role-name>-password (e.g., angus-password). This Secret contains three core keys:

  1. username: The name of the database role.
  2. password: The newly generated secure password.
  3. pgpass: A pre-formatted utility string (*:5432:*:angus:<generated-password>) designed to be appended directly to a user’s or application’s ~/.pgpass file.

Furthermore, PostgreSQL stores the password as a SCRAM-SHA-256 verifier while simultaneously setting a hard expiration boundary:

postgres=# SELECT rolname, rolcanlogin, rolvaliduntil
           FROM pg_authid WHERE rolname = 'angus';
 rolname | rolcanlogin |     rolvaliduntil
---------+-------------+------------------------
 angus   | t           | 2026-11-23 09:13:23+00
(1 row)

Advanced Password Shaping and Criteria

By default, the operator generates 24-character strings composed of mixed-case letters and digits, deliberately excluding symbols to prevent escaping issues in connection strings and URIs. However, organizations bound by strict compliance frameworks can utilize a detailed criteria block:

    criteria:
      length: 32
      digits: 6
      symbols: 4
      symbolCharacters: "!#$%&*+-?"
      noUpper: false
      allowRepeat: false

The operator validates these constraints at the API level. If an impossible combination is requested—such as demanding more unique characters than are available in the character set without allowing repetition—the API rejects the manifest outright, logging the error in status.password.message.


Official Responses and Ecosystem Context

The introduction of native password generation bridges a significant architectural divide in cloud-native database security. Speaking on the integration, core maintainers highlighted that while external tools like the External Secrets Operator (ESO) remain vital for organizations utilizing centralized secret vaults (such as HashiCorp Vault), mode: generate democratizes security for self-contained workloads.

"For many use cases, introducing an external vault controller introduces unnecessary operational overhead," noted project contributors in the release documentation. "With mode: generate, the credential is born, lives, and dies with the role itself, requiring zero auxiliary components to maintain health."

For teams that do rely on ESO, integration pathways remain fully supported. Administrators can continue using mode: secret to bridge external vaults directly to CloudNativePG database roles.


Implications: Operational Security and GitOps Workflows

The implementation of automated rotation and database-enforced expiration carries profound implications for enterprise architecture and GitOps-driven operations:

  1. Elimination of Infinite-Life Credentials: By leveraging PostgreSQL’s native VALID UNTIL attribute, organizations eliminate the risk of "zombie credentials"—passwords that persist indefinitely in legacy systems or forgotten configuration files.
  2. Graceful Application Handling: Because PostgreSQL evaluates authentication credentials exclusively at connection time, rotating a password does not disrupt active, established sessions. Applications that implement standard reconnection logic seamlessly pick up the new secret during their next connection attempt.
  3. Streamlined GitOps Management: Infrastructure-as-Code (IaC) pipelines can now declare identity, authentication policies, and rotation schedules within a single unified manifest. Emergency rotations can be triggered on-demand via simple annotations (kubectl annotate databaserole <name> cnpg.io/rotatePassword=now), providing incident responders with immediate remediation tools.
  4. Upcoming TLS Enhancements: CloudNativePG 1.31 is also laying the groundwork for aligned certificate lifecycles. Tracked under issue #11312, upcoming enhancements will bring configurable durations and renewal windows to TLS client certificates, unifying the management of both passwords and certificates under a single administrative model.

As CloudNativePG 1.31 approaches its official release, maintainers are actively encouraging community testing via development snapshots. Platform engineers and database administrators are invited to evaluate the new features and provide feedback via the CloudNativePG CNCF Slack channel or GitHub pull requests to ensure robust production stability upon general availability.