Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iRfjm-0001vX-Ca for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Nov 2019 17:01:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iRfjk-0000KS-Vl for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Nov 2019 17:01:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iRfjk-0000KL-KC for pgsql-hackers@lists.postgresql.org; Mon, 04 Nov 2019 17:01:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iRfjh-0001Ij-AW for pgsql-hackers@lists.postgresql.org; Mon, 04 Nov 2019 17:01:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xA4H1kXR030951; Mon, 4 Nov 2019 12:01:46 -0500 From: Tom Lane To: pgsql-hackers@lists.postgresql.org cc: La Cancellera Yoann Subject: Re: Issues with PAM : log that it failed, whether it actually failed or not In-reply-to: <15705.1570802917@sss.pgh.pa.us> References: <15705.1570802917@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Fri, 11 Oct 2019 10:08:37 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <30702.1572886796.0@sss.pgh.pa.us> Date: Mon, 04 Nov 2019 12:01:46 -0500 Message-ID: <30950.1572886906@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30702.1572886796.1@sss.pgh.pa.us> [ redirecting to pgsql-hackers ] I wrote: > La Cancellera Yoann writes: >> I am having issues with PAM auth : >> it works, password are correctly checked, unknown users cannot access, >> known user can, everything looks good >> But, it always log an error by default even if auth is succesful: >> And if auth is unsuccessful, it will log that very same message twice > Those aren't errors, they're just log events. > If you're using psql to connect, the extra messages aren't surprising, > because psql will first try to connect without a password, and only > if it gets a failure that indicates that a password is needed will > it prompt the user for a password (so two connection attempts occur, > even if the second one is successful). You can override that default > behavior with the -W switch, and I bet that will make the extra > log messages go away. > Having said that, using LOG level for unsurprising auth failures > seems excessively chatty. More-commonly-used auth methods aren't > that noisy. I took a closer look at this and realized that the problem is that the PAM code doesn't support our existing convention of not logging anything about connections wherein the client side disconnects when challenged for a password. 0001 attached fixes that, not in a terribly nice way perhaps, but the PAM code is already relying on static variables for communication :-(. Also, 0002 adjusts some messages in the same file to match project capitalization conventions. Barring objections, I propose to back-patch 0001 but apply 0002 to HEAD only. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="0001-suppress-PAM-logging-for-EOF.patch"; charset="us-ascii" Content-ID: <30702.1572886796.2@sss.pgh.pa.us> Content-Description: 0001-suppress-PAM-logging-for-EOF.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index d28271c..909d736 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -110,6 +110,7 @@ static const char *pam_passwd =3D NULL; /* Workaround = for Solaris 2.6 * brokenness */ static Port *pam_port_cludge; /* Workaround for passing "Port *port" into * pam_passwd_conv_proc */ +static bool pam_no_password; /* For detecting no-password-given */ #endif /* USE_PAM */ = = @@ -2099,8 +2099,10 @@ pam_passwd_conv_proc(int num_msg, const struct pam_= message **msg, { /* * Client didn't want to send password. We - * intentionally do not log anything about this. + * intentionally do not log anything about this, + * either here or at higher levels. */ + pam_no_password =3D true; goto fail; } } @@ -2159,6 +2161,7 @@ CheckPAMAuth(Port *port, const char *user, const cha= r *password) */ pam_passwd =3D password; pam_port_cludge =3D port; + pam_no_password =3D false; = /* * Set the application data portion of the conversation struct. This is @@ -2244,22 +2247,26 @@ CheckPAMAuth(Port *port, const char *user, const c= har *password) = if (retval !=3D PAM_SUCCESS) { - ereport(LOG, - (errmsg("pam_authenticate failed: %s", - pam_strerror(pamh, retval)))); + /* If pam_passwd_conv_proc saw EOF, don't log anything */ + if (!pam_no_password) + ereport(LOG, + (errmsg("pam_authenticate failed: %s", + pam_strerror(pamh, retval)))); pam_passwd =3D NULL; /* Unset pam_passwd */ - return STATUS_ERROR; + return pam_no_password ? STATUS_EOF : STATUS_ERROR; } = retval =3D pam_acct_mgmt(pamh, 0); = if (retval !=3D PAM_SUCCESS) { - ereport(LOG, - (errmsg("pam_acct_mgmt failed: %s", - pam_strerror(pamh, retval)))); + /* If pam_passwd_conv_proc saw EOF, don't log anything */ + if (!pam_no_password) + ereport(LOG, + (errmsg("pam_acct_mgmt failed: %s", + pam_strerror(pamh, retval)))); pam_passwd =3D NULL; /* Unset pam_passwd */ - return STATUS_ERROR; + return pam_no_password ? STATUS_EOF : STATUS_ERROR; } = retval =3D pam_end(pamh, retval); ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="0002-message-style-police.patch"; charset="us-ascii" Content-ID: <30702.1572886796.3@sss.pgh.pa.us> Content-Description: 0002-message-style-police.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index d28271c..909d736 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -959,7 +960,7 @@ CheckSCRAMAuth(Port *port, char *shadow_pass, char **l= ogdetail) return STATUS_ERROR; } = - elog(DEBUG4, "Processing received SASL response of length %d", buf.len)= ; + elog(DEBUG4, "processing received SASL response of length %d", buf.len)= ; = /* * The first SASLInitialResponse message is different from the others. @@ -1150,7 +1151,7 @@ pg_GSS_recvauth(Port *port) gbuf.length =3D buf.len; gbuf.value =3D buf.data; = - elog(DEBUG4, "Processing received GSS token of length %u", + elog(DEBUG4, "processing received GSS token of length %u", (unsigned int) gbuf.length); = maj_stat =3D gss_accept_sec_context( @@ -1427,8 +1428,7 @@ pg_SSPI_recvauth(Port *port) outbuf.pBuffers =3D OutBuffers; outbuf.ulVersion =3D SECBUFFER_VERSION; = - - elog(DEBUG4, "Processing received SSPI token of length %u", + elog(DEBUG4, "processing received SSPI token of length %u", (unsigned int) buf.len); = r =3D AcceptSecurityContext(&sspicred, @@ -2949,7 +2956,7 @@ radius_add_attribute(radius_packet *packet, uint8 ty= pe, const unsigned char *dat * fail. */ elog(WARNING, - "Adding attribute code %d with length %d to radius packet would creat= e oversize packet, ignoring", + "adding attribute code %d with length %d to radius packet would creat= e oversize packet, ignoring", type, len); return; } ------- =_aaaaaaaaaa0--