Objective. Learners independently apply all course security controls — authentication, RBAC, SSL, encryption, and auditing — to a preconfigured insecure PostgreSQL instance, producing a hardened database and a completed CIS Benchmark checklist.
This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.
VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.
This lab brings together every security control covered in the course — authentication, role-based access control (RBAC), SSL/TLS, encryption, and auditing — and applies them to a single, intentionally misconfigured PostgreSQL 16 instance. Completing this lab gives you a concrete artifact (a hardened database and a signed checklist) that demonstrates job-ready skills recognized by the PostgreSQL CE (EDB), Oracle DBA CA, Microsoft DP-300, and DAMA CDMP frameworks.
Real production databases are rarely deployed in a perfectly secure state. Licensing constraints, legacy configurations, rushed deployments, and operator error leave gaps. A database administrator must be able to identify those gaps using an authoritative benchmark and close them systematically. The Center for Internet Security (CIS) PostgreSQL Benchmark provides exactly that: a prioritized, evidence-based checklist that maps each item to a specific risk. Working through it item by item is standard professional practice.
When you first log into the lab VM, the PostgreSQL instance will have several deliberate misconfigurations:
Before making any change, record the current state of each setting. Use `SHOW ssl;`, `\du` in psql to list roles and their attributes, and `cat /etc/postgresql/16/main/pg_hba.conf` to capture the authentication rules. This before-state is the evidence baseline for your Hardening Summary Report.
Replace every `trust` entry with `scram-sha-256`, which is the strongest built-in password hashing method PostgreSQL 16 supports. Update `postgresql.conf` to set `password_encryption = scram-sha-256`. After editing, reload the configuration with `SELECT pg_reload_conf();` or `pg_ctlcluster 16 main reload`. Verify by attempting to connect from a remote address without credentials — the connection must be refused.
Generate or install a server certificate and key using OpenSSL. Set `ssl = on` and point `ssl_cert_file` and `ssl_key_file` to the correct paths. Restrict the key file permissions so only the postgres OS user can read it (`chmod 600`). Update `pg_hba.conf` to require SSL for remote connections using the `hostssl` record type and remove plain `host` entries for untrusted networks. Confirm with `SHOW ssl;` returning `on` and by attempting an unencrypted connection, which must fail or be rejected.
Safety note: File permission errors on the SSL key will prevent PostgreSQL from starting. Always test a reload or restart in a maintenance window on production systems and keep a console session open so you are not locked out.
Review all roles with `\du`. Revoke `SUPERUSER`, `CREATEROLE`, and `CREATEDB` from any application or reporting role that does not need them. Use `REVOKE ALL ON ALL TABLES IN SCHEMA public FROM PUBLIC;` to eliminate the default public access that PostgreSQL historically granted. Create purpose-specific roles (for example, `app_readonly`, `app_writer`, `etl_loader`) and grant only the minimum privileges each needs. Verify with `\dp tablename` that permission sets match the intended design.
Install the pgaudit extension and add it to `shared_preload_libraries` in `postgresql.conf`. After restarting, run `CREATE EXTENSION pgaudit;`. Configure `pgaudit.log = 'ddl, role, connection, object'` to capture the categories relevant to a hardening audit. Check `postgresql.log` (or your configured log destination) to confirm that connection attempts, role changes, and DDL statements are appearing. Without audit logs, you cannot prove that attacks were detected — this is a core DAMA data governance control as well.
Using `pgcrypto`, convert the plaintext sensitive column to an encrypted form. A typical pattern uses `pgp_sym_encrypt(plaintext, key)` for storage and `pgp_sym_decrypt(ciphertext, key)` for retrieval. In this lab, you will apply the function to the existing column data and alter the column type to `bytea`. Document the encryption key management approach — even in a lab, note that in production the key must never be stored in the same database.
Your instructor (or a designated peer following a script) will attempt five attacks:
1. Unauthenticated remote connection — must be blocked by `scram-sha-256` and firewall/pg_hba rules.
2. SQL injection probe on a test endpoint — must be logged by pgaudit and blocked by parameterized query design or restricted role privilege.
3. Direct file read of `pg_hba.conf` as a low-privilege OS user — must fail because the file is owned by `postgres` and not world-readable.
4. Privilege escalation via `SET ROLE` — must fail because the attacker's session role has no granted path to a privileged role.
5. Unencrypted connection attempt — must be rejected by `hostssl` rules.
For each attack, capture the error message or log entry. A score of 5 of 5 blocked or logged is required to pass.
Your two-page report must list each configuration change made, the CIS Benchmark item number it satisfies, and at least one piece of evidence — a command output snippet or a log line — confirming the control is active. Use the provided template. Organize the report by control category: Authentication, Transport Security, Authorization, Auditing, Encryption. Your instructor will sign the completed CIS checklist only after reviewing the report and witnessing or reviewing the penetration simulation results.
Always work on the designated lab VM — never on a shared or production system. Confirm with your instructor before making any change outside the lab environment. Keep notes of every command you run; in real DBA work, undocumented changes are a compliance liability.
Answer each question, then check it. Nothing is recorded; this is your own practice.
A free tech program — complimentary, as our commitment to get America working. Help us build VoTechWorks. Tell us what works, what doesn’t, and what you want to learn.