Skip to content
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

Don't access database with a superuser. Create dedicated read user #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions puppet/oss/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
- PUPPETDB_USER=${POSTGRES_USER:-puppetdb}
volumes:
- puppetdb:/opt/puppetlabs/server/data/puppetdb
- ./read-database.ini:/etc/puppetlabs/puppetdb/conf.d/read-database.ini:ro
restart: always
ports:
- 8081:8081
Expand All @@ -50,8 +51,8 @@ services:
hostname: postgres
environment:
- POSTGRES_DB=${POSTGRES_DB:-puppetdb}
- POSTGRES_USER=${POSTGRES_USER:-puppetdb}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-puppetdb}
- POSTGRES_USER=${POSTGRES_SUPERUSER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_SUPERUSER_PASSWORD:-postgres}
healthcheck:
test: ["CMD-SHELL", "sh -c 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}'"]
interval: 10s
Expand Down
9 changes: 9 additions & 0 deletions puppet/oss/postgresql_init/roles.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE USER puppetdb PASSWORD 'puppetdb';
CREATE USER puppetdb_read PASSWORD 'puppetdb_read';

REVOKE CREATE ON SCHEMA public FROM public;
GRANT CREATE ON SCHEMA public TO puppetdb;

ALTER DEFAULT PRIVILEGES FOR USER puppetdb IN SCHEMA public GRANT SELECT ON tables TO puppetdb_read;
ALTER DEFAULT PRIVILEGES FOR USER puppetdb IN SCHEMA public GRANT USAGE ON sequences TO puppetdb_read;
ALTER DEFAULT PRIVILEGES FOR USER puppetdb IN SCHEMA public GRANT EXECUTE ON functions TO puppetdb_read;
4 changes: 4 additions & 0 deletions puppet/oss/read-database.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[read-database]
subname = //postgres:5432/puppetdb
username = puppetdb_read
password = puppetdb_read