Merge pull request #70 from CartoDB/remove-grant-select-from-cdb_tablemetadata-to-public

Remove grant select from cdb tablemetadata to public
master
Raul Ochoa 10 years ago
commit 05617382a9

@ -1,7 +1,7 @@
# cartodb/Makefile # cartodb/Makefile
EXTENSION = cartodb EXTENSION = cartodb
EXTVERSION = 0.5.3 EXTVERSION = 0.6.0
SED = sed SED = sed
@ -32,6 +32,7 @@ UPGRADABLE = \
0.5.0 \ 0.5.0 \
0.5.1 \ 0.5.1 \
0.5.2 \ 0.5.2 \
0.5.3 \
$(EXTVERSION)dev \ $(EXTVERSION)dev \
$(EXTVERSION)next \ $(EXTVERSION)next \
$(END) $(END)

@ -1,3 +1,8 @@
0.6.0 (2015-02-xx)
------------------
* Select permission in CDB_TableMetadata no longer granted to public
* New function to upsert the updated_at in CDB_TableMetadata for a regclass
0.5.3 (2015-02-xx) 0.5.3 (2015-02-xx)
------------------ ------------------
* Fixed secuity problem related with system tables * Fixed secuity problem related with system tables

@ -32,6 +32,7 @@ SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
---------------------- ----------------------
-- CREATE TABLE -- CREATE TABLE
---------------------- ----------------------
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
select 1 as i INTO c.t3; select 1 as i INTO c.t3;
NOTICE: trigger "track_updates" for table "c.t3" does not exist, skipping NOTICE: trigger "track_updates" for table "c.t3" does not exist, skipping
NOTICE: trigger "update_the_geom_webmercator_trigger" for table "c.t3" does not exist, skipping NOTICE: trigger "update_the_geom_webmercator_trigger" for table "c.t3" does not exist, skipping
@ -55,6 +56,7 @@ from c.t3;
1 | t | t | | | 1 1 | t | t | | | 1
(1 row) (1 row)
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)) as age round(extract('secs' from now() - updated_at)) as age
@ -64,6 +66,7 @@ FROM CDB_TableMetadata WHERE tabname = 'c.t3'::regclass;
c.t3 | 0 c.t3 | 0
(1 row) (1 row)
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
-- Table with cartodb_id field, see -- Table with cartodb_id field, see
-- http://github.com/CartoDB/cartodb-postgresql/issues/32 -- http://github.com/CartoDB/cartodb-postgresql/issues/32
select 1 as cartodb_id INTO c.t4; select 1 as cartodb_id INTO c.t4;
@ -91,6 +94,7 @@ from c.t4;
1 | t | t | | 1 | t | t | |
(1 row) (1 row)
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)) as age round(extract('secs' from now() - updated_at)) as age
@ -103,6 +107,7 @@ FROM CDB_TableMetadata WHERE tabname = 'c.t4'::regclass;
---------------------------- ----------------------------
-- ALTER TABLE RENAME COLUMN -- ALTER TABLE RENAME COLUMN
---------------------------- ----------------------------
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
select pg_sleep(.1); select pg_sleep(.1);
pg_sleep pg_sleep
---------- ----------
@ -131,6 +136,7 @@ from c.t3;
1 | t | t | | | 1 | 1 | t | t | | | 1 |
(1 row) (1 row)
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs round(extract('secs' from now() - updated_at)*10) as agecs
@ -140,6 +146,7 @@ FROM CDB_TableMetadata WHERE tabname = 'c.t3'::regclass;
c.t3 | 0 c.t3 | 0
(1 row) (1 row)
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
select pg_sleep(.1); select pg_sleep(.1);
pg_sleep pg_sleep
---------- ----------
@ -168,6 +175,7 @@ from c.t3;
1 | t | t | | | 1 | | 1 | t | t | | | 1 | |
(1 row) (1 row)
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs round(extract('secs' from now() - updated_at)*10) as agecs
@ -180,6 +188,7 @@ FROM CDB_TableMetadata WHERE tabname = 'c.t3'::regclass;
---------------------------- ----------------------------
-- ALTER TABLE DROP COLUMN -- ALTER TABLE DROP COLUMN
---------------------------- ----------------------------
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
select pg_sleep(.1); select pg_sleep(.1);
pg_sleep pg_sleep
---------- ----------
@ -208,6 +217,7 @@ from c.t3;
1 | t | t | | | 1 | | 1 | t | t | | | 1 | |
(1 row) (1 row)
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs round(extract('secs' from now() - updated_at)*10) as agecs
@ -220,6 +230,7 @@ FROM CDB_TableMetadata WHERE tabname = 'c.t3'::regclass;
---------------------------- ----------------------------
-- ALTER TABLE ADD COLUMN -- ALTER TABLE ADD COLUMN
---------------------------- ----------------------------
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
select pg_sleep(.1); select pg_sleep(.1);
pg_sleep pg_sleep
---------- ----------
@ -239,6 +250,7 @@ from c.t3;
1 | t | t | | | 1 | | | 1 | t | t | | | 1 | | |
(1 row) (1 row)
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs round(extract('secs' from now() - updated_at)*10) as agecs

@ -5,9 +5,9 @@ CREATE TABLE IF NOT EXISTS
updated_at timestamp with time zone not null default now() updated_at timestamp with time zone not null default now()
); );
-- Anyone can see this, but updates are only possible trough -- No one can see this
-- the security definer trigger -- Updates are only possible trough the security definer trigger
GRANT SELECT ON public.CDB_TableMetadata TO public; -- GRANT SELECT ON public.CDB_TableMetadata TO public;
-- --
-- Trigger logging updated_at in the CDB_TableMetadata -- Trigger logging updated_at in the CDB_TableMetadata
@ -118,3 +118,21 @@ CREATE TRIGGER table_modified AFTER INSERT OR UPDATE
ON CDB_TableMetadata FOR EACH ROW EXECUTE PROCEDURE ON CDB_TableMetadata FOR EACH ROW EXECUTE PROCEDURE
_CDB_TableMetadata_Updated(); _CDB_TableMetadata_Updated();
-- similar to TOUCH(1) in unix filesystems but for table in cdb_tablemetadata
CREATE OR REPLACE FUNCTION public.CDB_TableMetadataTouch(tablename regclass)
RETURNS void AS
$$
BEGIN
WITH upsert AS (
UPDATE public.cdb_tablemetadata
SET updated_at = NOW()
WHERE tabname = tablename
RETURNING *
)
INSERT INTO public.cdb_tablemetadata (tabname, updated_at)
SELECT tablename, NOW()
WHERE NOT EXISTS (SELECT * FROM upsert);
END;
$$
LANGUAGE 'plpgsql' VOLATILE STRICT;

@ -18,7 +18,7 @@ SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
---------------------- ----------------------
-- CREATE TABLE -- CREATE TABLE
---------------------- ----------------------
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
select 1 as i INTO c.t3; select 1 as i INTO c.t3;
select select
@ -28,11 +28,13 @@ select
i i
from c.t3; from c.t3;
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)) as age round(extract('secs' from now() - updated_at)) as age
FROM CDB_TableMetadata WHERE tabname = 'c.t3'::regclass; FROM CDB_TableMetadata WHERE tabname = 'c.t3'::regclass;
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
-- Table with cartodb_id field, see -- Table with cartodb_id field, see
-- http://github.com/CartoDB/cartodb-postgresql/issues/32 -- http://github.com/CartoDB/cartodb-postgresql/issues/32
select 1 as cartodb_id INTO c.t4; select 1 as cartodb_id INTO c.t4;
@ -41,6 +43,8 @@ select
NOW() - updated_at < '1 secs' as "u<1s", NOW() - updated_at < '1 secs' as "u<1s",
the_geom, the_geom_webmercator the_geom, the_geom_webmercator
from c.t4; from c.t4;
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)) as age round(extract('secs' from now() - updated_at)) as age
@ -49,6 +53,7 @@ FROM CDB_TableMetadata WHERE tabname = 'c.t4'::regclass;
---------------------------- ----------------------------
-- ALTER TABLE RENAME COLUMN -- ALTER TABLE RENAME COLUMN
---------------------------- ----------------------------
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
select pg_sleep(.1); select pg_sleep(.1);
alter table c.t3 rename column the_geom_webmercator to webmerc; alter table c.t3 rename column the_geom_webmercator to webmerc;
@ -60,11 +65,13 @@ select
i, webmerc i, webmerc
from c.t3; from c.t3;
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs round(extract('secs' from now() - updated_at)*10) as agecs
FROM CDB_TableMetadata WHERE tabname = 'c.t3'::regclass; FROM CDB_TableMetadata WHERE tabname = 'c.t3'::regclass;
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
select pg_sleep(.1); select pg_sleep(.1);
alter table c.t3 rename column the_geom_webmercator to webmerc2; alter table c.t3 rename column the_geom_webmercator to webmerc2;
@ -75,6 +82,7 @@ select
i, webmerc, webmerc2 i, webmerc, webmerc2
from c.t3; from c.t3;
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs round(extract('secs' from now() - updated_at)*10) as agecs
@ -83,7 +91,7 @@ FROM CDB_TableMetadata WHERE tabname = 'c.t3'::regclass;
---------------------------- ----------------------------
-- ALTER TABLE DROP COLUMN -- ALTER TABLE DROP COLUMN
---------------------------- ----------------------------
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
select pg_sleep(.1); select pg_sleep(.1);
alter table c.t3 drop column the_geom_webmercator; alter table c.t3 drop column the_geom_webmercator;
@ -94,6 +102,7 @@ select
i, webmerc, webmerc2 i, webmerc, webmerc2
from c.t3; from c.t3;
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs round(extract('secs' from now() - updated_at)*10) as agecs
@ -102,7 +111,7 @@ FROM CDB_TableMetadata WHERE tabname = 'c.t3'::regclass;
---------------------------- ----------------------------
-- ALTER TABLE ADD COLUMN -- ALTER TABLE ADD COLUMN
---------------------------- ----------------------------
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
select pg_sleep(.1); select pg_sleep(.1);
alter table c.t3 add column id2 int; alter table c.t3 add column id2 int;
@ -113,6 +122,7 @@ select
i, webmerc, webmerc2, id2 i, webmerc, webmerc2, id2
from c.t3; from c.t3;
RESET SESSION AUTHORIZATION;
select select
tabname::text, tabname::text,
round(extract('secs' from now() - updated_at)*10) as agecs round(extract('secs' from now() - updated_at)*10) as agecs

@ -1,3 +1,4 @@
SET SCHEMA 'cartodb'; SET SCHEMA 'cartodb';
\i scripts-available/CDB_Quota.sql \i scripts-available/CDB_Quota.sql
\i scripts-available/CDB_TableMetadata.sql
SET SCHEMA 'public'; SET SCHEMA 'public';

@ -75,6 +75,15 @@ function sql() {
set_failed set_failed
fi fi
fi fi
if [[ "$3" == "should-not" ]]
then
if [[ "${RESULT}" == "$4" ]]
then
log_error "QUERY '${QUERY}' did not expect '${RESULT}'"
set_failed
fi
fi
} }
@ -277,6 +286,42 @@ function test_quota_for_each_user() {
sql cdb_testmember_2 "SELECT cartodb.CDB_UserDataSize('cdb_testmember_2'::TEXT);" should 4096 sql cdb_testmember_2 "SELECT cartodb.CDB_UserDataSize('cdb_testmember_2'::TEXT);" should 4096
} }
function test_cdb_tablemetadatatouch() {
sql "CREATE TABLE touch_example (a int)"
sql postgres "SELECT updated_at FROM CDB_TableMetadata WHERE tabname = 'touch_example'::regclass;" should ''
sql "SELECT CDB_TableMetadataTouch('touch_example');"
sql postgres "SELECT updated_at FROM CDB_TableMetadata WHERE tabname = 'touch_example'::regclass;" should-not ''
# Another call doesn't fail
sql "SELECT CDB_TableMetadataTouch('touch_example');"
sql postgres "SELECT updated_at FROM CDB_TableMetadata WHERE tabname = 'touch_example'::regclass;" should-not ''
# Works with qualified tables
sql "SELECT CDB_TableMetadataTouch('public.touch_example');"
sql "SELECT CDB_TableMetadataTouch('public.\"touch_example\"');"
sql "SELECT CDB_TableMetadataTouch('\"public\".touch_example');"
sql "SELECT CDB_TableMetadataTouch('\"public\".\"touch_example\"');"
#### test tear down
sql 'DROP TABLE touch_example;'
}
function test_cdb_tablemetadatatouch_fails_for_unexistent_table() {
sql postgres "SELECT CDB_TableMetadataTouch('unexistent_example');" fails
}
function test_cdb_tablemetadatatouch_fails_from_user_without_permission() {
sql "CREATE TABLE touch_example (a int);"
sql postgres "SELECT CDB_TableMetadataTouch('touch_example');"
sql cdb_testmember_1 "SELECT CDB_TableMetadataTouch('touch_example');" fails
sql postgres "GRANT ALL ON CDB_TableMetadata TO cdb_testmember_1;"
sql cdb_testmember_1 "SELECT CDB_TableMetadataTouch('touch_example');"
sql postgres "REVOKE ALL ON CDB_TableMetadata FROM cdb_testmember_1;"
}
#################################################### TESTS END HERE #################################################### #################################################### TESTS END HERE ####################################################
run_tests $@ run_tests $@

Loading…
Cancel
Save