Skip to content

Commit

Permalink
🔨 New sql script template to remove readonly user (ITISFoundation#6500)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored and mrnicegyu11 committed Oct 14, 2024
1 parent 8b34d98 commit 26e7fd6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .env-devel
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ POSTGRES_PORT=5432
POSTGRES_USER=scu

POSTGRES_READONLY_PASSWORD=readonly
POSTGRES_READONLY_USER=readonly
POSTGRES_READONLY_USER=postgres_readonly


RABBIT_HOST=rabbit
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,3 @@ tests/public-api/osparc_python_wheels/*

# osparc-config repo files
repo.config

# scripts resolved with .env s
services/postgres/scripts/create-readonly-user.sql
3 changes: 2 additions & 1 deletion .vscode/settings.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
"files.associations": {
".*rc": "ini",
".env*": "ini",
"*.logs*": "log",
"**/requirements/*.in": "pip-requirements",
"**/requirements/*.txt": "pip-requirements",
"*logs.txt": "log",
"*.logs*": "log",
"*Makefile": "makefile",
"*sql.*": "sql",
"docker-compose*.yml": "dockercompose",
"Dockerfile*": "dockerfile"
},
Expand Down
8 changes: 4 additions & 4 deletions services/postgres/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ ifneq (,$(wildcard $(DOT_ENV_FILE)))
endif


.PHONY: scripts/create-readonly-user.sql
scripts/create-readonly-user.sql: scripts/create-readonly-user.sql.template
@echo "Generating SQL script from $<..."

scripts/%.sql: scripts/%.sql.template
@echo "Generating SQL script from '$<'..."
@envsubst < $< > $@
@echo "SQL script generated as $@"
@echo "SQL script generated as '$@'"
3 changes: 3 additions & 0 deletions services/postgres/scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!*.template.*
16 changes: 16 additions & 0 deletions services/postgres/scripts/remove-readonly-user.sql.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Revoke all privileges the user has on the public schema
REVOKE ALL PRIVILEGES ON SCHEMA public FROM ${POSTGRES_READONLY_USER};

-- Revoke all privileges the user has on tables and sequences in the public schema
REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM ${POSTGRES_READONLY_USER};
REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM ${POSTGRES_READONLY_USER};

-- Revoke any future privileges set via ALTER DEFAULT PRIVILEGES
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON TABLES FROM ${POSTGRES_READONLY_USER};
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON SEQUENCES FROM ${POSTGRES_READONLY_USER};

-- Drop the user
DROP USER ${POSTGRES_READONLY_USER};

-- Listing all users
SELECT * FROM pg_roles;

0 comments on commit 26e7fd6

Please sign in to comment.