Skip to content

Enable audit logs via pgaudit #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions api/v1/postgres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ type PostgresSpec struct {

// BackupSecretRef reference to the secret where the backup credentials are stored
BackupSecretRef string `json:"backupSecretRef,omitempty"`

AuditLogs *bool `json:"auditLogs,omitempty"`
}

// AccessList defines the type of restrictions to access the database
Expand Down Expand Up @@ -447,6 +449,9 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor
z.Spec.NumberOfInstances = p.Spec.NumberOfInstances
z.Spec.PostgresqlParam.PgVersion = p.Spec.Version
z.Spec.PostgresqlParam.Parameters = map[string]string{}
if p.Spec.AuditLogs == nil || *p.Spec.AuditLogs {
enableAuditLogs(z.Spec.PostgresqlParam.Parameters)
}
setSharedBufferSize(z.Spec.PostgresqlParam.Parameters, p.Spec.Size.SharedBuffer)
z.Spec.Resources.ResourceRequests.CPU = p.Spec.Size.CPU
z.Spec.Resources.ResourceRequests.Memory = p.Spec.Size.Memory
Expand Down Expand Up @@ -639,3 +644,12 @@ func setSharedBufferSize(parameters map[string]string, shmSize string) {
}
}
}

// enableAuditLogs configures this postgres instances audit logging
func enableAuditLogs(parameters map[string]string) {
parameters["shared_preload_libraries"] = "pgaudit"
parameters["pgaudit.log_catalog"] = "off"
parameters["pgaudit.log"] = "ddl"
parameters["pgaudit.log_relation"] = "on"
parameters["pgaudit.log_parameter"] = "on"
}
6 changes: 6 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion config/crd/bases/database.fits.cloud_postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.5.0
controller-gen.kubebuilder.io/version: v0.6.1
creationTimestamp: null
name: postgres.database.fits.cloud
spec:
Expand Down Expand Up @@ -65,6 +65,8 @@ spec:
type: string
type: array
type: object
auditLogs:
type: boolean
backupSecretRef:
description: BackupSecretRef reference to the secret where the backup
credentials are stored
Expand Down