Skip to content

Commit ceb63cc

Browse files
shusaanNiccoloFeigbartolini
authored
feat: add pgaudit extension (#1)
Closes #22 Signed-off-by: Husn E Rabbi <[email protected]> Signed-off-by: Niccolò Fei <[email protected]> Signed-off-by: Gabriele Bartolini <[email protected]> Co-authored-by: Niccolò Fei <[email protected]> Co-authored-by: Gabriele Bartolini <[email protected]>
1 parent 297c539 commit ceb63cc

File tree

5 files changed

+119
-2
lines changed

5 files changed

+119
-2
lines changed

.github/workflows/bake.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
options:
1212
- pgvector
1313
- postgis
14+
- pgaudit
1415

1516
defaults:
1617
run:
@@ -41,6 +42,8 @@ jobs:
4142
- 'pgvector/**'
4243
postgis:
4344
- 'postgis/**'
45+
pgaudit:
46+
- 'pgaudit/**'
4447
4548
# Compute a matrix containing the list of all extensions that have been modified
4649
- name: Compute matrix

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ For detailed instructions on building the images, see the [BUILD.md file](BUILD.
2222

2323
## Supported Extensions
2424

25-
- [pgvector](pgvector) - Open-source vector similarity search for PostgreSQL
26-
- [PostGIS](postgis) - Open-source geospatial database extension for PostgreSQL
25+
- [pgvector](pgvector) - Vector similarity search for PostgreSQL
26+
- [PostGIS](postgis) - Geospatial database extension for PostgreSQL
27+
- [pgAudit](pgaudit) - PostgreSQL Audit Extension
2728

2829
---
2930

pgaudit/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
2+
FROM $BASE AS builder
3+
4+
ARG PG_MAJOR
5+
ARG EXT_VERSION
6+
7+
USER 0
8+
9+
RUN set -eux; \
10+
apt-get update; \
11+
apt-get install -y --no-install-recommends "postgresql-${PG_MAJOR}-pgaudit=${EXT_VERSION}"
12+
13+
FROM scratch
14+
ARG PG_MAJOR
15+
16+
# Licenses
17+
COPY --from=builder /usr/share/doc/postgresql-${PG_MAJOR}-pgaudit/copyright /licenses/postgresql-${PG_MAJOR}-pgaudit/
18+
19+
# Libraries
20+
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pgaudit* /lib/
21+
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/ /lib/bitcode/
22+
23+
# Share
24+
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/pgaudit* /share/extension/
25+
26+
USER 65532:65532

pgaudit/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# pgAudit Extension
2+
3+
[pgAudit](https://github.com/pgaudit/pgaudit) is an open-source extension
4+
that provides detailed session and/or object audit logging for PostgreSQL.
5+
6+
## Usage
7+
8+
### 1. Add the pgAudit extension image to your Cluster
9+
10+
Define the `pgaudit` extension under the `postgresql.extensions` section of
11+
your `Cluster` resource. For example:
12+
13+
```yaml
14+
apiVersion: postgresql.cnpg.io/v1
15+
kind: Cluster
16+
metadata:
17+
name: cluster-pgaudit
18+
spec:
19+
imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
20+
instances: 1
21+
22+
storage:
23+
size: 1Gi
24+
25+
postgresql:
26+
shared_preload_libraries:
27+
- "pgaudit"
28+
parameters:
29+
pgaudit.log: "all, -misc"
30+
pgaudit.log_catalog: "off"
31+
pgaudit.log_parameter: "on"
32+
pgaudit.log_relation: "on"
33+
34+
extensions:
35+
- name: pgaudit
36+
image:
37+
reference: ghcr.io/cloudnative-pg/pgaudit:18.0-18-trixie
38+
```
39+
40+
### 2. Enable the extension in a database
41+
42+
You can install `pgaudit` in a specific database by creating or updating a
43+
`Database` resource. For example, to enable it in the `app` database:
44+
45+
```yaml
46+
apiVersion: postgresql.cnpg.io/v1
47+
kind: Database
48+
metadata:
49+
name: cluster-pgaudit-app
50+
spec:
51+
name: app
52+
owner: app
53+
cluster:
54+
name: cluster-pgaudit
55+
extensions:
56+
- name: pgaudit
57+
```
58+
59+
### 3. Verify installation
60+
61+
Once the database is ready, connect to it with `psql` and run:
62+
63+
```sql
64+
\dx
65+
```
66+
67+
You should see `pgaudit` listed among the installed extensions.

pgaudit/metadata.hcl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
metadata = {
2+
name = "pgaudit"
3+
sql_name = "pgaudit"
4+
image_name = "pgaudit"
5+
shared_preload_libraries = ["pgaudit"]
6+
extension_control_path = []
7+
dynamic_library_path = []
8+
ld_library_path = []
9+
10+
versions = {
11+
bookworm = {
12+
// renovate: suite=bookworm-pgdg depName=postgresql-18-pgaudit
13+
"18" = "18.0-2.pgdg12+1"
14+
}
15+
trixie = {
16+
// renovate: suite=trixie-pgdg depName=postgresql-18-pgaudit
17+
"18" = "18.0-2.pgdg13+1"
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)