Skip to content

Commit 9a08841

Browse files
committed
Change default for include_realm to 1
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 '1', 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 set to 1 and adding a mapping in pg_ident.conf, but alternatively by explicitly setting include_realm=0 prior to upgrading). 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.
1 parent f91feba commit 9a08841

File tree

2 files changed

+63
-24
lines changed

2 files changed

+63
-24
lines changed

doc/src/sgml/client-auth.sgml

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -947,15 +947,24 @@ omicron bryanh guest1
947947
</para>
948948

949949
<para>
950-
Client principals must have their <productname>PostgreSQL</> database user
951-
name as their first component, for example
952-
<literal>pgusername@realm</>. Alternatively, you can use a user name
953-
mapping to map from the first component of the principal name to the
954-
database user name. By default, the realm of the client is
955-
not checked by <productname>PostgreSQL</>. If you have cross-realm
956-
authentication enabled and need to verify the realm, use the
957-
<literal>krb_realm</> parameter, or enable <literal>include_realm</>
958-
and use user name mapping to check the realm.
950+
Client principals can be mapped to different <productname>PostgreSQL</>
951+
database user names with <filename>pg_ident.conf</>. For example,
952+
<literal>pgusername@realm</> could be mapped to just <literal>pgusername</>.
953+
Alternatively, you can use the full <literal>username@realm</> principal as
954+
the role name in <productname>PostgreSQL</> without any mapping.
955+
</para>
956+
957+
<para>
958+
<productname>PostgreSQL</> also supports a parameter to strip the realm from
959+
the principal. This method is supported for backwards compatibility and is
960+
strongly discouraged as it is then impossible to distinguish different users
961+
with the same username but coming from different realms. To enable this,
962+
set <literal>include_realm</> to 0. For simple single-realm
963+
installations, <literal>include_realm</> combined with the
964+
<literal>krb_realm</> parameter (which checks that the realm provided
965+
matches exactly what is in the krb_realm parameter) would be a secure but
966+
less capable option compared to specifying an explicit mapping in
967+
<filename>pg_ident.conf</>.
959968
</para>
960969

961970
<para>
@@ -997,10 +1006,13 @@ omicron bryanh guest1
9971006
<term><literal>include_realm</literal></term>
9981007
<listitem>
9991008
<para>
1000-
If set to 1, the realm name from the authenticated user
1001-
principal is included in the system user name that's passed through
1002-
user name mapping (<xref linkend="auth-username-maps">). This is
1003-
useful for handling users from multiple realms.
1009+
If set to 0, the realm name from the authenticated user principal is
1010+
stripped off before being passed through the user name mapping
1011+
(<xref linkend="auth-username-maps">). This is discouraged and is
1012+
primairly available for backwards compatibility as it is not secure
1013+
in multi-realm environments unless krb_realm is also used. Users
1014+
are recommended to leave include_realm set to the default (1) and to
1015+
provide an explicit mapping in <filename>pg_ident.conf</>.
10041016
</para>
10051017
</listitem>
10061018
</varlistentry>
@@ -1010,12 +1022,15 @@ omicron bryanh guest1
10101022
<listitem>
10111023
<para>
10121024
Allows for mapping between system and database user names. See
1013-
<xref linkend="auth-username-maps"> for details. For a Kerberos
1014-
principal <literal>username/hostbased@EXAMPLE.COM</literal>, the
1015-
user name used for mapping is <literal>username/hostbased</literal>
1016-
if <literal>include_realm</literal> is disabled, and
1017-
<literal>username/hostbased@EXAMPLE.COM</literal> if
1018-
<literal>include_realm</literal> is enabled.
1025+
<xref linkend="auth-username-maps"> for details. For a GSSAPI/Kerberos
1026+
principal, such as <literal>username@EXAMPLE.COM</literal> (or, less
1027+
commonly, <literal>username/hostbased@EXAMPLE.COM</literal>), the
1028+
user name used for mapping is
1029+
<literal>username@EXAMPLE.COM</literal> (or
1030+
<literal>username/hostbased@EXAMPLE.COM</literal>, respectfully),
1031+
unless <literal>include_realm</literal> has been set to 0, in which case
1032+
<literal>username</literal> (or <literal>username/hostbased</literal>)
1033+
is what is seen as the system username when mapping.
10191034
</para>
10201035
</listitem>
10211036
</varlistentry>
@@ -1070,10 +1085,13 @@ omicron bryanh guest1
10701085
<term><literal>include_realm</literal></term>
10711086
<listitem>
10721087
<para>
1073-
If set to 1, the realm name from the authenticated user
1074-
principal is included in the system user name that's passed through
1075-
user name mapping (<xref linkend="auth-username-maps">). This is
1076-
useful for handling users from multiple realms.
1088+
If set to 0, the realm name from the authenticated user principal is
1089+
stripped off before being passed through the user name mapping
1090+
(<xref linkend="auth-username-maps">). This is discouraged and is
1091+
primairly available for backwards compatibility as it is not secure
1092+
in multi-realm environments unless krb_realm is also used. Users
1093+
are recommended to leave include_realm set to the default (1) and to
1094+
provide an explicit mapping in <filename>pg_ident.conf</>.
10771095
</para>
10781096
</listitem>
10791097
</varlistentry>
@@ -1083,7 +1101,15 @@ omicron bryanh guest1
10831101
<listitem>
10841102
<para>
10851103
Allows for mapping between system and database user names. See
1086-
<xref linkend="auth-username-maps"> for details.
1104+
<xref linkend="auth-username-maps"> for details. For a SSPI/Kerberos
1105+
principal, such as <literal>username@EXAMPLE.COM</literal> (or, less
1106+
commonly, <literal>username/hostbased@EXAMPLE.COM</literal>), the
1107+
user name used for mapping is
1108+
<literal>username@EXAMPLE.COM</literal> (or
1109+
<literal>username/hostbased@EXAMPLE.COM</literal>, respectfully),
1110+
unless <literal>include_realm</literal> has been set to 0, in which case
1111+
<literal>username</literal> (or <literal>username/hostbased</literal>)
1112+
is what is seen as the system username when mapping.
10871113
</para>
10881114
</listitem>
10891115
</varlistentry>

src/backend/libpq/hba.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,19 @@ parse_hba_auth_opt(char *name, char *val, HbaLine *hbaline, int line_num)
13761376
hbaline->ldapscope = LDAP_SCOPE_SUBTREE;
13771377
#endif
13781378

1379+
/*
1380+
* For GSS and SSPI, set the default value of include_realm to true.
1381+
* Having include_realm set to false is dangerous in multi-realm
1382+
* situations and is generally considered bad practice. We keep the
1383+
* capability around for backwards compatibility, but we might want to
1384+
* remove it at some point in the future. Users who still need to strip
1385+
* the realm off would be better served by using an appropriate regex in
1386+
* a pg_ident.conf mapping.
1387+
*/
1388+
if (hbaline->auth_method == uaGSS ||
1389+
hbaline->auth_method == uaSSPI)
1390+
hbaline->include_realm = true;
1391+
13791392
if (strcmp(name, "map") == 0)
13801393
{
13811394
if (hbaline->auth_method != uaIdent &&

0 commit comments

Comments
 (0)