Skip to content

Commit 26e7fd6

Browse files
pcrespovmrnicegyu11
authored andcommitted
🔨 New sql script template to remove readonly user (ITISFoundation#6500)
1 parent 8b34d98 commit 26e7fd6

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

‎.env-devel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ POSTGRES_PORT=5432
154154
POSTGRES_USER=scu
155155

156156
POSTGRES_READONLY_PASSWORD=readonly
157-
POSTGRES_READONLY_USER=readonly
157+
POSTGRES_READONLY_USER=postgres_readonly
158158

159159

160160
RABBIT_HOST=rabbit

‎.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,3 @@ tests/public-api/osparc_python_wheels/*
181181

182182
# osparc-config repo files
183183
repo.config
184-
185-
# scripts resolved with .env s
186-
services/postgres/scripts/create-readonly-user.sql

‎.vscode/settings.template.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
"files.associations": {
1010
".*rc": "ini",
1111
".env*": "ini",
12+
"*.logs*": "log",
1213
"**/requirements/*.in": "pip-requirements",
1314
"**/requirements/*.txt": "pip-requirements",
1415
"*logs.txt": "log",
15-
"*.logs*": "log",
1616
"*Makefile": "makefile",
17+
"*sql.*": "sql",
1718
"docker-compose*.yml": "dockercompose",
1819
"Dockerfile*": "dockerfile"
1920
},

‎services/postgres/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ ifneq (,$(wildcard $(DOT_ENV_FILE)))
77
endif
88

99

10-
.PHONY: scripts/create-readonly-user.sql
11-
scripts/create-readonly-user.sql: scripts/create-readonly-user.sql.template
12-
@echo "Generating SQL script from $<..."
10+
11+
scripts/%.sql: scripts/%.sql.template
12+
@echo "Generating SQL script from '$<'..."
1313
@envsubst < $< > $@
14-
@echo "SQL script generated as $@"
14+
@echo "SQL script generated as '$@'"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!.gitignore
3+
!*.template.*
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Revoke all privileges the user has on the public schema
2+
REVOKE ALL PRIVILEGES ON SCHEMA public FROM ${POSTGRES_READONLY_USER};
3+
4+
-- Revoke all privileges the user has on tables and sequences in the public schema
5+
REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM ${POSTGRES_READONLY_USER};
6+
REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM ${POSTGRES_READONLY_USER};
7+
8+
-- Revoke any future privileges set via ALTER DEFAULT PRIVILEGES
9+
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON TABLES FROM ${POSTGRES_READONLY_USER};
10+
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON SEQUENCES FROM ${POSTGRES_READONLY_USER};
11+
12+
-- Drop the user
13+
DROP USER ${POSTGRES_READONLY_USER};
14+
15+
-- Listing all users
16+
SELECT * FROM pg_roles;

0 commit comments

Comments
 (0)