Bruce, all,

* Bruce Momjian (br...@momjian.us) wrote:
> On Tue, Dec  9, 2014 at 05:38:25PM -0500, Stephen Frost wrote:
> > > My comment that include_realm is supported back to 8.4 was because there
> > > is an expectation that a pg_hba.conf file can be used unchanged across
> > > several major releases.  So when 9.5 comes out and people update their
> > > pg_hba.conf files for 9.5, those files will still work in old releases.
> > >  But the time to do those updates is then, not now.
> > 
> > The back-branches are being patched to discourage using the default
> > because it's not a secure approach.  New users start using PG all the
> > time and so changing the existing documentation is worthwhile to ensure
> > those new users understand.  A note in the release notes for whichever
> > minor release the change to the documentation shows up in would be a
> > good way to make existing users aware of the change and hopefully
> > encourage them to review their configuration.
> > 
> > If we don't agree that the change should be made then we can discuss
> > that, but everyone commenting so far has agreed on the change.
> 
> Where are we on this?

Patches for master and 9.4 attached.  The 9.4 patch should cherry-pick
down to the other current releases just fine.  Please provide any
comments or suggestions for changes.  If all looks good, I'll push this
to change the default for 9.5 to be include_realm=1 and the
documentation updates to recommend it in back-branches.

        Thanks!

                Stephen
From ee6682b895b2f00ac89da6355b28960c358b8569 Mon Sep 17 00:00:00 2001
From: Stephen Frost <sfr...@snowman.net>
Date: Mon, 27 Apr 2015 12:40:07 -0400
Subject: [PATCH] Change default for include_realm to 0

The default behavior for GSS and SSPI authentication methods has long
been to strip the realm off of the principal, however, this is not a
secure approach in multi-realm environments and the use-case for the
parameter at all has been superseded by the regex-based mapping support
available in pg_ident.conf.

Change the default for include_realm to be '0', meaning that we do
NOT remove the realm from the principal by default.  Any installations
which depend on the existing behavior will need to update their
configurations (ideally by leaving include_realm on and adding a mapping
in pg_ident.conf).  Note that the mapping capability exists in all
currently supported versions of PostgreSQL and so this change can be
done today.  Barring that, existing users can update their
configurations today to explicitly set include_realm=0 to ensure that
the prior behavior is maintained when they upgrade.

This needs to be noted in the release notes.

Per discussion with Magnus and Peter.
---
 doc/src/sgml/client-auth.sgml | 74 +++++++++++++++++++++++++++++--------------
 src/backend/libpq/hba.c       | 13 ++++++++
 2 files changed, 63 insertions(+), 24 deletions(-)

diff --git a/doc/src/sgml/client-auth.sgml b/doc/src/sgml/client-auth.sgml
index d27dd49..620ddc6 100644
--- a/doc/src/sgml/client-auth.sgml
+++ b/doc/src/sgml/client-auth.sgml
@@ -947,15 +947,24 @@ omicron         bryanh                  guest1
    </para>
 
    <para>
-    Client principals must have their <productname>PostgreSQL</> database user
-    name as their first component, for example
-    <literal>pgusername@realm</>.  Alternatively, you can use a user name
-    mapping to map from the first component of the principal name to the
-    database user name.  By default, the realm of the client is
-    not checked by <productname>PostgreSQL</>. If you have cross-realm
-    authentication enabled and need to verify the realm, use the
-    <literal>krb_realm</> parameter, or enable <literal>include_realm</>
-    and use user name mapping to check the realm.
+    Client principals can be mapped to different <productname>PostgreSQL</>
+    database user names with <filename>pg_ident.conf</>.  For example,
+    <literal>pgusername@realm</> could be mapped to just <literal>pgusername</>.
+    Alternatively, you can use the full <literal>username@realm</> principal as
+    the role name in <productname>PostgreSQL</> without any mapping.
+   </para>
+
+   <para>
+    <productname>PostgreSQL</> also supports a parameter to strip the realm from
+    the principal.  This method is supported for backwards compatibility and is
+    strongly discouraged as it is then impossible to distinguish different users
+    with the same username but coming from different realms.  To enable this,
+    set <literal>include_realm</> to 0.  For simple single-realm
+    installations, <literal>include_realm</> combined with the
+    <literal>krb_realm</> parameter (which checks that the realm provided
+    matches exactly what is in the krb_realm parameter) would be a secure but
+    less capable option compared to specifying an explicit mapping in
+    <filename>pg_ident.conf</>.
    </para>
 
    <para>
@@ -997,10 +1006,13 @@ omicron         bryanh                  guest1
       <term><literal>include_realm</literal></term>
       <listitem>
        <para>
-        If set to 1, the realm name from the authenticated user
-        principal is included in the system user name that's passed through
-        user name mapping (<xref linkend="auth-username-maps">). This is
-        useful for handling users from multiple realms.
+        If set to 0, the realm name from the authenticated user principal is
+        stripped off before being passed through the user name mapping
+        (<xref linkend="auth-username-maps">). This is discouraged and is
+        primairly available for backwards compatibility as it is not secure
+        in multi-realm environments unless krb_realm is also used.  Users
+        are recommended to leave include_realm set to the default (1) and to
+        provide an explicit mapping in <filename>pg_ident.conf</>.
        </para>
       </listitem>
      </varlistentry>
@@ -1010,12 +1022,15 @@ omicron         bryanh                  guest1
       <listitem>
        <para>
         Allows for mapping between system and database user names. See
-        <xref linkend="auth-username-maps"> for details. For a Kerberos
-        principal <literal>username/hostba...@example.com</literal>, the
-        user name used for mapping is <literal>username/hostbased</literal>
-        if <literal>include_realm</literal> is disabled, and
-        <literal>username/hostba...@example.com</literal> if
-        <literal>include_realm</literal> is enabled.
+        <xref linkend="auth-username-maps"> for details.  For a GSSAPI/Kerberos
+        principal, such as <literal>usern...@example.com</literal> (or, less
+        commonly, <literal>username/hostba...@example.com</literal>), the
+        user name used for mapping is
+        <literal>usern...@example.com</literal> (or
+        <literal>username/hostba...@example.com</literal>, respectfully),
+        unless <literal>include_realm</literal> has been set to 0, in which case
+        <literal>username</literal> (or <literal>username/hostbased</literal>)
+        is what is seen as the system username when mapping.
        </para>
       </listitem>
      </varlistentry>
@@ -1070,10 +1085,13 @@ omicron         bryanh                  guest1
       <term><literal>include_realm</literal></term>
       <listitem>
        <para>
-        If set to 1, the realm name from the authenticated user
-        principal is included in the system user name that's passed through
-        user name mapping (<xref linkend="auth-username-maps">). This is
-        useful for handling users from multiple realms.
+        If set to 0, the realm name from the authenticated user principal is
+        stripped off before being passed through the user name mapping
+        (<xref linkend="auth-username-maps">). This is discouraged and is
+        primairly available for backwards compatibility as it is not secure
+        in multi-realm environments unless krb_realm is also used.  Users
+        are recommended to leave include_realm set to the default (1) and to
+        provide an explicit mapping in <filename>pg_ident.conf</>.
        </para>
       </listitem>
      </varlistentry>
@@ -1083,7 +1101,15 @@ omicron         bryanh                  guest1
       <listitem>
        <para>
         Allows for mapping between system and database user names. See
-        <xref linkend="auth-username-maps"> for details.
+        <xref linkend="auth-username-maps"> for details.  For a SSPI/Kerberos
+        principal, such as <literal>usern...@example.com</literal> (or, less
+        commonly, <literal>username/hostba...@example.com</literal>), the
+        user name used for mapping is
+        <literal>usern...@example.com</literal> (or
+        <literal>username/hostba...@example.com</literal>, respectfully),
+        unless <literal>include_realm</literal> has been set to 0, in which case
+        <literal>username</literal> (or <literal>username/hostbased</literal>)
+        is what is seen as the system username when mapping.
        </para>
       </listitem>
      </varlistentry>
diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index a0f5396..c239385 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -1376,6 +1376,19 @@ parse_hba_auth_opt(char *name, char *val, HbaLine *hbaline, int line_num)
 	hbaline->ldapscope = LDAP_SCOPE_SUBTREE;
 #endif
 
+	/*
+	 * For GSS and SSPI, set the default value of include_realm to true.
+	 * Having include_realm set to false is dangerous in multi-realm
+	 * situations and is generally considered bad practice.  We keep the
+	 * capability around for backwards compatibility, but we might want to
+	 * remove it at some point in the future.  Users who still need to strip
+	 * the realm off would be better served by using an appropriate regex in
+	 * a pg_ident.conf mapping.
+	 */
+	if (hbaline->auth_method == uaGSS ||
+		hbaline->auth_method == uaSSPI)
+		hbaline->include_realm = true;
+
 	if (strcmp(name, "map") == 0)
 	{
 		if (hbaline->auth_method != uaIdent &&
-- 
1.9.1

From 6a0a7bb06dd461c4f2f11c55f30815bada6b2e10 Mon Sep 17 00:00:00 2001
From: Stephen Frost <sfr...@snowman.net>
Date: Mon, 27 Apr 2015 13:30:24 -0400
Subject: [PATCH] Recommend include_realm=1 in docs

As discussed, the default setting of include_realm=0 can be dangerous in
multi-realm environments because it is then impossible to differentiate
users with the same username but who are from two different realms.

Recommend include_realm=1 and note that the default setting may change
in a future version of PostgreSQL and therefore users may wish to
explicitly set include_realm to avoid issues while upgrading.
---
 doc/src/sgml/client-auth.sgml | 41 ++++++++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/doc/src/sgml/client-auth.sgml b/doc/src/sgml/client-auth.sgml
index d27dd49..9bb8a94 100644
--- a/doc/src/sgml/client-auth.sgml
+++ b/doc/src/sgml/client-auth.sgml
@@ -1000,7 +1000,12 @@ omicron         bryanh                  guest1
         If set to 1, the realm name from the authenticated user
         principal is included in the system user name that's passed through
         user name mapping (<xref linkend="auth-username-maps">). This is
-        useful for handling users from multiple realms.
+        the recommended configuration as, otherwise, it is impossible to
+        differentiate users with the same username who are from different
+        realms.  The default for this parameter is 0 (meaning to not include
+        the realm in the system user name) but may change to 1 in a future
+        version of <productname>PostgreSQL</productname>.  Users can set it
+        explicitly to avoid any issues when upgrading.
        </para>
       </listitem>
      </varlistentry>
@@ -1010,12 +1015,16 @@ omicron         bryanh                  guest1
       <listitem>
        <para>
         Allows for mapping between system and database user names. See
-        <xref linkend="auth-username-maps"> for details. For a Kerberos
-        principal <literal>username/hostba...@example.com</literal>, the
-        user name used for mapping is <literal>username/hostbased</literal>
-        if <literal>include_realm</literal> is disabled, and
-        <literal>username/hostba...@example.com</literal> if
-        <literal>include_realm</literal> is enabled.
+        <xref linkend="auth-username-maps"> for details.  For a GSSAPI/Kerberos
+        principal, such as <literal>usern...@example.com</literal> (or, less
+        commonly, <literal>username/hostba...@example.com</literal>), the
+        default user name used for mapping is
+        <literal>username</literal> (or <literal>username/hostbased</literal>,
+        respectfully), unless <literal>include_realm</literal> has been set to
+        1 (as recommended, see above), in which case
+        <literal>usern...@example.com</literal> (or
+        <literal>username/hostba...@example.com</literal>)
+        is what is seen as the system username when mapping.
        </para>
       </listitem>
      </varlistentry>
@@ -1073,7 +1082,12 @@ omicron         bryanh                  guest1
         If set to 1, the realm name from the authenticated user
         principal is included in the system user name that's passed through
         user name mapping (<xref linkend="auth-username-maps">). This is
-        useful for handling users from multiple realms.
+        the recommended configuration as, otherwise, it is impossible to
+        differentiate users with the same username who are from different
+        realms.  The default for this parameter is 0 (meaning to not include
+        the realm in the system user name) but may change to 1 in a future
+        version of <productname>PostgreSQL</productname>.  Users can set it
+        explicitly to avoid any issues when upgrading.
        </para>
       </listitem>
      </varlistentry>
@@ -1083,7 +1097,16 @@ omicron         bryanh                  guest1
       <listitem>
        <para>
         Allows for mapping between system and database user names. See
-        <xref linkend="auth-username-maps"> for details.
+        <xref linkend="auth-username-maps"> for details.  For a SSPI/Kerberos
+        principal, such as <literal>usern...@example.com</literal> (or, less
+        commonly, <literal>username/hostba...@example.com</literal>), the
+        default user name used for mapping is
+        <literal>username</literal> (or <literal>username/hostbased</literal>,
+        respectfully), unless <literal>include_realm</literal> has been set to
+        1 (as recommended, see above), in which case
+        <literal>usern...@example.com</literal> (or
+        <literal>username/hostba...@example.com</literal>)
+        is what is seen as the system username when mapping.
        </para>
       </listitem>
      </varlistentry>
-- 
1.9.1

Attachment: signature.asc
Description: Digital signature

Reply via email to