feat(postgres): add an audit toggle for access and statement logging

Managed Postgres could already load pgaudit through the
sharedPreloadLibraries allowlist and set pgaudit.log and log_connections
through postgresql.parameters, but that leaves an orchestrator depending
on internal parameter names to answer who connected and what they ran.

This adds an audit block that bundles access and statement auditing
behind one switch. With audit.enabled the chart adds pgaudit to
shared_preload_libraries and seeds pgaudit.log (from audit.log,
default "write, ddl, role"), log_connections and log_disconnections. The
parameters are seeded as defaults, so an explicit pgaudit.log or
log_connections in postgresql.parameters still wins. The audit trail
goes to the instance log, which the platform log stack already collects,
so it is queryable per database without extra wiring.

Postgres only; the other managed databases are left for follow-ups.

Assisted-by: LLM
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
This commit is contained in:
IvanHunters committed 2026-11-23 17:25:17 +03:00
1 parent 1ab20ea96e
commit 902909dbe7
7 files changed
+177 -3

No files matched your search

+12
View File
@@ -53,6 +53,9 @@ type ConfigSpec struct {
// PostgreSQL server configuration.
// +kubebuilder:default:={}
Postgresql PostgreSQL `json:"postgresql"`
// PostgreSQL audit configuration.
// +kubebuilder:default:={}
Audit Audit `json:"audit"`
// Quorum configuration for synchronous replication.
// +kubebuilder:default:={}
Quorum Quorum `json:"quorum"`
@@ -73,6 +76,15 @@ type ConfigSpec struct {
Bootstrap Bootstrap `json:"bootstrap"`
}
type Audit struct {
// Enable PostgreSQL auditing. Loads the pgaudit extension through the `sharedPreloadLibraries` allowlist and turns on `log_connections`/`log_disconnections`, so who connected and the classes of statement they ran are written to the instance log and collected by the platform log stack. The audited statement classes are set by `log`. Off by default. Enabling or disabling it restarts PostgreSQL, since pgaudit is a preloaded library.
// +kubebuilder:default:=false
Enabled bool `json:"enabled,omitempty"`
// pgaudit session audit classes recorded when `enabled`, as the comma-separated value of `pgaudit.log` (for example `ddl, role`, `write, ddl, role` or `all`; `all` logs every statement including reads and is heavy). Defaults to `write, ddl, role`. A `pgaudit.log` set directly in `postgresql.parameters` overrides this.
// +kubebuilder:default:="write, ddl, role"
Log string `json:"log,omitempty"`
}
type Autoscaling struct {
// Recommendation mode: keep the static count and render the ScaledObject with both scaling directions paused, so KEDA keeps the HPA and keeps serving its trigger metric but actuates neither way. Note both scaling policies are disabled, so the HPA's desiredReplicas is frozen to the current count - read the recommendation from the matching read-load dashboard panel for your metric (connections or CPU): desired = 1 + ceil(read load / target), clamped to [effectiveMin..maxReplicas] where effectiveMin = max(minReplicas, maxSyncReplicas+1, 2), not from the desired-replicas line. Like disabling, flipping a LIVE autoscaled cluster into dryRun re-renders `instances: replicas` (the raw static value, which can be below the autoscaling floor); if `replicas` is below the live count, stage it to the live count first (see the enablement note) or the cluster sheds down to `replicas`. No shed occurs when the rendered value is unchanged (replicas already equals the active seed) — client-side merge is then a no-op and the live count is preserved. Permanent, unlike `transition`.
// +kubebuilder:default:=false