Check table ownership in mark_tables_colocated

pull/2483/head
Marco Slot 2018-11-17 00:01:14 +01:00
parent 18acd00553
commit e17025e1d4
3 changed files with 23 additions and 7 deletions

View File

@ -78,8 +78,9 @@ mark_tables_colocated(PG_FUNCTION_ARGS)
"operation")));
}
EnsureCoordinator();
CheckCitusVersion(ERROR);
EnsureCoordinator();
EnsureTableOwner(sourceRelationId);
relationIdDatumArray = DeconstructArrayObject(relationIdArrayObject);
@ -87,6 +88,9 @@ mark_tables_colocated(PG_FUNCTION_ARGS)
{
Oid nextRelationOid = DatumGetObjectId(relationIdDatumArray[relationIndex]);
/* we require that the user either owns all tables or is superuser */
EnsureTableOwner(nextRelationOid);
MarkTablesColocated(sourceRelationId, nextRelationOid);
}

View File

@ -21,6 +21,13 @@ SELECT create_distributed_table('test', 'id');
(1 row)
CREATE TABLE test_coloc (id integer, val integer);
SELECT create_distributed_table('test_coloc', 'id', colocate_with := 'none');
create_distributed_table
--------------------------
(1 row)
SET citus.shard_count TO 1;
CREATE TABLE singleshard (id integer, val integer);
SELECT create_distributed_table('singleshard', 'id');
@ -234,6 +241,9 @@ ERROR: permission denied for function citus_stat_statements_reset
-- should not be allowed to upgrade to reference table
SELECT upgrade_to_reference_table('singleshard');
ERROR: must be owner of table singleshard
-- should not be allowed to co-located tables
SELECT mark_tables_colocated('test', ARRAY['test_coloc'::regclass]);
ERROR: must be owner of table test
-- table owner should be the same on the shards, even when distributing the table as superuser
SET ROLE full_access;
CREATE TABLE my_table (id integer, val integer);
@ -251,9 +261,7 @@ SELECT result FROM run_command_on_workers($$SELECT tableowner FROM pg_tables WHE
full_access
(2 rows)
DROP TABLE my_table;
DROP TABLE test;
DROP TABLE singleshard;
DROP TABLE my_table, singleshard, test, test_coloc;
DROP USER full_access;
DROP USER read_access;
DROP USER no_access;

View File

@ -16,6 +16,9 @@ SET citus.shard_replication_factor TO 1;
CREATE TABLE test (id integer, val integer);
SELECT create_distributed_table('test', 'id');
CREATE TABLE test_coloc (id integer, val integer);
SELECT create_distributed_table('test_coloc', 'id', colocate_with := 'none');
SET citus.shard_count TO 1;
CREATE TABLE singleshard (id integer, val integer);
SELECT create_distributed_table('singleshard', 'id');
@ -151,6 +154,9 @@ SELECT * FROM citus_stat_statements_reset();
-- should not be allowed to upgrade to reference table
SELECT upgrade_to_reference_table('singleshard');
-- should not be allowed to co-located tables
SELECT mark_tables_colocated('test', ARRAY['test_coloc'::regclass]);
-- table owner should be the same on the shards, even when distributing the table as superuser
SET ROLE full_access;
CREATE TABLE my_table (id integer, val integer);
@ -158,9 +164,7 @@ RESET ROLE;
SELECT create_distributed_table('my_table', 'id');
SELECT result FROM run_command_on_workers($$SELECT tableowner FROM pg_tables WHERE tablename LIKE 'my_table_%' LIMIT 1$$);
DROP TABLE my_table;
DROP TABLE test;
DROP TABLE singleshard;
DROP TABLE my_table, singleshard, test, test_coloc;
DROP USER full_access;
DROP USER read_access;
DROP USER no_access;