-
Notifications
You must be signed in to change notification settings - Fork 32
🔨 Doc and scripts to create read-only user in PostgreSQL #6426
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
Merged
pcrespov
merged 11 commits into
ITISFoundation:master
from
pcrespov:is1701/pg-readonly-user
Oct 2, 2024
+43
−0
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3941ed9
adds ro user sh
pcrespov 91526ca
new envs and avoids error upon recreationg
pcrespov 539ea0f
tabs
pcrespov 12f3f63
minor
pcrespov 266c0bc
rename base name
pcrespov 38d4af5
adds script
pcrespov 4779d4e
WIP
pcrespov 7a6761a
@YuryHrytsuk review: rm mount on postgres db
pcrespov 28fcf62
minor
pcrespov 179d03b
@YuryHrytsuk review: rm init script on startup
pcrespov 0049779
Merge branch 'master' into is1701/pg-readonly-user
pcrespov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| include ../../scripts/common.Makefile | ||
|
|
||
|
|
||
| ifneq (,$(wildcard $(DOT_ENV_FILE))) | ||
| include $(DOT_ENV_FILE) | ||
| export $(shell sed 's/=.*//' $(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 $<..." | ||
| @envsubst < $< > $@ | ||
| @echo "SQL script generated as $@" |
22 changes: 22 additions & 0 deletions
22
services/postgres/scripts/create-readonly-user.sql.template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| -- SQL script to create a read-only user and grant privileges | ||
|
|
||
|
|
||
| --Create the read-only user with a password | ||
| CREATE USER ${POSTGRES_READONLY_USER} WITH PASSWORD '${POSTGRES_READONLY_PASSWORD}'; | ||
|
|
||
| --Grant CONNECT privilege to the database (e.g., 'foo' is the database name) | ||
| GRANT CONNECT ON DATABASE ${POSTGRES_DB} TO ${POSTGRES_READONLY_USER}; | ||
|
|
||
| --Grant USAGE privilege on the **public** schema | ||
| GRANT USAGE ON SCHEMA public TO ${POSTGRES_READONLY_USER}; | ||
|
|
||
| --Grant SELECT privilege on all existing tables and sequencies in the **public** schema | ||
| GRANT SELECT ON ALL TABLES IN SCHEMA public TO ${POSTGRES_READONLY_USER}; | ||
| GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO ${POSTGRES_READONLY_USER}; | ||
|
|
||
| --Ensure that future tables created in the public schema and sequencies will have SELECT privilege for the read-only user | ||
| ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO ${POSTGRES_READONLY_USER}; | ||
| ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON SEQUENCES TO ${POSTGRES_READONLY_USER}; | ||
|
|
||
| -- Listing all users | ||
| SELECT * FROM pg_roles; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.