Skip to content

Commit 3d9a3ef

Browse files
committed
Fix intermittent self-test failures caused by the stats_ext test.
Commit d7f8d26 added new tests to the stats_ext regression test that included creating a view in the public schema, without realising that the stats_ext test runs in the same parallel group as the rules test, which makes doing that unsafe. This led to intermittent failures of the rules test on the buildfarm, although I wasn't able to reproduce that locally. Fix by creating the view in a different schema. Tomas Vondra and Dean Rasheed, report and diagnosis by Thomas Munro. Discussion: https://postgr.es/m/CA+hUKGKX9hFZrYA7rQzAMRE07L4hziCc-nO_b3taJpiuKyLLxg@mail.gmail.com
1 parent 87e9fae commit 3d9a3ef

File tree

2 files changed

+44
-38
lines changed

2 files changed

+44
-38
lines changed

src/test/regress/expected/stats_ext.out

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -752,59 +752,63 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE NOT a AND
752752
-- the underlying table.
753753
--
754754
-- Currently this is only relevant for MCV stats.
755-
CREATE TABLE priv_test_tbl (
755+
CREATE SCHEMA tststats;
756+
CREATE TABLE tststats.priv_test_tbl (
756757
a int,
757758
b int
758759
);
759-
INSERT INTO priv_test_tbl
760+
INSERT INTO tststats.priv_test_tbl
760761
SELECT mod(i,5), mod(i,10) FROM generate_series(1,100) s(i);
761-
CREATE STATISTICS priv_test_stats (mcv) ON a, b
762-
FROM priv_test_tbl;
763-
ANALYZE priv_test_tbl;
762+
CREATE STATISTICS tststats.priv_test_stats (mcv) ON a, b
763+
FROM tststats.priv_test_tbl;
764+
ANALYZE tststats.priv_test_tbl;
764765
-- User with no access
765766
CREATE USER regress_stats_user1;
767+
GRANT USAGE ON SCHEMA tststats TO regress_stats_user1;
766768
SET SESSION AUTHORIZATION regress_stats_user1;
767-
SELECT * FROM priv_test_tbl; -- Permission denied
769+
SELECT * FROM tststats.priv_test_tbl; -- Permission denied
768770
ERROR: permission denied for table priv_test_tbl
769771
-- Attempt to gain access using a leaky operator
770772
CREATE FUNCTION op_leak(int, int) RETURNS bool
771773
AS 'BEGIN RAISE NOTICE ''op_leak => %, %'', $1, $2; RETURN $1 < $2; END'
772774
LANGUAGE plpgsql;
773775
CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
774776
restrict = scalarltsel);
775-
SELECT * FROM priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
777+
SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
776778
ERROR: permission denied for table priv_test_tbl
777-
DELETE FROM priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
779+
DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
778780
ERROR: permission denied for table priv_test_tbl
779781
-- Grant access via a security barrier view, but hide all data
780782
RESET SESSION AUTHORIZATION;
781-
CREATE VIEW priv_test_view WITH (security_barrier=true)
782-
AS SELECT * FROM priv_test_tbl WHERE false;
783-
GRANT SELECT, DELETE ON priv_test_view TO regress_stats_user1;
783+
CREATE VIEW tststats.priv_test_view WITH (security_barrier=true)
784+
AS SELECT * FROM tststats.priv_test_tbl WHERE false;
785+
GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
784786
-- Should now have access via the view, but see nothing and leak nothing
785787
SET SESSION AUTHORIZATION regress_stats_user1;
786-
SELECT * FROM priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
788+
SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
787789
a | b
788790
---+---
789791
(0 rows)
790792

791-
DELETE FROM priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
793+
DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
792794
-- Grant table access, but hide all data with RLS
793795
RESET SESSION AUTHORIZATION;
794-
ALTER TABLE priv_test_tbl ENABLE ROW LEVEL SECURITY;
795-
GRANT SELECT, DELETE ON priv_test_tbl TO regress_stats_user1;
796+
ALTER TABLE tststats.priv_test_tbl ENABLE ROW LEVEL SECURITY;
797+
GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
796798
-- Should now have direct table access, but see nothing and leak nothing
797799
SET SESSION AUTHORIZATION regress_stats_user1;
798-
SELECT * FROM priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
800+
SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
799801
a | b
800802
---+---
801803
(0 rows)
802804

803-
DELETE FROM priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
805+
DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
804806
-- Tidy up
805807
DROP OPERATOR <<< (int, int);
806808
DROP FUNCTION op_leak(int, int);
807809
RESET SESSION AUTHORIZATION;
808-
DROP VIEW priv_test_view;
809-
DROP TABLE priv_test_tbl;
810+
DROP SCHEMA tststats CASCADE;
811+
NOTICE: drop cascades to 2 other objects
812+
DETAIL: drop cascades to table tststats.priv_test_tbl
813+
drop cascades to view tststats.priv_test_view
810814
DROP USER regress_stats_user1;

src/test/regress/sql/stats_ext.sql

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -493,58 +493,60 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE NOT a AND
493493
-- the underlying table.
494494
--
495495
-- Currently this is only relevant for MCV stats.
496-
CREATE TABLE priv_test_tbl (
496+
CREATE SCHEMA tststats;
497+
498+
CREATE TABLE tststats.priv_test_tbl (
497499
a int,
498500
b int
499501
);
500502

501-
INSERT INTO priv_test_tbl
503+
INSERT INTO tststats.priv_test_tbl
502504
SELECT mod(i,5), mod(i,10) FROM generate_series(1,100) s(i);
503505

504-
CREATE STATISTICS priv_test_stats (mcv) ON a, b
505-
FROM priv_test_tbl;
506+
CREATE STATISTICS tststats.priv_test_stats (mcv) ON a, b
507+
FROM tststats.priv_test_tbl;
506508

507-
ANALYZE priv_test_tbl;
509+
ANALYZE tststats.priv_test_tbl;
508510

509511
-- User with no access
510512
CREATE USER regress_stats_user1;
513+
GRANT USAGE ON SCHEMA tststats TO regress_stats_user1;
511514
SET SESSION AUTHORIZATION regress_stats_user1;
512-
SELECT * FROM priv_test_tbl; -- Permission denied
515+
SELECT * FROM tststats.priv_test_tbl; -- Permission denied
513516

514517
-- Attempt to gain access using a leaky operator
515518
CREATE FUNCTION op_leak(int, int) RETURNS bool
516519
AS 'BEGIN RAISE NOTICE ''op_leak => %, %'', $1, $2; RETURN $1 < $2; END'
517520
LANGUAGE plpgsql;
518521
CREATE OPERATOR <<< (procedure = op_leak, leftarg = int, rightarg = int,
519522
restrict = scalarltsel);
520-
SELECT * FROM priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
521-
DELETE FROM priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
523+
SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
524+
DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Permission denied
522525

523526
-- Grant access via a security barrier view, but hide all data
524527
RESET SESSION AUTHORIZATION;
525-
CREATE VIEW priv_test_view WITH (security_barrier=true)
526-
AS SELECT * FROM priv_test_tbl WHERE false;
527-
GRANT SELECT, DELETE ON priv_test_view TO regress_stats_user1;
528+
CREATE VIEW tststats.priv_test_view WITH (security_barrier=true)
529+
AS SELECT * FROM tststats.priv_test_tbl WHERE false;
530+
GRANT SELECT, DELETE ON tststats.priv_test_view TO regress_stats_user1;
528531

529532
-- Should now have access via the view, but see nothing and leak nothing
530533
SET SESSION AUTHORIZATION regress_stats_user1;
531-
SELECT * FROM priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
532-
DELETE FROM priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
534+
SELECT * FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
535+
DELETE FROM tststats.priv_test_view WHERE a <<< 0 AND b <<< 0; -- Should not leak
533536

534537
-- Grant table access, but hide all data with RLS
535538
RESET SESSION AUTHORIZATION;
536-
ALTER TABLE priv_test_tbl ENABLE ROW LEVEL SECURITY;
537-
GRANT SELECT, DELETE ON priv_test_tbl TO regress_stats_user1;
539+
ALTER TABLE tststats.priv_test_tbl ENABLE ROW LEVEL SECURITY;
540+
GRANT SELECT, DELETE ON tststats.priv_test_tbl TO regress_stats_user1;
538541

539542
-- Should now have direct table access, but see nothing and leak nothing
540543
SET SESSION AUTHORIZATION regress_stats_user1;
541-
SELECT * FROM priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
542-
DELETE FROM priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
544+
SELECT * FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
545+
DELETE FROM tststats.priv_test_tbl WHERE a <<< 0 AND b <<< 0; -- Should not leak
543546

544547
-- Tidy up
545548
DROP OPERATOR <<< (int, int);
546549
DROP FUNCTION op_leak(int, int);
547550
RESET SESSION AUTHORIZATION;
548-
DROP VIEW priv_test_view;
549-
DROP TABLE priv_test_tbl;
551+
DROP SCHEMA tststats CASCADE;
550552
DROP USER regress_stats_user1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy