Skip to content

Commit

Permalink
Add test to make sure that we can't leak info fooling the planner
Browse files Browse the repository at this point in the history
  • Loading branch information
rjuju committed Jun 1, 2023
1 parent 4c61207 commit f817f6f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ ifneq ($(MAJORVERSION), 10)
REGRESS += 02_partitioning_hash
endif

REGRESS += 03_inheritance 99_cleanup
REGRESS += 03_inheritance \
10_security \
99_cleanup
34 changes: 34 additions & 0 deletions expected/10_security.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--setup
LOAD 'pg_anonymize';
CREATE TABLE customer_security(
id integer,
name text,
country text
);
INSERT INTO customer_security VALUES (1, 'Secret Name', 'Taiwan');
SECURITY LABEL ON COLUMN customer_security.name IS $$'XXX'::text$$;
-- mask our own user
SELECT current_user \gset
SECURITY LABEL FOR pg_anonymize ON ROLE :current_user IS 'anonymize';
SELECT * FROM customer_security;
id | name | country
----+------+---------
1 | XXX | Taiwan
(1 row)

-- It shouldn't be possible to access the original fooling the planner
CREATE FUNCTION leak_info(name text, country text) RETURNS BOOL AS
$_$
BEGIN
RAISE NOTICE 'saw % - %', name, country;

RETURN true;
END;
$_$ LANGUAGE plpgsql COST 0.0000000000000000000001;
SELECT * FROM customer_security WHERE leak_info(name, country);
NOTICE: saw XXX - Taiwan
id | name | country
----+------+---------
1 | XXX | Taiwan
(1 row)

30 changes: 30 additions & 0 deletions test/sql/10_security.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--setup
LOAD 'pg_anonymize';

CREATE TABLE customer_security(
id integer,
name text,
country text
);

INSERT INTO customer_security VALUES (1, 'Secret Name', 'Taiwan');

SECURITY LABEL ON COLUMN customer_security.name IS $$'XXX'::text$$;

-- mask our own user
SELECT current_user \gset
SECURITY LABEL FOR pg_anonymize ON ROLE :current_user IS 'anonymize';

SELECT * FROM customer_security;

-- It shouldn't be possible to access the original fooling the planner
CREATE FUNCTION leak_info(name text, country text) RETURNS BOOL AS
$_$
BEGIN
RAISE NOTICE 'saw % - %', name, country;

RETURN true;
END;
$_$ LANGUAGE plpgsql COST 0.0000000000000000000001;

SELECT * FROM customer_security WHERE leak_info(name, country);

0 comments on commit f817f6f

Please sign in to comment.