forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit0bf22e0
committed
RLS fixes, new hooks, and new test module
In prepend_row_security_policies(), defaultDeny was always true, so ifthere were any hook policies, the RLS policies on the table would justget discarded. Fixed to start off with defaultDeny as false and thenproperly set later if we detect that only the default deny policy existsfor the internal policies.The infinite recursion detection in fireRIRrules() didn't properlymanage the activeRIRs list in the case of WCOs, so it would incorrectlyreport infinite recusion if the same relation with RLS appeared morethan once in the rtable, for example "UPDATE t ... FROM t ...".Further, the RLS expansion code in fireRIRrules() was handling RLS inthe main loop through the rtable, which lead to RTEs being visited twiceif they contained sublink subqueries, whichprepend_row_security_policies() attempted to handle by exiting early ifthe RTE already had securityQuals. That doesn't work, however, sinceif the query involved a security barrier view on top of a table withRLS, the RTE would already have securityQuals (from the view) by thetime fireRIRrules() was invoked, and so the table's RLS policies wouldbe ignored. This is fixed in fireRIRrules() by handling RLS in aseparate loop at the end, after dealing with any other sublinksubqueries, thus ensuring that each RTE is only visited once for RLSexpansion.The inheritance planner code didn't correctly handle non-targetrelations with RLS, which would get turned into subqueries duringplanning. Thus an update of the form "UPDATE t1 ... FROM t2 ..." wheret1 has inheritance and t2 has RLS quals would fail. Fix by making sureto copy in and update the securityQuals when they exist for non-targetrelations.process_policies() was adding WCOs to non-target relations, which isunnecessary, and could lead to a lot of wasted time in the rewriter andthe planner. Fix by only adding WCO policies when working on the resultrelation. Also in process_policies, we should be copying the USINGpolicies to the WITH CHECK policies on a per-policy basis, fix by movingthe copying up into the per-policy loop.Lastly, as noted by Dean, we were simply adding policies returned by thehook provided to the list of quals being AND'd, meaning that they wouldactually restrict records returned and there was no option to haveinternal policies and hook-based policies work together permissively (asall internal policies currently work). Instead, explicitly add supportfor both permissive and restrictive policies by having a hook for eachand combining the results appropriately. To ensure this is all donecorrectly, add a new test module (test_rls_hooks) to test the variouscombinations of internal, permissive, and restrictive hook policies.Largely from Dean Rasheed (thanks!):CAEZATCVmFUfUOwwhnBTcgi6AquyjQ0-1fyKd0T3xBWJvn+xsFA@mail.gmail.comAuthor: Dean Rasheed, though I added the new hooks and test module.1 parent4ccc5bd commit0bf22e0
File tree
16 files changed
+1271
-147
lines changed- src
- backend
- optimizer/plan
- rewrite
- include/rewrite
- test
- modules
- test_rls_hooks
- expected
- sql
- regress
- expected
- sql
16 files changed
+1271
-147
lines changedLines changed: 40 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
790 | 790 |
| |
791 | 791 |
| |
792 | 792 |
| |
| 793 | + | |
793 | 794 |
| |
794 | 795 |
| |
795 | 796 |
| |
| |||
815 | 816 |
| |
816 | 817 |
| |
817 | 818 |
| |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
818 | 824 |
| |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
819 | 834 |
| |
820 | 835 |
| |
821 | 836 |
| |
| |||
886 | 901 |
| |
887 | 902 |
| |
888 | 903 |
| |
889 |
| - | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
890 | 912 |
| |
891 | 913 |
| |
892 | 914 |
| |
893 | 915 |
| |
894 | 916 |
| |
895 |
| - | |
896 |
| - | |
897 |
| - | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
898 | 920 |
| |
899 | 921 |
| |
900 | 922 |
| |
901 | 923 |
| |
902 | 924 |
| |
903 | 925 |
| |
| 926 | + | |
904 | 927 |
| |
905 | 928 |
| |
906 | 929 |
| |
| |||
2283 | 2306 |
| |
2284 | 2307 |
| |
2285 | 2308 |
| |
2286 |
| - | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
2287 | 2322 |
| |
2288 | 2323 |
| |
2289 | 2324 |
| |
|
Lines changed: 82 additions & 45 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1714 | 1714 |
| |
1715 | 1715 |
| |
1716 | 1716 |
| |
1717 |
| - | |
1718 |
| - | |
1719 |
| - | |
1720 |
| - | |
1721 |
| - | |
1722 |
| - | |
1723 |
| - | |
1724 |
| - | |
1725 |
| - | |
1726 |
| - | |
1727 |
| - | |
1728 |
| - | |
1729 |
| - | |
1730 |
| - | |
1731 |
| - | |
1732 |
| - | |
1733 |
| - | |
1734 |
| - | |
1735 |
| - | |
1736 |
| - | |
1737 |
| - | |
1738 |
| - | |
1739 |
| - | |
1740 |
| - | |
1741 |
| - | |
1742 |
| - | |
1743 |
| - | |
1744 |
| - | |
1745 |
| - | |
1746 |
| - | |
1747 |
| - | |
1748 |
| - | |
1749 |
| - | |
1750 |
| - | |
1751 |
| - | |
1752 |
| - | |
1753 |
| - | |
1754 |
| - | |
1755 |
| - | |
1756 |
| - | |
1757 |
| - | |
1758 |
| - | |
1759 |
| - | |
1760 |
| - | |
1761 |
| - | |
1762 | 1717 |
| |
1763 | 1718 |
| |
1764 | 1719 |
| |
| |||
1780 | 1735 |
| |
1781 | 1736 |
| |
1782 | 1737 |
| |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
1783 | 1820 |
| |
1784 | 1821 |
| |
1785 | 1822 |
| |
|
0 commit comments
Comments
(0)