<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 25, 2018 at 12:09 PM Tatsuo Ishii &lt;<a href="mailto:ishii@sraoss.co.jp">ishii@sraoss.co.jp</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Usama,<br>
<br>
&gt; Hi Ishii-San<br>
&gt; <br>
&gt; <br>
&gt; On Mon, Jul 23, 2018 at 7:13 AM Tatsuo Ishii &lt;<a href="mailto:ishii@sraoss.co.jp" target="_blank">ishii@sraoss.co.jp</a>&gt; wrote:<br>
&gt; <br>
&gt;&gt; Usama,<br>
&gt;&gt;<br>
&gt;&gt; Thank you for the updation!<br>
&gt;&gt;<br>
&gt;&gt; Here are some commnets.<br>
&gt;&gt;<br>
&gt;&gt; 1) There are some traling space additions in the patch.<br>
&gt;&gt;<br>
&gt;&gt; t-ishii@localhost: git apply ~/scram_auth_feature_patch.diff<br>
&gt;&gt; /home/t-ishii/scram_auth_feature_patch.diff:1692: trailing whitespace.<br>
&gt;&gt;<br>
&gt;&gt; /home/t-ishii/scram_auth_feature_patch.diff:1696: trailing whitespace.<br>
&gt;&gt;<br>
&gt;&gt; /home/t-ishii/scram_auth_feature_patch.diff:1702: trailing whitespace.<br>
&gt;&gt;<br>
&gt;&gt; /home/t-ishii/scram_auth_feature_patch.diff:1709: trailing whitespace.<br>
&gt;&gt;<br>
&gt;&gt; /home/t-ishii/scram_auth_feature_patch.diff:2792: trailing whitespace.<br>
&gt;&gt;<br>
&gt;&gt; warning: squelched 87 whitespace errors<br>
&gt;&gt; warning: 92 lines add whitespace errors.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt; Yes there are few debug message cleanups and these whitespaces error exists<br>
&gt; in the patch,<br>
&gt; I will fix those in next version.<br>
<br>
Ok.<br>
<br>
&gt;&gt; 2) Design suggesions<br>
&gt;&gt;<br>
&gt;&gt; &gt; Note: allow_clear_text_frontend_auth only works when pool_hba.conf is not<br>
&gt;&gt; &gt; enabled in pgpool.conf<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; For example: suppose PostgreSQL servers has a user named &quot;*some_user*&quot;<br>
&gt;&gt; &gt; which can connect to database using SCRAM authentication, Now for this<br>
&gt;&gt; &gt; &quot;some_user&quot; to connect to PostgreSQL using SCRAM through Pgpool-II we<br>
&gt;&gt; must<br>
&gt;&gt; &gt; have the *some_user*&#39;s password stored in the pool_passwd file, but if in<br>
&gt;&gt; &gt; some case when pool_passwd does not have the entry of &quot;*some_user*&quot; and<br>
&gt;&gt; &gt; *allow_clear_text_frontend_auth *is enabled in the pgpool.conf then<br>
&gt;&gt; &gt; Pgpool-II will ask the connecting frontend to use clear-text-password<br>
&gt;&gt; auth<br>
&gt;&gt; &gt; method for authentication, and after receiving the password from the<br>
&gt;&gt; &gt; client, Pgpool-II will use that password to authenticate with backend<br>
&gt;&gt; using<br>
&gt;&gt; &gt; the required SCRAM auth.<br>
&gt;&gt;<br>
&gt;&gt; Why do we need &quot;allow_clear_text_frontend_auth&quot;? Rather, can&#39;t we set<br>
&gt;&gt; &quot;password&quot; in the pool_hba.conf auth method for a user who is allow to<br>
&gt;&gt; connect to pgpool with clear text password? This way is more flexible<br>
&gt;&gt; since at the same we can force different user MD5 and/or SCRAM auth.<br>
&gt;&gt;<br>
&gt; <br>
&gt; Setting the &quot;password&quot; auth in pool_hba.conf  does work as you described,<br>
&gt; while allow_clear_text_frontend_auth is for the cases when pool_hba is<br>
&gt; disabled in pgpool.conf.<br>
&gt; So setting allow_clear_text_frontend_auth allows the clients to connect<br>
&gt; through pgpool<br>
&gt; when they don&#39;t want to use pool_hba while backend requires SCRAM or MD5<br>
&gt; auth.<br>
<br>
Ok, that makes sense.<br>
<br>
&gt;&gt; 4) Migration of pool_passwd<br>
&gt;&gt;<br>
&gt;&gt; If user have large number of entries in pool_passwd, migrating to new<br>
&gt;&gt; pool_passwd using AES encryption is pain. Is there any way to migate<br>
&gt;&gt; the pain?<br>
&gt;&gt;<br>
&gt; <br>
&gt; Yes that could be a problem, and also the case<br>
&gt; when user want to change the encryption password for entries in pool_passwd.<br>
&gt; I will try to enhance pg_enc to tackle these two cases separately.<br>
&gt; But for the older versions pool_passwd file I don&#39;t think we can do much<br>
&gt; about the existing<br>
&gt; entries. since currently pool_passwd only supports MD5 entries which is one<br>
&gt; way<br>
&gt; hashing. So for old pool_passwd file either users have to create new<br>
&gt; entries from scratch or have<br>
&gt; to stick with MD5 auth.<br>
&gt; Do you have some suggestion to work around that?<br>
<br>
No. Probably there&#39;s no clear answer to this for now. Let&#39;s leave as<br>
it until we come up with a better idea.<br></blockquote><div><br></div><div>Sure </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
BTW, in the new regression test: 021.pool_passwd_auth I see clear text<br>
password is stored in pool_passwd. I thought your implementation<br>
allows to store password in AES 256 encryption, which is great. Is<br>
there any reason you did not use the feature?<br></blockquote><div><br></div><div>Not really, Actually I wrote the test case before completing the AES encryption system,</div><div>I will add another test case to test encrypted passwords in pool_passwd</div><div><br></div><div>Thanks</div><div>Best Regards</div><div>Muhammad Usama</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
&gt; Thanks<br>
&gt; Best Regards<br>
&gt; Muhammad Usama<br>
&gt; <br>
&gt; <br>
&gt;&gt;<br>
&gt;&gt; Best regards,<br>
&gt;&gt; --<br>
&gt;&gt; Tatsuo Ishii<br>
&gt;&gt; SRA OSS, Inc. Japan<br>
&gt;&gt; English: <a href="http://www.sraoss.co.jp/index_en.php" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
&gt;&gt; Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.jp</a><br>
&gt;&gt;<br>
&gt;&gt; &gt; Hi All,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I have been working on supporting the new authentication methods in<br>
&gt;&gt; &gt; Pgpool-II, So here is the working patch for supporting the SCRAM and CERT<br>
&gt;&gt; &gt; based authentication methods.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; The patch needs a some compilation warning fixes and little bit of review<br>
&gt;&gt; &gt; of memory management and code cleanups (which I am working on) but other<br>
&gt;&gt; &gt; than that it is ready for review testing.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; The code is also checked-in to SCRAM_AUTH branch in Pgpool&#39;s git repo<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Below is the brief overview of changes made by the patch and how to use<br>
&gt;&gt; the<br>
&gt;&gt; &gt; newly added auth methods.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; *Allow different auth methods for frontend and backend for user session:*<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; The patch made it possible to use different authentication methods<br>
&gt;&gt; between<br>
&gt;&gt; &gt; client to Pgpool-II and Pgpool-II to backend.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; For example: now we can use clear-text-password authentication between<br>
&gt;&gt; &gt; Pgpool-II and frontend applications while md5 or scram auth method to<br>
&gt;&gt; &gt; authenticate the backend connections for same session. Similarly the<br>
&gt;&gt; &gt; frontend can now be authenticated using the ssl certificate (CERT auth)<br>
&gt;&gt; &gt; while for backend we can use md5 or scram for the same session.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; *Able to use MD5 and SCRAM auth methods without pool_passwd:*<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; The patch adds a new configuration parameter<br>
&gt;&gt; &gt; *allow_clear_text_frontend_auth*, enabling this config allows the<br>
&gt;&gt; Pgpool-II<br>
&gt;&gt; &gt; to use clear-text-password authentication with frontend clients when<br>
&gt;&gt; &gt; pool_passwd file does not contains the password for the connecting user,<br>
&gt;&gt; &gt; and use that password (provided by client) to authenticate with the<br>
&gt;&gt; backend<br>
&gt;&gt; &gt; using MD5 and/or SCRAM authentication.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Note: allow_clear_text_frontend_auth only works when pool_hba.conf is not<br>
&gt;&gt; &gt; enabled in pgpool.conf<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; For example: suppose PostgreSQL servers has a user named &quot;*some_user*&quot;<br>
&gt;&gt; &gt; which can connect to database using SCRAM authentication, Now for this<br>
&gt;&gt; &gt; &quot;some_user&quot; to connect to PostgreSQL using SCRAM through Pgpool-II we<br>
&gt;&gt; must<br>
&gt;&gt; &gt; have the *some_user*&#39;s password stored in the pool_passwd file, but if in<br>
&gt;&gt; &gt; some case when pool_passwd does not have the entry of &quot;*some_user*&quot; and<br>
&gt;&gt; &gt; *allow_clear_text_frontend_auth *is enabled in the pgpool.conf then<br>
&gt;&gt; &gt; Pgpool-II will ask the connecting frontend to use clear-text-password<br>
&gt;&gt; auth<br>
&gt;&gt; &gt; method for authentication, and after receiving the password from the<br>
&gt;&gt; &gt; client, Pgpool-II will use that password to authenticate with backend<br>
&gt;&gt; using<br>
&gt;&gt; &gt; the required SCRAM auth.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; *Creating encrypted passwords:*<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; The patch adds a new utility *pg_enc* to create AES encrypted password<br>
&gt;&gt; &gt; entries. The utility works similar in most ways as pg_md5 utility, with a<br>
&gt;&gt; &gt; some small differences,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; pg_enc also requires the key for encrypting the password entries. later<br>
&gt;&gt; &gt; that same key is required by Pgpool-II to decrypt the passwords to be<br>
&gt;&gt; used<br>
&gt;&gt; &gt; for authentication.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Note: Pgpool-II must be build with ssl (--with-openssl) support to use<br>
&gt;&gt; this<br>
&gt;&gt; &gt; encrypted password feature.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; *Storing the encrypted password in pool_passwd file*<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Since the SCRAM authentication method explicitly guards against the<br>
&gt;&gt; &gt; man-in-middle type attack so Pgpool-II can only use SCRAM auth method if<br>
&gt;&gt; it<br>
&gt;&gt; &gt; has the user password (or *allow_clear_text_frontend_auth *is enabled).<br>
&gt;&gt; But<br>
&gt;&gt; &gt; storing the clear text password in a file is never a good idea, so for<br>
&gt;&gt; that<br>
&gt;&gt; &gt; reason pool_passwd file now allows to store user password in AES-256<br>
&gt;&gt; &gt; encrypted format<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; for example:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; some_user:AESWJPIi/R2QJS4cHKTAtjATw==<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Note: database passwords are encrypted using AES 256 encryption and then<br>
&gt;&gt; &gt; encoded into base64 for storing in pool_passwd file, AES prefix is added<br>
&gt;&gt; to<br>
&gt;&gt; &gt; the encoded password strings after encryption+encoding for<br>
&gt;&gt; identification.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; *Ways to provide encryption key to pg_enc utility*<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; There are multiple ways to provide encryption key to pgenc utility.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 1- using stdin ( -P, --prompt-for-key)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 2- using command line argument (-K, --enc-key=ENCRYPTION_KEY)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 3- using key file (-k, --key-file=KEY_FILE)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    by default the pg_enc looks for the key in home/.pgpoolkey file<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    and the default location can be over ridden by PGPOOLKEYFILE<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    environment variable<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Try  pg_enc --help  for more details<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; *Providing encryption key to Pgpool-II*<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Pgpool-II reads the encryption key from *pgpoolkey* file, the path to the<br>
&gt;&gt; &gt; key file can be specified using the new (-k, --key-file=KEY_FILE) command<br>
&gt;&gt; &gt; line argument, if the argument is not provided, Pgpool-II will try to<br>
&gt;&gt; look<br>
&gt;&gt; &gt; for the key file in user&#39;s home directory.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; If you do not want to use the key file at default location and also do<br>
&gt;&gt; not<br>
&gt;&gt; &gt; want to specify the location in command line argument you can also<br>
&gt;&gt; specify<br>
&gt;&gt; &gt; the poolkey file in *PGPOOLKEYFILE* environment variable.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; If encryption key is not provided to Pgpool-II or the wrong encryption<br>
&gt;&gt; key<br>
&gt;&gt; &gt; is provided the encrypted password entries in pool_passwd becomes<br>
&gt;&gt; unusable.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; *AES encrypted password entries can also be used for md5 auth method*<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Previously only way to use md5 authentication method was to add md5<br>
&gt;&gt; encoded<br>
&gt;&gt; &gt; password to the pool_passwd file for the user. now with this<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; patch md5 authentication system in Pgpool-II can also use the AES<br>
&gt;&gt; encrypted<br>
&gt;&gt; &gt; passwords.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; So same AES encrypted password can be used for SCRAM, clear-text and md5<br>
&gt;&gt; &gt; authentications.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; *Using CERT authentication between Pgpool-II and frontend*<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; To use the cert authentication between Pgpool-II and frontend configure<br>
&gt;&gt; the<br>
&gt;&gt; &gt; following ssl configurations in pgpool.conf<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; ssl_key = &#39;/server.key&#39;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; ssl_cert = &#39;server.crt&#39;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; ssl_ca_cert = &#39;root.crt&#39;<br>
&gt;&gt; &gt; Note: You must use the same ssl certificates in Pgpool-II that are used<br>
&gt;&gt; by<br>
&gt;&gt; &gt; backend PostgreSQL server.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Now configure pool_hba.conf to use cert ( in this example we want<br>
&gt;&gt; &gt; PostgreSQL user named cert_user to use cert auth)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; *hostssl    all         cert_user         0/0     cert*<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; This will enable the cert authentication between pgpool and frontend<br>
&gt;&gt; &gt; clients. After this cert_user will only be able to connect to Pgpool-II<br>
&gt;&gt; &gt; when it will present the valid ssl client certificate with the<br>
&gt;&gt; certificate<br>
&gt;&gt; &gt; having the common name  same as the database user name (cert_user in this<br>
&gt;&gt; &gt; case)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; You can use any other auth method for same cert_user in backend.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I will also share the detailed step by step guide for using the cert<br>
&gt;&gt; &gt; authentication later.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; *Example test case for SCRAM authentication:*<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 1-- create user in PostgreSQL with SCRAM type password<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; SET password_encryption = &#39;scram-sha-256&#39;;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; CREATE ROLE scram_user PASSWORD &#39;scram_password&#39;;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; ALTER ROLE scram_user WITH LOGIN;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 2-- create the encryption key file in home directory<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; echo poolencryptionkey &gt;&gt; ~/.pgpoolkey<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 3-- create the pool_passwd entry for scram_user<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; pg_enc -m -f pgpool.conf -u sceam_user scram_password<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 4-- adjust pg_hba.conf to use scram for scram_user<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; host      all   scram_user     0/0    scram-sha-256<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 5-- configure pool_hba.conf to use scram for scram_user<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; host    all         scram_user         0/0     scram-sha-256<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 6-- restart postgresql and run pgpool<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 7-- connect through pgpool using scram user<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; psql -h 127.0.0.1 -U scram_user -p 9999 postgres<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; *Regression test cases*<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Patch also contains following three regression test cases, You can have a<br>
&gt;&gt; &gt; look into those get a idea.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 020.allow_clear_text_frontend_auth<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 021.pool_passwd_auth<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 022.pool_passwd_alternative_auth<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Comments and suggestions are most welcome.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Best Regards<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Muhammad Usama<br>
&gt;&gt;<br>
</blockquote></div></div>