Skip to content

Commit 01f20bf

Browse files
Enable pgaudit extension in rds-init (#22)
1 parent f65664e commit 01f20bf

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

cmd/rds-init/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# RDS Database Initialization Tool
22

3-
A utility for initializing and configuring RDS PostgreSQL databases. This tool manages the `nessus_scan_user` account for security scanning and enables RDS IAM authentication for the admin user.
3+
A utility for initializing and configuring RDS PostgreSQL databases. This tool manages the `nessus_scan_user` account for security scanning, enables RDS IAM authentication for the admin user, and enables the `pgaudit` extension for audit logging.
44

55
## Overview
66

7-
This tool performs two main tasks:
7+
This tool performs three main tasks:
88

99
1. **Nessus scan user management** — Creates and maintains a dedicated database user (`nessus_scan_user`) for Nessus security scans, with credentials stored in AWS Secrets Manager.
1010

1111
2. **RDS IAM authentication setup** — Grants the `rds_iam` role to the admin user, enabling IAM-based database authentication for future connections.
1212

13+
3. **pgaudit extension** — Runs `CREATE EXTENSION IF NOT EXISTS pgaudit` so audit logging required by Nessus is active. The parameter group must already include `pgaudit` in `shared_preload_libraries`.
14+
1315
## How It Works
1416

1517
### Nessus User Setup

cmd/rds-init/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ func main() {
254254
log.Printf("Created secret %q in Secrets Manager.", secretName)
255255
}
256256

257+
// pgaudit requires `shared_preload_libraries = pgaudit` in the parameter
258+
// group; CREATE EXTENSION is the per-database step that completes setup.
259+
if _, err := db.ExecContext(ctx, "CREATE EXTENSION IF NOT EXISTS pgaudit"); err != nil {
260+
log.Fatalf("Failed to create pgaudit extension: %v", err)
261+
}
262+
257263
// 1) Ensure user exists (no password embedded)
258264
ensureUserSQL := fmt.Sprintf(`
259265
DO $do$

0 commit comments

Comments
 (0)