Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/pg_repack.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,15 @@ LANGUAGE C STABLE STRICT;
CREATE FUNCTION repack.get_table_and_inheritors(regclass) RETURNS regclass[] AS
'MODULE_PATHNAME', 'repack_get_table_and_inheritors'
LANGUAGE C STABLE STRICT;

-- discussion of the security model is in https://github.com/reorg/pg_repack/pull/475
--
-- non-superusers need to be granted CREATE on the repack schema
-- after this grant, they can repack their own tables with --no-superuser-check
--
-- pg_repack is not compatible with pg_maintain for allowing non-superusers
-- to repack tables they don't own
--
GRANT USAGE ON SCHEMA repack TO PUBLIC;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA repack TO PUBLIC;
GRANT SELECT ON ALL TABLES IN SCHEMA repack TO PUBLIC;
22 changes: 13 additions & 9 deletions regress/expected/nosuper.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SET client_min_messages = error;
DROP ROLE IF EXISTS nosuper;
SET client_min_messages = warning;
CREATE ROLE nosuper WITH LOGIN;
GRANT CREATE ON SCHEMA repack TO nosuper;
-- => OK
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check
INFO: repacking table "public.tbl_cluster"
Expand All @@ -13,16 +14,19 @@ INFO: repacking table "public.tbl_cluster"
ERROR: pg_repack failed with error: You must be a superuser to use pg_repack
-- => ERROR
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check
ERROR: pg_repack failed with error: ERROR: permission denied for schema repack
LINE 1: select repack.version(), repack.version_sql()
^
GRANT ALL ON ALL TABLES IN SCHEMA repack TO nosuper;
GRANT USAGE ON SCHEMA repack TO nosuper;
-- => ERROR
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check
INFO: repacking table "public.tbl_cluster"
WARNING: lock_exclusive() failed for public.tbl_cluster
ERROR: permission denied for table tbl_cluster
REVOKE ALL ON ALL TABLES IN SCHEMA repack FROM nosuper;
REVOKE USAGE ON SCHEMA repack FROM nosuper;
CREATE SCHEMA nosuper;
GRANT ALL ON SCHEMA nosuper TO nosuper;
SET SESSION AUTHORIZATION nosuper;
CREATE TABLE nosuper.nosuper_test (id SERIAL PRIMARY KEY, data TEXT);
INSERT INTO nosuper.nosuper_test (data) VALUES ('row1'), ('row2');
RESET SESSION AUTHORIZATION;
-- => OK
\! pg_repack --dbname=contrib_regression --table=nosuper.nosuper_test --username=nosuper --no-superuser-check
INFO: repacking table "nosuper.nosuper_test"
DROP TABLE IF EXISTS nosuper.nosuper_test;
DROP SCHEMA IF EXISTS nosuper;
REVOKE CREATE ON SCHEMA repack FROM nosuper;
DROP ROLE IF EXISTS nosuper;
22 changes: 13 additions & 9 deletions regress/expected/nosuper_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SET client_min_messages = error;
DROP ROLE IF EXISTS nosuper;
SET client_min_messages = warning;
CREATE ROLE nosuper WITH LOGIN;
GRANT CREATE ON SCHEMA repack TO nosuper;
-- => OK
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check
INFO: repacking table "public.tbl_cluster"
Expand All @@ -13,16 +14,19 @@ INFO: repacking table "public.tbl_cluster"
ERROR: pg_repack failed with error: You must be a superuser to use pg_repack
-- => ERROR
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check
ERROR: pg_repack failed with error: ERROR: permission denied for schema repack
LINE 1: select repack.version(), repack.version_sql()
^
GRANT ALL ON ALL TABLES IN SCHEMA repack TO nosuper;
GRANT USAGE ON SCHEMA repack TO nosuper;
-- => ERROR
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check
INFO: repacking table "public.tbl_cluster"
WARNING: lock_exclusive() failed for public.tbl_cluster
ERROR: permission denied for relation tbl_cluster
REVOKE ALL ON ALL TABLES IN SCHEMA repack FROM nosuper;
REVOKE USAGE ON SCHEMA repack FROM nosuper;
CREATE SCHEMA nosuper;
GRANT ALL ON SCHEMA nosuper TO nosuper;
SET SESSION AUTHORIZATION nosuper;
CREATE TABLE nosuper.nosuper_test (id SERIAL PRIMARY KEY, data TEXT);
INSERT INTO nosuper.nosuper_test (data) VALUES ('row1'), ('row2');
RESET SESSION AUTHORIZATION;
-- => OK
\! pg_repack --dbname=contrib_regression --table=nosuper.nosuper_test --username=nosuper --no-superuser-check
INFO: repacking table "nosuper.nosuper_test"
DROP TABLE IF EXISTS nosuper.nosuper_test;
DROP SCHEMA IF EXISTS nosuper;
REVOKE CREATE ON SCHEMA repack FROM nosuper;
DROP ROLE IF EXISTS nosuper;
19 changes: 13 additions & 6 deletions regress/sql/nosuper.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@ SET client_min_messages = error;
DROP ROLE IF EXISTS nosuper;
SET client_min_messages = warning;
CREATE ROLE nosuper WITH LOGIN;
GRANT CREATE ON SCHEMA repack TO nosuper;

-- => OK
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check
-- => ERROR
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper
-- => ERROR
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check

GRANT ALL ON ALL TABLES IN SCHEMA repack TO nosuper;
GRANT USAGE ON SCHEMA repack TO nosuper;
CREATE SCHEMA nosuper;
GRANT ALL ON SCHEMA nosuper TO nosuper;
SET SESSION AUTHORIZATION nosuper;
CREATE TABLE nosuper.nosuper_test (id SERIAL PRIMARY KEY, data TEXT);
INSERT INTO nosuper.nosuper_test (data) VALUES ('row1'), ('row2');
RESET SESSION AUTHORIZATION;

-- => ERROR
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check
-- => OK
\! pg_repack --dbname=contrib_regression --table=nosuper.nosuper_test --username=nosuper --no-superuser-check

REVOKE ALL ON ALL TABLES IN SCHEMA repack FROM nosuper;
REVOKE USAGE ON SCHEMA repack FROM nosuper;
DROP TABLE IF EXISTS nosuper.nosuper_test;
DROP SCHEMA IF EXISTS nosuper;
REVOKE CREATE ON SCHEMA repack FROM nosuper;
DROP ROLE IF EXISTS nosuper;