pgpool2.git / summary / log / commit / refs

commit    dc9742678dd04719a08a747d40cd4c0781fce49a
Author:   Tatsuo Ishii <ishii@sraoss.co.jp>
Date:     Fri Jun 07 07:50:39 2019 +0000

    Allow to use MD5 hashed password in health_check_password and sr_check_password.
    
    If they are left blank (empty string), then pool_passwd is consulted.


doc.ja/src/sgml/healthcheck.sgml | 81 ++++++++++++++++++------------------ doc.ja/src/sgml/stream-check.sgml | 86 ++++++++++++++++++++------------------- doc/src/sgml/healthcheck.sgml | 71 +++++++++++++++++++++++--------- doc/src/sgml/stream-check.sgml | 77 +++++++++++++++++++++++++---------- src/auth/pool_auth.c | 13 +++++- src/auth/pool_passwd.c | 16 ++++---- 6 files changed, 213 insertions(+), 131 deletions(-) diff --git a/doc.ja/src/sgml/healthcheck.sgml b/doc.ja/src/sgml/healthcheck.sgml index 0305b847f..3c70277e6 100644 --- a/doc.ja/src/sgml/healthcheck.sgml +++ b/doc.ja/src/sgml/healthcheck.sgml @@ -176,47 +176,50 @@ TCP接続が時間内に成功せずにバックエンドの<productname>Postgre <varname>health_check_password</varname>が空白のままの場合、 <productname>Pgpool-II</productname>は空のパスワードを使用する前にまず<xref linkend="guc-pool-passwd">ファイルから<xref linkend="guc-health-check-user">のパスワードを取得できるか試みます。 </para> <para> -<!-- - You can also specify AES256-CBC encrypted password in <varname>health_check_password</varname> field. - To specify the <literal>AES</literal> encrypted password, password string must be prefixed with - <literal>AES</literal> after encrypting (using <literal>aes-256-cbc</literal> algorithm) and - encoding to <literal>base64</literal>. ---> -<varname>health_check_password</varname>にAES256-CBCで暗号化されたパスワードも指定することができます。 -<literal>AES</literal>で暗号化されたパスワードを指定するためには、パスワード文字列は暗号化(<literal>aes-256-cbc</literal>アルゴリズムを使用)および<literal>base64</literal>でエンコードした後、<literal>AES</literal>を接頭辞として付けなければいけません。 - </para> - <para> -<!-- - To specify the unencrypted clear text password, prefix the password string with - <literal>TEXT</literal>. For example if you want to set <literal>mypass</literal> as - a password, you should specify <literal>TEXTmypass</literal> in the password field. - In the absence of a valid prefix, <productname>Pgpool-II</productname> will considered - the string as a plain text password. ---> -暗号化されていないクリアテキストパスワードを指定するためには、<literal>TEXT</literal>をパスワード文字列の前に付けます。 -例えば、パスワードとして<literal>mypass</literal>を設定したい場合、パスワードフィールドに<literal>TEXTmypass</literal>と指定すべきです。 -有効な接頭辞がない場合、<productname>Pgpool-II</productname>は平文のパスワードとして文字列を見なします。 - </para> - <para> -<!-- - You can also use <xref linkend="PG-ENC"> utility to create the correctly formatted - <literal>AES</literal> encrypted password strings. ---> -正しくフォーマットされた<literal>AES</literal>暗号化パスワード文字を<xref linkend="PG-ENC">コマンドを使用して作成することもできます。 - <note> - <para> -<!-- - <productname>Pgpool-II</productname> will require a valid decryption key at the - startup to use the encrypted passwords. - see <xref linkend="auth-aes-decryption-key"> for more details on providing the - decryption key to <productname>Pgpool-II</productname> ---> -<productname>Pgpool-II</productname>は暗号化されたパスワードを使うために起動時に有効な復号鍵を要求します。 -<productname>Pgpool-II</productname>に復号鍵を提供する方法の詳細は<xref linkend="auth-aes-decryption-key">を参照してください。 - </para> + <productname>Pgpool-II</productname>は、<varname>health_check_password</varname>あるいは<xref linkend="guc-pool-passwd">ファイルで以下の形式のパスワード格納できます。 + <variablelist> - </note> + <varlistentry> + <term>AES256-CBC暗号化パスワード</term> + <listitem> + <para> + パスワードを格納する最もセキュアで推奨できる方法です。 + パスワード文字列は<literal>AES</literal>で始まっていなければなりません。 + <xref linkend="PG-ENC">ユーティリティを使って正しく<literal>AES</literal>で暗号化された文字列を作ることができます。 + <productname>Pgpool-II</productname>は暗号化されたパスワードを使うために起動時に有効な復号鍵を要求します。 + <productname>Pgpool-II</productname>に復号鍵を提供する方法の詳細は<xref linkend="auth-aes-decryption-key">を参照してください。 + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>MD5ハッシュパスワード</term> + <listitem> + <para> + AESほどはセキュアではありませんが、平文パスワードよりは良いです。 + パスワード文字列は<literal>MD5</literal>で始まっていなければなりません。 + バックエンドにはMD5認証を設定しなければならないことに注意してください。 + <xref linkend="PG-MD5">ユーティリティを使って正しい<literal>MD5</literal>ハッシュパワード文字列を作ることができます。 + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>平文パスワード</term> + <listitem> + <para> + 暗号化されていない平分のパスワードです。 + 可能ならば使用を避けるべきです。 + パスワード文字列は<literal>TEXT</literal>で始まっていなければなりません。 + 例えば、パスワードとして<literal>mypass</literal>を設定したい場合、パスワードフィールドに<literal>TEXTmypass</literal>と指定します。 + 有効な接頭辞がない場合、<productname>Pgpool-II</productname>は平文のパスワードとして文字列を見なします。 + </para> + </listitem> + </varlistentry> + + </variablelist> </para> + <para> <!-- This parameter can be changed by reloading the <productname>Pgpool-II</> configurations. diff --git a/doc.ja/src/sgml/stream-check.sgml b/doc.ja/src/sgml/stream-check.sgml index bee06508c..344c86586 100644 --- a/doc.ja/src/sgml/stream-check.sgml +++ b/doc.ja/src/sgml/stream-check.sgml @@ -129,48 +129,50 @@ --> <varname>sr_check_password</varname>が空白のままの場合、 <productname>Pgpool-II</productname>は空のパスワードを使用する前にまず<xref linkend="guc-pool-passwd">ファイルから<xref linkend="guc-sr-check-user">のパスワードを取得できるか試みます。 </para> - <para> -<!-- - You can also specify AES256-CBC encrypted password in <varname>sr_check_password</varname> field. - To specify the <literal>AES</literal> encrypted password, password string must be prefixed with - <literal>AES</literal> after encrypting (using <literal>aes-256-cbc</literal> algorithm) and - encoding to <literal>base64</literal>. ---> -<varname>sr_check_password</varname>にAES256-CBCで暗号化されたパスワードも指定することができます。 -<literal>AES</literal>で暗号化されたパスワードを指定するためには、パスワード文字列は暗号化(<literal>aes-256-cbc</literal>アルゴリズムを使用)および<literal>base64</literal>でエンコードした後、<literal>AES</literal>を接頭辞として付けなければいけません。 - </para> - <para> -<!-- - To specify the unencrypted clear text password, prefix the password string with - <literal>TEXT</literal>. For example if you want to set <literal>mypass</literal> as - a password, you should specify <literal>TEXTmypass</literal> in the password field. - In the absence of a valid prefix, <productname>Pgpool-II</productname> will considered - the string as a plain text password. ---> -暗号化されていないクリアテキストパスワードを指定するためには、<literal>TEXT</literal>をパスワード文字列の前に付けます。 -例えば、パスワードとして<literal>mypass</literal>を設定したい場合、パスワードフィールドに<literal>TEXTmypass</literal>と指定すべきです。 -有効な接頭辞がない場合、<productname>Pgpool-II</productname>は平文のパスワードとして文字列を見なします。 - </para> - <para> -<!-- - You can also use <xref linkend="PG-ENC"> utility to create the correctly formatted - <literal>AES</literal> encrypted password strings. ---> -正しくフォーマットされた<literal>AES</literal>暗号化パスワードを<xref linkend="PG-ENC">コマンドを使用して作成することもできます。 - - <note> - <para> -<!-- - <productname>Pgpool-II</productname> will require a valid decryption key at the - startup to use the encrypted passwords. - see <xref linkend="auth-aes-decryption-key"> for more details on providing the - decryption key to <productname>Pgpool-II</productname> ---> -<productname>Pgpool-II</productname>は暗号化されたパスワードを使うために起動時に有効な復号鍵を要求します。 -<productname>Pgpool-II</productname>に復号鍵を提供する方法の詳細は<xref linkend="auth-aes-decryption-key">を参照してください。 - </para> - </note> - </para> + <para> + <productname>Pgpool-II</productname>は、<varname>sr_check_password</varname>あるいは<xref linkend="guc-pool-passwd">ファイルで以下の形式のパスワード格納できます。 + <variablelist> + + <varlistentry> + <term>AES256-CBC暗号化パスワード</term> + <listitem> + <para> + パスワードを格納する最もセキュアで推奨できる方法です。 + パスワード文字列は<literal>AES</literal>で始まっていなければなりません。 + <xref linkend="PG-ENC">ユーティリティを使って正しく<literal>AES</literal>で暗号化された文字列を作ることができます。 + <productname>Pgpool-II</productname>は暗号化されたパスワードを使うために起動時に有効な復号鍵を要求します。 + <productname>Pgpool-II</productname>に復号鍵を提供する方法の詳細は<xref linkend="auth-aes-decryption-key">を参照してください。 + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>MD5ハッシュパスワード</term> + <listitem> + <para> + AESほどはセキュアではありませんが、平文パスワードよりは良いです。 + パスワード文字列は<literal>MD5</literal>で始まっていなければなりません。 + バックエンドにはMD5認証を設定しなければならないことに注意してください。 + <xref linkend="PG-MD5">ユーティリティを使って正しい<literal>MD5</literal>ハッシュパワード文字列を作ることができます。 + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>平文パスワード</term> + <listitem> + <para> + 暗号化されていない平分のパスワードです。 + 可能ならば使用を避けるべきです。 + パスワード文字列は<literal>TEXT</literal>で始まっていなければなりません。 + 例えば、パスワードとして<literal>mypass</literal>を設定したい場合、パスワードフィールドに<literal>TEXTmypass</literal>と指定します。 + 有効な接頭辞がない場合、<productname>Pgpool-II</productname>は平文のパスワードとして文字列を見なします。 + </para> + </listitem> + </varlistentry> + + </variablelist> + </para> <para> <!-- diff --git a/doc/src/sgml/healthcheck.sgml b/doc/src/sgml/healthcheck.sgml index 24b660b79..280aac974 100644 --- a/doc/src/sgml/healthcheck.sgml +++ b/doc/src/sgml/healthcheck.sgml @@ -111,30 +111,63 @@ <xref linkend="guc-pool-passwd"> file before using the empty password. </para> <para> - You can also specify AES256-CBC encrypted password in <varname>health_check_password</varname> field. - To specify the <literal>AES</literal> encrypted password, password string must be prefixed with - <literal>AES</literal> after encrypting (using <literal>aes-256-cbc</literal> algorithm) and - encoding to <literal>base64</literal>. - </para> - <para> - To specify the unencrypted clear text password, prefix the password string with - <literal>TEXT</literal>. For example if you want to set <literal>mypass</literal> as - a password, you should specify <literal>TEXTmypass</literal> in the password field. - In the absence of a valid prefix, <productname>Pgpool-II</productname> will considered - the string as a plain text password. - </para> - <para> - You can also use <xref linkend="PG-ENC"> utility to create the correctly formatted - <literal>AES</literal> encrypted password strings. - <note> - <para> + <productname>Pgpool-II</productname> accepts following forms + of password in either <varname>health_check_password</varname> + or <xref linkend="guc-pool-passwd"> file: + <variablelist> + + <varlistentry> + <term>AES256-CBC encrypted password</term> + <listitem> + <para> + Most secure and recommended way to store password. The + password string must be prefixed + with <literal>AES</literal>. + You can use <xref linkend="PG-ENC"> utility to create the correctly formatted + <literal>AES</literal> encrypted password strings. <productname>Pgpool-II</productname> will require a valid decryption key at the startup to use the encrypted passwords. see <xref linkend="auth-aes-decryption-key"> for more details on providing the decryption key to <productname>Pgpool-II</productname> - </para> - </note> + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>MD5 hashed password</term> + <listitem> + <para> + Not so secure as AES256, but still better than clear + text password. The password string must be prefixed + with <literal>MD5</literal>. Note that the backend + must set up MD5 authentication as well. You can + use <xref linkend="PG-MD5"> utility to create the + correctly formatted + <literal>MD5</literal> hashed password strings. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>Plain text password</term> + <listitem> + <para> + Not encrypted, clear text password. You should avoid + to use this if possible. The password string must be + prefixed with <literal>TEXT</literal>. For example if + you want to set <literal>mypass</literal> as a + password, you should + specify <literal>TEXTmypass</literal> in the password + field. In the absence of a valid + prefix, <productname>Pgpool-II</productname> will + considered the string as a plain text password. + </para> + </listitem> + </varlistentry> + + </variablelist> </para> + <para> This parameter can be changed by reloading the <productname>Pgpool-II</> configurations. </para> diff --git a/doc/src/sgml/stream-check.sgml b/doc/src/sgml/stream-check.sgml index 621c0b74d..b02d8e368 100644 --- a/doc/src/sgml/stream-check.sgml +++ b/doc/src/sgml/stream-check.sgml @@ -85,31 +85,64 @@ will first try to get the password for <xref linkend="guc-sr-check-user"> from <xref linkend="guc-pool-passwd"> file before using the empty password. </para> - <para> - You can also specify AES256-CBC encrypted password in <varname>sr_check_password</varname> field. - To specify the <literal>AES</literal> encrypted password, password string must be prefixed with - <literal>AES</literal> after encrypting (using <literal>aes-256-cbc</literal> algorithm) and - encoding to <literal>base64</literal>. - </para> - <para> - To specify the unencrypted clear text password, prefix the password string with - <literal>TEXT</literal>. For example if you want to set <literal>mypass</literal> as - a password, you should specify <literal>TEXTmypass</literal> in the password field. - In the absence of a valid prefix, <productname>Pgpool-II</productname> will considered - the string as a plain text password. - </para> - <para> - You can also use <xref linkend="PG-ENC"> utility to create the correctly formatted - <literal>AES</literal> encrypted password strings. - <note> - <para> + + <para> + <productname>Pgpool-II</productname> accepts following forms + of password in either <varname>sr_check_password</varname> + or <xref linkend="guc-pool-passwd"> file: + <variablelist> + + <varlistentry> + <term>AES256-CBC encrypted password</term> + <listitem> + <para> + Most secure and recommended way to store password. The + password string must be prefixed + with <literal>AES</literal>. + You can use <xref linkend="PG-ENC"> utility to create the correctly formatted + <literal>AES</literal> encrypted password strings. <productname>Pgpool-II</productname> will require a valid decryption key at the startup to use the encrypted passwords. see <xref linkend="auth-aes-decryption-key"> for more details on providing the - decryption key to <productname>Pgpool-II</productname> - </para> - </note> - </para> + decryption key to <productname>Pgpool-II</productname> + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>MD5 hashed password</term> + <listitem> + <para> + Not so secure as AES256, but still better than clear + text password. The password string must be prefixed + with <literal>MD5</literal>. Note that the backend + must set up MD5 authentication as well. You can + use <xref linkend="PG-MD5"> utility to create the + correctly formatted + <literal>MD5</literal> hashed password strings. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>Plain text password</term> + <listitem> + <para> + Not encrypted, clear text password. You should avoid + to use this if possible. The password string must be + prefixed with <literal>TEXT</literal>. For example if + you want to set <literal>mypass</literal> as a + password, you should + specify <literal>TEXTmypass</literal> in the password + field. In the absence of a valid + prefix, <productname>Pgpool-II</productname> will + considered the string as a plain text password. + </para> + </listitem> + </varlistentry> + + </variablelist> + </para> <para> This parameter can be changed by reloading the <productname>Pgpool-II</> configurations. diff --git a/src/auth/pool_auth.c b/src/auth/pool_auth.c index 78316b819..5c790a9b4 100644 --- a/src/auth/pool_auth.c +++ b/src/auth/pool_auth.c @@ -187,9 +187,18 @@ connection_do_auth(POOL_CONNECTION_POOL_SLOT * cp, char *password) buf = palloc0(2 * (MD5_PASSWD_LEN + 4)); /* hash + "md5" + '\0' */ - /* build md5 password */ + /* set buffer address for building md5 password */ buf1 = buf + MD5_PASSWD_LEN + 4; - pool_md5_encrypt(password, cp->sp->user, strlen(cp->sp->user), buf1); + + /* + * If the supplied password is already in md5 hash format, we just + * copy it. Otherwise calculate the md5 hash value. + */ + if (!strncmp("md5", password, 3) && (strlen(password) - 3) == MD5_PASSWD_LEN) + memcpy(buf1, password + 3, MD5_PASSWD_LEN + 1); + else + pool_md5_encrypt(password, cp->sp->user, strlen(cp->sp->user), buf1); + pool_md5_encrypt(buf1, salt, 4, buf + 3); memcpy(buf, "md5", 3); diff --git a/src/auth/pool_passwd.c b/src/auth/pool_passwd.c index c84136bb4..a24eb9b62 100644 --- a/src/auth/pool_passwd.c +++ b/src/auth/pool_passwd.c @@ -449,10 +449,10 @@ pool_reopen_passwd_file(void) } /* - * function first uses the password in the argument, if the - * argument is empty string or NULL, it looks for the password - * for uset in pool_passwd file. - * The returned password is always in plain text and palloc'd (if not null) + * function first uses the password in the argument, if the argument is empty + * string or NULL, it looks for the password for uset in pool_passwd file. + * The returned password is always in plain text or md5 hashed and palloc'd + * (if not null) */ char * get_pgpool_config_user_password(char *username, char *password_in_config) @@ -514,11 +514,13 @@ get_pgpool_config_user_password(char *username, char *password_in_config) password = (char*)(password + strlen(PASSWORD_TEXT_PREFIX)); } - if (password && strlen(password) && passwordType != PASSWORD_TYPE_PLAINTEXT) + if (password && strlen(password) && (passwordType != PASSWORD_TYPE_PLAINTEXT && + passwordType != PASSWORD_TYPE_MD5)) { /* - * Could not find plain text password in pool_passwd corresponding to the user. - * This is normal. Just use empty password in pgpool.conf. + * Could not find either plain text or md5 hashed password in + * pool_passwd corresponding to the user. This is normal. Just use + * empty password in pgpool.conf. */ ereport(DEBUG5, (errmsg("could not get the password for user:%s", username), [parent: d7d1b0e557b4]