pg-cdc-ssl.td 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. # We test interesting combinations of server and client SSL configs
  10. # (part of the CREATE SOURCE statement).
  11. #
  12. # The important bit is that each user is named after the record type
  13. # in `pg_hba.conf`. The record type indicates what kind of connection
  14. # is allowed, e.g. `host` allows SSL and plaintext whereas `hostssl`
  15. # only allows SSL.
  16. #
  17. # Check out https://www.postgresql.org/docs/13/auth-pg-hba-conf.html
  18. # for more details.
  19. # TODO: Reenable when database-issues#4009 is fixed
  20. $ skip-if
  21. SELECT true
  22. > CREATE SECRET ssl_ca AS '${arg.ssl-ca}'
  23. > CREATE SECRET ssl_cert AS '${arg.ssl-cert}'
  24. > CREATE SECRET ssl_key AS '${arg.ssl-key}'
  25. > CREATE SECRET ssl_wrong_cert AS '${arg.ssl-wrong-cert}'
  26. > CREATE SECRET ssl_wrong_key AS '${arg.ssl-wrong-key}'
  27. # Bootstrap users and data
  28. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  29. DROP SCHEMA IF EXISTS public CASCADE;
  30. CREATE SCHEMA public;
  31. DROP USER IF EXISTS host;
  32. CREATE USER host LOGIN SUPERUSER;
  33. DROP USER IF EXISTS hostssl;
  34. CREATE USER hostssl LOGIN SUPERUSER;
  35. DROP USER IF EXISTS hostnossl;
  36. CREATE USER hostnossl LOGIN SUPERUSER;
  37. DROP USER IF EXISTS certuser;
  38. CREATE USER certuser LOGIN SUPERUSER;
  39. DROP TABLE IF EXISTS numbers;
  40. CREATE TABLE numbers (number int PRIMARY KEY, is_prime bool, name text);
  41. ALTER TABLE numbers REPLICA IDENTITY FULL;
  42. DROP PUBLICATION IF EXISTS mz_source;
  43. CREATE PUBLICATION mz_source FOR ALL TABLES;
  44. INSERT INTO numbers VALUES (1, true, 'one');
  45. $ set-regex match=(\d{1,3}\.){3}\d{1,3} replacement=(HOST)
  46. # server: host, client: disable => OK
  47. > CREATE CONNECTION pgconn TO POSTGRES ( (
  48. HOST postgres,
  49. USER host,
  50. SSL MODE disable,
  51. DATABASE postgres
  52. );
  53. > CREATE SOURCE "mz_source"
  54. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source')
  55. FOR TABLES ("numbers");
  56. > SELECT * FROM "numbers";
  57. 1 true one
  58. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  59. INSERT INTO numbers VALUES (2, true, 'two');
  60. > SELECT * FROM "numbers";
  61. 1 true one
  62. 2 true two
  63. > DROP SOURCE "mz_source" CASCADE;
  64. > DROP CONNECTION pgconn;
  65. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  66. DELETE FROM numbers WHERE number = 2;
  67. # server: host, client: prefer => unsupported
  68. ! CREATE CONNECTION pgconn TO POSTGRES (
  69. HOST postgres,
  70. USER host,
  71. SSL MODE prefer,
  72. DATABASE postgres
  73. );
  74. contains: invalid CONNECTION: unknown SSL MODE "prefer"
  75. # server: host, client: require => OK
  76. > CREATE CONNECTION pgconn TO POSTGRES (
  77. HOST postgres,
  78. USER host,
  79. SSL MODE require,
  80. DATABASE postgres
  81. );
  82. > CREATE SOURCE "mz_source"
  83. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source')
  84. FOR TABLES ("numbers");
  85. > SELECT * FROM "numbers";
  86. 1 true one
  87. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  88. INSERT INTO numbers VALUES (2, true, 'two');
  89. > SELECT * FROM "numbers";
  90. 1 true one
  91. 2 true two
  92. > DROP SOURCE "mz_source" CASCADE;
  93. > DROP CONNECTION pgconn;
  94. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  95. DELETE FROM numbers WHERE number = 2;
  96. # server: hostssl, client: disable => ERROR
  97. > CREATE CONNECTION pgconn TO POSTGRES (
  98. HOST postgres,
  99. USER hostssl,
  100. SSL MODE disable,
  101. DATABASE postgres
  102. );
  103. ! CREATE SOURCE "mz_source"
  104. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source');
  105. contains:db error: FATAL: no pg_hba.conf entry for host "(HOST)", user "hostssl", database "postgres", SSL off
  106. > DROP CONNECTION pgconn;
  107. # server: hostssl, client: require => OK
  108. > CREATE CONNECTION pgconn TO POSTGRES (
  109. HOST postgres,
  110. USER hostssl,
  111. SSL MODE require,
  112. DATABASE postgres
  113. );
  114. > CREATE SOURCE "mz_source"
  115. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source')
  116. FOR TABLES ("numbers");
  117. > SELECT * FROM "numbers";
  118. 1 true one
  119. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  120. INSERT INTO numbers VALUES (2, true, 'two');
  121. > SELECT * FROM "numbers";
  122. 1 true one
  123. 2 true two
  124. > DROP SOURCE "mz_source" CASCADE;
  125. > DROP CONNECTION pgconn;
  126. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  127. DELETE FROM numbers WHERE number = 2;
  128. # server: hostssl, client: verify-ca => ERROR
  129. > CREATE CONNECTION pgconn TO POSTGRES (
  130. HOST postgres,
  131. USER hostssl,
  132. SSL MODE verify_ca,
  133. DATABASE postgres
  134. );
  135. ! CREATE SOURCE "mz_source"
  136. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source');
  137. contains:self signed certificate in certificate chain
  138. > DROP CONNECTION pgconn;
  139. # server: hostssl, client: verify-ca => OK
  140. > CREATE CONNECTION pgconn TO POSTGRES (
  141. HOST postgres,
  142. USER hostssl,
  143. SSL MODE verify_ca,
  144. SSL CERTIFICATE AUTHORITY SECRET ssl_ca,
  145. DATABASE postgres
  146. );
  147. > CREATE SOURCE "mz_source"
  148. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source')
  149. FOR TABLES ("numbers");
  150. > SELECT * FROM "numbers";
  151. 1 true one
  152. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  153. INSERT INTO numbers VALUES (2, true, 'two');
  154. > SELECT * FROM "numbers";
  155. 1 true one
  156. 2 true two
  157. > DROP SOURCE "mz_source" CASCADE;
  158. > DROP CONNECTION pgconn;
  159. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  160. DELETE FROM numbers WHERE number = 2;
  161. # server: hostssl, client: verify-full => ERROR
  162. > CREATE CONNECTION pgconn TO POSTGRES (
  163. HOST postgres,
  164. USER hostssl,
  165. SSL MODE verify_full,
  166. DATABASE postgres
  167. );
  168. ! CREATE SOURCE "mz_source"
  169. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source');
  170. contains:self signed certificate in certificate chain
  171. > DROP CONNECTION pgconn;
  172. # server: hostssl, client: verify-full => OK
  173. > CREATE CONNECTION pgconn TO POSTGRES (
  174. HOST postgres,
  175. USER hostssl,
  176. SSL MODE verify_full,
  177. SSL CERTIFICATE AUTHORITY SECRET ssl_ca,
  178. DATABASE postgres
  179. );
  180. > CREATE SOURCE "mz_source"
  181. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source')
  182. FOR TABLES ("numbers");
  183. > SELECT * FROM "numbers";
  184. 1 true one
  185. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  186. INSERT INTO numbers VALUES (2, true, 'two');
  187. > SELECT * FROM "numbers";
  188. 1 true one
  189. 2 true two
  190. > DROP SOURCE "mz_source" CASCADE;
  191. > DROP CONNECTION pgconn;
  192. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  193. DELETE FROM numbers WHERE number = 2;
  194. # server: hostnossl, client: disable => OK
  195. > CREATE CONNECTION pgconn TO POSTGRES (
  196. HOST postgres,
  197. USER hostnossl,
  198. SSL MODE disable,
  199. DATABASE postgres
  200. );
  201. > CREATE SOURCE "mz_source"
  202. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source')
  203. FOR TABLES ("numbers");
  204. > SELECT * FROM "numbers";
  205. 1 true one
  206. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  207. INSERT INTO numbers VALUES (2, true, 'two');
  208. > SELECT * FROM "numbers";
  209. 1 true one
  210. 2 true two
  211. > DROP SOURCE "mz_source" CASCADE;
  212. > DROP CONNECTION pgconn;
  213. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  214. DELETE FROM numbers WHERE number = 2;
  215. # server: hostnossl, client: require => ERROR
  216. > CREATE CONNECTION pgconn TO POSTGRES (
  217. HOST postgres,
  218. USER hostnossl,
  219. SSL MODE require,
  220. DATABASE postgres
  221. );
  222. ! CREATE SOURCE "mz_source"
  223. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source');
  224. contains:db error: FATAL: no pg_hba.conf entry for host "(HOST)", user "hostnossl", database "postgres", SSL on
  225. > DROP CONNECTION pgconn;
  226. # server: hostnossl, client: verify-ca => ERROR
  227. > CREATE CONNECTION pgconn TO POSTGRES (
  228. HOST postgres,
  229. USER hostnossl,
  230. SSL MODE verify_ca,
  231. DATABASE postgres
  232. );
  233. ! CREATE SOURCE "mz_source"
  234. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source');
  235. contains:self signed certificate in certificate chain
  236. > DROP CONNECTION pgconn;
  237. # server: hostnossl, client: verify-full => ERROR
  238. > CREATE CONNECTION pgconn TO POSTGRES (
  239. HOST postgres,
  240. USER hostnossl,
  241. SSL MODE verify_full,
  242. DATABASE postgres
  243. );
  244. ! CREATE SOURCE "mz_source"
  245. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source');
  246. contains:self signed certificate in certificate chain
  247. > DROP CONNECTION pgconn;
  248. # server: certuser, client: require => OK
  249. > CREATE CONNECTION pgconn TO POSTGRES (
  250. HOST postgres,
  251. USER certuser,
  252. SSL MODE require,
  253. SSL CERTIFICATE SECRET ssl_cert,
  254. SSL KEY SECRET ssl_key,
  255. SSL CERTIFICATE AUTHORITY SECRET ssl_ca,
  256. DATABASE postgres
  257. );
  258. > CREATE SOURCE "mz_source"
  259. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source')
  260. FOR TABLES ("numbers");
  261. > SELECT * FROM "numbers";
  262. 1 true one
  263. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  264. INSERT INTO numbers VALUES (2, true, 'two');
  265. > SELECT * FROM "numbers";
  266. 1 true one
  267. 2 true two
  268. > DROP SOURCE "mz_source" CASCADE;
  269. > DROP CONNECTION pgconn;
  270. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  271. DELETE FROM numbers WHERE number = 2;
  272. # server: certuser, client: verify-ca => ERROR
  273. > CREATE CONNECTION pgconn TO POSTGRES (
  274. HOST postgres,
  275. USER certuser,
  276. SSL MODE verify_ca,
  277. SSL CERTIFICATE AUTHORITY SECRET ssl_ca,
  278. DATABASE postgres
  279. );
  280. ! CREATE SOURCE "mz_source"
  281. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source')
  282. contains:db error: FATAL: connection requires a valid client certificate
  283. > DROP CONNECTION pgconn;
  284. # server: certuser, client: verify-ca (wrong cert) => ERROR
  285. > CREATE CONNECTION pgconn TO POSTGRES (
  286. HOST postgres,
  287. USER certuser,
  288. SSL MODE verify_ca,
  289. SSL CERTIFICATE SECRET ssl_wrong_cert,
  290. SSL KEY SECRET ssl_wrong_key,
  291. SSL CERTIFICATE AUTHORITY SECRET ssl_ca,
  292. DATABASE postgres
  293. );
  294. ! CREATE SOURCE "mz_source"
  295. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source')
  296. contains:db error: FATAL: certificate authentication failed for user "certuser"
  297. > DROP CONNECTION pgconn;
  298. # server: certuser, client: verify-ca => OK
  299. > CREATE CONNECTION pgconn TO POSTGRES (
  300. HOST postgres,
  301. USER certuser,
  302. SSL MODE verify_ca,
  303. SSL CERTIFICATE SECRET ssl_cert,
  304. SSL KEY SECRET ssl_key,
  305. SSL CERTIFICATE AUTHORITY SECRET ssl_ca,
  306. DATABASE postgres
  307. );
  308. > CREATE SOURCE "mz_source"
  309. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source')
  310. FOR TABLES ("numbers");
  311. > SELECT * FROM "numbers";
  312. 1 true one
  313. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  314. INSERT INTO numbers VALUES (2, true, 'two');
  315. > SELECT * FROM "numbers";
  316. 1 true one
  317. 2 true two
  318. > DROP SOURCE "mz_source" CASCADE;
  319. > DROP CONNECTION pgconn;
  320. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  321. DELETE FROM numbers WHERE number = 2;
  322. # server: certuser, client: verify-full => OK
  323. > CREATE CONNECTION pgconn TO POSTGRES (
  324. HOST postgres,
  325. USER certuser,
  326. SSL MODE verify_full,
  327. SSL CERTIFICATE SECRET ssl_cert,
  328. SSL KEY SECRET ssl_key,
  329. SSL CERTIFICATE AUTHORITY SECRET ssl_ca,
  330. DATABASE postgres
  331. );
  332. > CREATE SOURCE "mz_source"
  333. FROM POSTGRES CONNECTION pgconn (PUBLICATION 'mz_source')
  334. FOR TABLES ("numbers");
  335. > SELECT * FROM "numbers";
  336. 1 true one
  337. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  338. INSERT INTO numbers VALUES (2, true, 'two');
  339. > SELECT * FROM "numbers";
  340. 1 true one
  341. 2 true two
  342. > DROP SOURCE "mz_source" CASCADE;
  343. > DROP CONNECTION pgconn;
  344. $ postgres-execute connection=postgres://postgres:postgres@postgres:5432
  345. DELETE FROM numbers WHERE number = 2;
  346. # missing sslcert
  347. ! CREATE CONNECTION pgconn TO POSTGRES (
  348. HOST postgres,
  349. USER certuser,
  350. SSL MODE verify_full,
  351. SSL CERTIFICATE SECRET noexist,
  352. SSL KEY SECRET ssl_key,
  353. SSL CERTIFICATE AUTHORITY SECRET ssl_ca,
  354. DATABASE postgres
  355. );
  356. contains:unknown catalog item 'noexist'
  357. # missing sslkey
  358. ! CREATE CONNECTION pgconn TO POSTGRES (
  359. HOST postgres,
  360. USER certuser,
  361. SSL MODE verify_full,
  362. SSL CERTIFICATE SECRET ssl_cert,
  363. SSL KEY SECRET noexist,
  364. SSL CERTIFICATE AUTHORITY SECRET ssl_ca,
  365. DATABASE postgres
  366. );
  367. contains:unknown catalog item 'noexist'
  368. # missing sslrootcert
  369. ! CREATE CONNECTION pgconn TO POSTGRES (
  370. HOST postgres,
  371. USER certuser,
  372. SSL MODE verify_full,
  373. SSL CERTIFICATE SECRET ssl_cert,
  374. SSL KEY SECRET ssl_key,
  375. SSL CERTIFICATE AUTHORITY SECRET noexist,
  376. DATABASE postgres
  377. );
  378. contains:unknown catalog item 'noexist'
  379. # require both sslcert and sslkey
  380. ! CREATE CONNECTION pgconn TO POSTGRES (
  381. HOST postgres,
  382. USER certuser,
  383. SSL MODE verify_full,
  384. SSL CERTIFICATE SECRET ssl_cert,
  385. DATABASE postgres
  386. );
  387. contains:invalid CONNECTION: both SSL KEY and SSL CERTIFICATE are required
  388. ! CREATE CONNECTION pgconn TO POSTGRES (
  389. HOST postgres,
  390. USER certuser,
  391. SSL MODE verify_full,
  392. SSL KEY SECRET ssl_cert,
  393. DATABASE postgres
  394. );
  395. contains:invalid CONNECTION: both SSL KEY and SSL CERTIFICATE are required