Skip to content

Commit

Permalink
Check if schema already exists before create extension [BF-2375]
Browse files Browse the repository at this point in the history
If the schema aiven_extras already exists and belongs to an
unprivileged user before adding the extension, it’s possible
to abuse it to run some queries in the context of the superuser.

[BF-2375]
  • Loading branch information
0xlianhu committed Feb 14, 2024
1 parent 2ad4fc1 commit 005a008
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
short_ver = 1.1.11
last_ver = 1.1.10
short_ver = 1.1.12
last_ver = 1.1.11
long_ver = $(shell git describe --long 2>/dev/null || echo $(short_ver)-0-unknown-g`git describe --always`)
generated = aiven_extras.control \
sql/aiven_extras--$(short_ver).sql \
Expand Down
1 change: 1 addition & 0 deletions sql/aiven_extras--1.1.10--1.1.11.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- NOOP
11 changes: 11 additions & 0 deletions sql/aiven_extras.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
-- Check that if schema already exist
DO $$
BEGIN
IF EXISTS (
SELECT * FROM information_schema.schemata WHERE schema_name = 'aiven_extras' AND schema_owner <> current_user
) THEN
RAISE EXCEPTION 'Cannot create extension, schema ''aiven_extras'' owned by other user already exists';
END IF;
END
$$ LANGUAGE 'plpgsql';

DO LANGUAGE plpgsql
$OUTER$
DECLARE
Expand Down

0 comments on commit 005a008

Please sign in to comment.