forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit8fea868
committed
Add support for regexps on database and user entries in pg_hba.conf
As of this commit, any database or user entry beginning with a slash (/)is considered as a regular expression. This is particularly useful forusers, as now there is no clean way to match pattern on multiple HBAlines. For example, a user name mapping with a regular expression needsfirst to match with a HBA line, and we would skip the follow-up HBAentries if the ident regexp does *not* match with what has matched inthe HBA line.pg_hba.conf is able to handle multiple databases and roles with acomma-separated list of these, hence individual regular expressions thatinclude commas need to be double-quoted.At authentication time, user and database names are now checked in thefollowing order:- Arbitrary keywords (like "all", the ones beginning by '+' formembership check), that we know will never have a regexp. A fancy caseis for physical WAL senders, we *have* to only match "replication" forthe database.- Regular expression matching.- Exact match.The previous logic did the same, but without the regexp step.We have discussed as well the possibility to support regexp patternmatching for host names, but these happen to lead to tricky issues basedon what I understand, particularly with host entries that have CIDRs.This commit relies heavily on the refactoring done ina903971 andfc579e1, so as the amount of code required to compile and executeregular expressions is now minimal. When parsing pg_hba.conf, all thecomputed regexps needs to explicitely free()'d, same as pg_ident.conf.Documentation and TAP tests are added to cover this feature, includingcases where the regexps use commas (for clarity in the docs, coveragefor the parsing logic in the tests).Note that this introduces a breakage with older versions, where adatabase or user name beginning with a slash are treated as something tocheck for an equal match. Per discussion, we have discarded this asbeing much of an issue in practice as it would require a cluster tohave database and/or role names that begin with a slash, as well as HBAentries using these. Hence, the consistency gained with regexps inpg_ident.conf is more appealing in the long term.**This compatibility change should be mentioned in the release notes.**Author: Bertrand DrouvotReviewed-by: Jacob Champion, Tom Lane, Michael PaquierDiscussion:https://postgr.es/m/fff0d7c1-8ad4-76a1-9db3-0ab6ec338bf7@amazon.com1 parent5035c93 commit8fea868
File tree
3 files changed
+163
-21
lines changed- doc/src/sgml
- src
- backend/libpq
- test/authentication/t
3 files changed
+163
-21
lines changedLines changed: 42 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
233 | 233 |
| |
234 | 234 |
| |
235 | 235 |
| |
236 |
| - | |
237 |
| - | |
238 |
| - | |
239 |
| - | |
240 |
| - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
241 | 250 |
| |
242 | 251 |
| |
243 | 252 |
| |
| |||
249 | 258 |
| |
250 | 259 |
| |
251 | 260 |
| |
252 |
| - | |
| 261 | + | |
| 262 | + | |
253 | 263 |
| |
254 | 264 |
| |
255 | 265 |
| |
| |||
258 | 268 |
| |
259 | 269 |
| |
260 | 270 |
| |
261 |
| - | |
262 |
| - | |
263 |
| - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
264 | 283 |
| |
265 | 284 |
| |
266 | 285 |
| |
| |||
739 | 758 |
| |
740 | 759 |
| |
741 | 760 |
| |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
742 | 769 |
| |
743 | 770 |
| |
744 | 771 |
| |
| |||
785 | 812 |
| |
786 | 813 |
| |
787 | 814 |
| |
788 |
| - | |
| 815 | + | |
789 | 816 |
| |
790 |
| - | |
791 |
| - | |
792 |
| - | |
793 |
| - | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
794 | 821 |
| |
795 | 822 |
| |
796 | 823 |
| |
| 824 | + | |
797 | 825 |
| |
798 | 826 |
| |
799 | 827 |
| |
|
Lines changed: 79 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
293 | 293 |
| |
294 | 294 |
| |
295 | 295 |
| |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
296 | 320 |
| |
297 | 321 |
| |
298 | 322 |
| |
| |||
661 | 685 |
| |
662 | 686 |
| |
663 | 687 |
| |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
664 | 692 |
| |
665 | 693 |
| |
666 | 694 |
| |
| |||
676 | 704 |
| |
677 | 705 |
| |
678 | 706 |
| |
679 |
| - | |
680 |
| - | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
681 | 715 |
| |
682 | 716 |
| |
683 | 717 |
| |
684 | 718 |
| |
685 | 719 |
| |
686 | 720 |
| |
687 | 721 |
| |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
688 | 726 |
| |
689 | 727 |
| |
690 | 728 |
| |
| |||
719 | 757 |
| |
720 | 758 |
| |
721 | 759 |
| |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
722 | 765 |
| |
723 | 766 |
| |
724 | 767 |
| |
| |||
1138 | 1181 |
| |
1139 | 1182 |
| |
1140 | 1183 |
| |
1141 |
| - | |
1142 |
| - | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
1143 | 1191 |
| |
1144 | 1192 |
| |
1145 | 1193 |
| |
| |||
1158 | 1206 |
| |
1159 | 1207 |
| |
1160 | 1208 |
| |
1161 |
| - | |
1162 |
| - | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
1163 | 1216 |
| |
1164 | 1217 |
| |
1165 | 1218 |
| |
| |||
2355 | 2408 |
| |
2356 | 2409 |
| |
2357 | 2410 |
| |
2358 |
| - | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
2359 | 2422 |
| |
2360 | 2423 |
| |
2361 | 2424 |
| |
2362 | 2425 |
| |
2363 | 2426 |
| |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
2364 | 2436 |
| |
2365 | 2437 |
| |
2366 | 2438 |
| |
|
Lines changed: 42 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
81 | 81 |
| |
82 | 82 |
| |
83 | 83 |
| |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
84 | 92 |
| |
85 | 93 |
| |
86 | 94 |
| |
| |||
200 | 208 |
| |
201 | 209 |
| |
202 | 210 |
| |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
203 | 245 |
| |
204 | 246 |
| |
205 | 247 |
| |
|
0 commit comments
Comments
(0)