- Notifications
You must be signed in to change notification settings - Fork28
Commit215b43c
committed
Improve RLS planning by marking individual quals with security levels.
In an RLS query, we must ensure that security filter quals are evaluatedbefore ordinary query quals, in case the latter contain "leaky" functionsthat could expose the contents of sensitive rows. The originalimplementation of RLS planning ensured this by pushing the scan of asecured table into a sub-query that it marked as a security-barrier view.Unfortunately this results in very inefficient plans in many cases, becausethe sub-query cannot be flattened and gets planned independently of therest of the query.To fix, drop the use of sub-queries to enforce RLS qual order, and insteadmark each qual (RestrictInfo) with a security_level field establishing itspriority for evaluation. Quals must be evaluated in security_level order,except that "leakproof" quals can be allowed to go ahead of quals of lowersecurity_level, if it's helpful to do so. This has to be enforced withinthe ordering of any one list of quals to be evaluated at a table scan node,and we also have to ensure that quals are not chosen for early evaluation(i.e., use as an index qual or TID scan qual) if they're not allowed to goahead of other quals at the scan node.This is sufficient to fix the problem for RLS quals, since we only supportRLS policies on simple tables and thus RLS quals will always exist at thetable scan level only. Eventually these qual ordering rules should beenforced for join quals as well, which would permit improving planning forexplicit security-barrier views; but that's a task for another patch.Note that FDWs would need to be aware of these rules --- and not, forexample, send an insecure qual for remote execution --- but since we donot yet allow RLS policies on foreign tables, the case doesn't arise.This will need to be addressed before we can allow such policies.Patch by me, reviewed by Stephen Frost and Dean Rasheed.Discussion:https://postgr.es/m/8185.1477432701@sss.pgh.pa.us1 parentaa17c06 commit215b43c
File tree
29 files changed
+1137
-1558
lines changed- src
- backend
- nodes
- optimizer
- path
- plan
- prep
- util
- include
- nodes
- optimizer
- test
- modules/test_rls_hooks/expected
- regress
- expected
- sql
29 files changed
+1137
-1558
lines changedLines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2027 | 2027 |
| |
2028 | 2028 |
| |
2029 | 2029 |
| |
| 2030 | + | |
| 2031 | + | |
2030 | 2032 |
| |
2031 | 2033 |
| |
2032 | 2034 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
805 | 805 |
| |
806 | 806 |
| |
807 | 807 |
| |
| 808 | + | |
808 | 809 |
| |
809 | 810 |
| |
810 | 811 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2059 | 2059 |
| |
2060 | 2060 |
| |
2061 | 2061 |
| |
| 2062 | + | |
2062 | 2063 |
| |
2063 | 2064 |
| |
2064 | 2065 |
| |
| |||
2112 | 2113 |
| |
2113 | 2114 |
| |
2114 | 2115 |
| |
| 2116 | + | |
2115 | 2117 |
| |
2116 | 2118 |
| |
2117 | 2119 |
| |
| |||
2195 | 2197 |
| |
2196 | 2198 |
| |
2197 | 2199 |
| |
| 2200 | + | |
| 2201 | + | |
2198 | 2202 |
| |
2199 | 2203 |
| |
2200 | 2204 |
| |
| |||
2261 | 2265 |
| |
2262 | 2266 |
| |
2263 | 2267 |
| |
| 2268 | + | |
| 2269 | + | |
2264 | 2270 |
| |
2265 | 2271 |
| |
2266 | 2272 |
| |
|
Lines changed: 102 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
877 | 877 |
| |
878 | 878 |
| |
879 | 879 |
| |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
880 | 982 |
| |
881 | 983 |
| |
882 | 984 |
| |
|
Lines changed: 104 additions & 62 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
896 | 896 |
| |
897 | 897 |
| |
898 | 898 |
| |
899 |
| - | |
| 899 | + | |
| 900 | + | |
900 | 901 |
| |
901 | 902 |
| |
| 903 | + | |
902 | 904 |
| |
903 | 905 |
| |
904 | 906 |
| |
| |||
921 | 923 |
| |
922 | 924 |
| |
923 | 925 |
| |
924 |
| - | |
925 |
| - | |
926 |
| - | |
927 |
| - | |
928 |
| - | |
929 |
| - | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
930 | 1020 |
| |
931 |
| - | |
932 |
| - | |
933 |
| - | |
934 |
| - | |
935 |
| - | |
936 |
| - | |
937 |
| - | |
938 |
| - | |
939 |
| - | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
940 | 1025 |
| |
941 | 1026 |
| |
942 |
| - | |
| 1027 | + | |
943 | 1028 |
| |
944 | 1029 |
| |
945 | 1030 |
| |
946 | 1031 |
| |
947 | 1032 |
| |
948 |
| - | |
949 |
| - | |
950 |
| - | |
951 |
| - | |
952 | 1033 |
| |
953 | 1034 |
| |
954 | 1035 |
| |
| |||
1712 | 1793 |
| |
1713 | 1794 |
| |
1714 | 1795 |
| |
| 1796 | + | |
1715 | 1797 |
| |
1716 | 1798 |
| |
1717 | 1799 |
| |
| |||
2640 | 2722 |
| |
2641 | 2723 |
| |
2642 | 2724 |
| |
2643 |
| - | |
2644 |
| - | |
2645 |
| - | |
2646 |
| - | |
2647 |
| - | |
2648 |
| - | |
2649 |
| - | |
2650 |
| - | |
2651 |
| - | |
2652 |
| - | |
2653 |
| - | |
2654 |
| - | |
2655 |
| - | |
2656 |
| - | |
2657 |
| - | |
2658 |
| - | |
2659 |
| - | |
2660 |
| - | |
2661 |
| - | |
2662 |
| - | |
2663 |
| - | |
2664 |
| - | |
2665 |
| - | |
2666 |
| - | |
2667 |
| - | |
2668 |
| - | |
2669 |
| - | |
2670 |
| - | |
2671 |
| - | |
2672 |
| - | |
2673 |
| - | |
2674 |
| - | |
2675 |
| - | |
2676 |
| - | |
2677 |
| - | |
2678 |
| - | |
2679 |
| - | |
2680 |
| - | |
2681 |
| - | |
2682 |
| - | |
2683 | 2725 |
| |
2684 | 2726 |
| |
2685 | 2727 |
| |
| |||
2708 | 2750 |
| |
2709 | 2751 |
| |
2710 | 2752 |
| |
2711 |
| - | |
| 2753 | + | |
2712 | 2754 |
| |
2713 | 2755 |
| |
2714 | 2756 |
| |
|
0 commit comments
Comments
(0)