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