Privileges for public Schema in PostgreSQL 15+ (#347)

Co-authored-by: Bernard Sarfo Twumasi <bst@smartocean.com>
This commit is contained in:
Bernard Sarfo Twumasi
2024-11-04 20:35:22 +01:00
committed by GitHub
parent 113607aae3
commit 0f810f4077
3 changed files with 25 additions and 3 deletions

View File

@ -1,10 +1,16 @@
USER_TO_REVOKE='__username__'
DB_VERSION='__version__'
DATABASES=$(sudo -u postgres psql -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;")
for DB in $DATABASES; do
echo "Revoking privileges in database: $DB"
sudo -u postgres psql -d "$DB" -c "REVOKE ALL PRIVILEGES ON DATABASE \"$DB\" FROM \"$USER_TO_REVOKE\";"
sudo -u postgres psql -d "$DB" -c "REVOKE ALL PRIVILEGES ON DATABASE \"$DB\" FROM $USER_TO_REVOKE;"
# Check if PostgreSQL version is 15 or greater
if [ "$DB_VERSION" -ge 15 ]; then
sudo -u postgres psql -d "$DB" -c "REVOKE USAGE, CREATE ON SCHEMA public FROM $USER_TO_REVOKE;"
fi
done
echo "Privileges revoked from $USER_TO_REVOKE"