Summary
Harden the PostgreSQL host-based authentication (pg_hba.conf) rules that the operator generates for the underlying CloudNative-PG cluster. Today they grant trust authentication to every address, which is overly permissive.
Background
Raised by @hossain-rayhan during review of #374:
Maybe we need to open a separate issue to make this more restricted?
(See review comment.)
In operator/src/internal/cnpg/cnpg_cluster.go (buildPostgresConfiguration), the operator sets:
pgHBA := []string{
"host all all 0.0.0.0/0 trust",
"host all all ::0/0 trust",
"host replication all all trust",
}
These rules allow any client from any IPv4/IPv6 address to connect with trust (no password / no TLS client verification) for both regular and replication connections.
Proposed work
- Replace the blanket
trust rules with more restrictive entries — for example, scope source CIDRs to the cluster's pod/service networks and require a stronger auth method (such as scram-sha-256 or certificate auth) instead of trust, especially for replication.
- Keep TLS / gateway connectivity working (the gateway and intra-cluster replication must still connect).
- Make the behavior consistent across single-region and multi-region (cross-cluster replication) deployments.
- Add/extend tests to cover the generated
pg_hba rules.
Acceptance criteria
References
Summary
Harden the PostgreSQL host-based authentication (
pg_hba.conf) rules that the operator generates for the underlying CloudNative-PG cluster. Today they granttrustauthentication to every address, which is overly permissive.Background
Raised by @hossain-rayhan during review of #374:
(See review comment.)
In
operator/src/internal/cnpg/cnpg_cluster.go(buildPostgresConfiguration), the operator sets:These rules allow any client from any IPv4/IPv6 address to connect with
trust(no password / no TLS client verification) for both regular and replication connections.Proposed work
trustrules with more restrictive entries — for example, scope source CIDRs to the cluster's pod/service networks and require a stronger auth method (such asscram-sha-256or certificate auth) instead oftrust, especially for replication.pg_hbarules.Acceptance criteria
pg_hbarules no longer usetrustfor0.0.0.0/0/::0/0.References
operator/src/internal/cnpg/cnpg_cluster.go—buildPostgresConfiguration