lab7: PKI, mTLS infra, OpenBao non-dev, hardening, lifecycle scripts
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
-- Lab 7 least-privilege PostgreSQL roles & schema ownership.
|
||||
-- Executed by postgres superuser on initial initdb (and idempotently re-applied
|
||||
-- by scripts/openbao-bootstrap.sh). Runtime passwords and LOGIN are enabled only
|
||||
-- after OpenBao generates scoped credentials.
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'messenger_migrator') THEN
|
||||
CREATE ROLE messenger_migrator NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN;
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'messenger_api') THEN
|
||||
CREATE ROLE messenger_api NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN;
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'messenger_worker') THEN
|
||||
CREATE ROLE messenger_worker NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN;
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
|
||||
|
||||
ALTER SCHEMA public OWNER TO messenger_migrator;
|
||||
|
||||
REVOKE ALL ON DATABASE messenger FROM PUBLIC;
|
||||
REVOKE ALL ON SCHEMA public FROM PUBLIC;
|
||||
|
||||
GRANT CONNECT ON DATABASE messenger TO messenger_migrator, messenger_api, messenger_worker;
|
||||
GRANT USAGE, CREATE ON SCHEMA public TO messenger_migrator;
|
||||
GRANT USAGE ON SCHEMA public TO messenger_api, messenger_worker;
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Copies read-only mounted TLS material into container-private tmpfs with 0600
|
||||
# key permissions required by PostgreSQL under non-root UID 70:70.
|
||||
set -eu
|
||||
|
||||
cert_dir=/var/run/postgresql/certs
|
||||
mkdir -p "$cert_dir"
|
||||
chmod 0700 "$cert_dir"
|
||||
|
||||
cp /run/certs/ca.crt "$cert_dir/ca.crt"
|
||||
cp /run/certs/ca.crl "$cert_dir/ca.crl"
|
||||
cp /run/certs/server.crt "$cert_dir/server.crt"
|
||||
cp /run/certs/server.key "$cert_dir/server.key"
|
||||
|
||||
chmod 0644 "$cert_dir/ca.crt" "$cert_dir/ca.crl" "$cert_dir/server.crt"
|
||||
chmod 0600 "$cert_dir/server.key"
|
||||
|
||||
exec docker-entrypoint.sh "$@"
|
||||
@@ -0,0 +1,9 @@
|
||||
# Lab 7 PostgreSQL client authentication configuration.
|
||||
# Local Unix socket allowed only for postgres superuser (healthcheck & operator maintenance).
|
||||
local all postgres peer
|
||||
# Mandatory TLS + SCRAM-SHA-256 for all network connections to application DB.
|
||||
hostssl messenger all 0.0.0.0/0 scram-sha-256
|
||||
hostssl messenger all ::/0 scram-sha-256
|
||||
# Reject all plaintext TCP connections explicitly.
|
||||
hostnossl all all 0.0.0.0/0 reject
|
||||
hostnossl all all ::/0 reject
|
||||
Reference in New Issue
Block a user