client-auth.sgml
来自「PostgreSQL 8.1.4的源码 适用于Linux下的开源数据库系统」· SGML 代码 · 共 973 行 · 第 1/3 页
SGML
973 行
<replaceable>servicename</> can be set on the server side using the <xref linkend="guc-krb-srvname"> configuration parameter, and on the client side using the <literal>krbsrvname</> connection parameter. (See also <xref linkend="libpq-connect">.) The installation default can be changed from the default <literal>postgres</literal> at build time using <literal>./configure --with-krb-srvnam=whatever</>. In most environments, this parameter never needs to be changed. However, to support multiple <productname>PostgreSQL</> installations on the same host it is necessary. Some Kerberos implementations may also require a different service name, such as Microsoft Active Directory which requires the service name to be in uppercase (<literal>POSTGRES</literal>). </para> <para> <replaceable>hostname</> is the fully qualified host name of the server machine. The service principal's realm is the preferred realm of the server machine. </para> <para> Client principals must have their <productname>PostgreSQL</> database user name as their first component, for example <literal>pgusername/otherstuff@realm</>. At present the realm of the client is not checked by <productname>PostgreSQL</>; so if you have cross-realm authentication enabled, then any principal in any realm that can communicate with yours will be accepted. </para> <para> Make sure that your server keytab file is readable (and preferably only readable) by the <productname>PostgreSQL</productname> server account. (See also <xref linkend="postgres-user">.) The location of the key file is specified by the <xref linkend="guc-krb-server-keyfile"> configuration parameter. The default is <filename>/usr/local/pgsql/etc/krb5.keytab</> (or whichever directory was specified as <varname>sysconfdir</> at build time). </para> <para> The keytab file is generated by the Kerberos software; see the Kerberos documentation for details. The following example is for MIT-compatible Kerberos 5 implementations:<screen><prompt>kadmin% </><userinput>ank -randkey postgres/server.my.domain.org</><prompt>kadmin% </><userinput>ktadd -k krb5.keytab postgres/server.my.domain.org</></screen> </para> <para> When connecting to the database make sure you have a ticket for a principal matching the requested database user name. For example, for database user name <literal>fred</>, both principal <literal>fred@EXAMPLE.COM</> and <literal>fred/users.example.com@EXAMPLE.COM</> could be used to authenticate to the database server. </para> <para> If you use <ulink url="http://modauthkerb.sf.net"> <application>mod_auth_kerb</application></ulink> and <application>mod_perl</application> on your <productname>Apache</productname> web server, you can use <literal>AuthType KerberosV5SaveCredentials</literal> with a <application>mod_perl</application> script. This gives secure database access over the web, no extra passwords required. </para> </sect2> <sect2 id="auth-ident"> <title>Ident-based authentication</title> <indexterm> <primary>ident</primary> </indexterm> <para> The ident authentication method works by obtaining the client's operating system user name, then determining the allowed database user names using a map file that lists the permitted corresponding pairs of names. The determination of the client's user name is the security-critical point, and it works differently depending on the connection type. </para> <sect3> <title>Ident Authentication over TCP/IP</title> <para> The <quote>Identification Protocol</quote> is described in <citetitle>RFC 1413</citetitle>. Virtually every Unix-like operating system ships with an ident server that listens on TCP port 113 by default. The basic functionality of an ident server is to answer questions like <quote>What user initiated the connection that goes out of your port <replaceable>X</replaceable> and connects to my port <replaceable>Y</replaceable>?</quote>. Since <productname>PostgreSQL</> knows both <replaceable>X</> and <replaceable>Y</> when a physical connection is established, it can interrogate the ident server on the host of the connecting client and could theoretically determine the operating system user for any given connection this way. </para> <para> The drawback of this procedure is that it depends on the integrity of the client: if the client machine is untrusted or compromised an attacker could run just about any program on port 113 and return any user name he chooses. This authentication method is therefore only appropriate for closed networks where each client machine is under tight control and where the database and system administrators operate in close contact. In other words, you must trust the machine running the ident server. Heed the warning: <blockquote> <attribution>RFC 1413</attribution> <para> The Identification Protocol is not intended as an authorization or access control protocol. </para> </blockquote> </para> <para> Some ident servers have a nonstandard option that causes the returned user name to be encrypted, using a key that only the originating machine's administrator knows. This option <emphasis>must not</> be used when using the ident server with <productname>PostgreSQL</>, since <productname>PostgreSQL</> does not have any way to decrypt the returned string to determine the actual user name. </para> </sect3> <sect3> <title>Ident Authentication over Local Sockets</title> <para> On systems supporting <symbol>SO_PEERCRED</symbol> requests for Unix-domain sockets (currently <systemitem class="osname">Linux</>, <systemitem class="osname">FreeBSD</>, <systemitem class="osname">NetBSD</>, <systemitem class=osname>OpenBSD</>, and <systemitem class="osname">BSD/OS</>), ident authentication can also be applied to local connections. In this case, no security risk is added by using ident authentication; indeed it is a preferable choice for local connections on such systems. </para> <para> On systems without <symbol>SO_PEERCRED</> requests, ident authentication is only available for TCP/IP connections. As a work-around, it is possible to specify the <systemitem class="systemname">localhost</> address <systemitem class="systemname">127.0.0.1</> and make connections to this address. This method is trustworthy to the extent that you trust the local ident server. </para> </sect3> <sect3 id="auth-ident-maps"> <title>Ident Maps</title> <para> When using ident-based authentication, after having determined the name of the operating system user that initiated the connection, <productname>PostgreSQL</productname> checks whether that user is allowed to connect as the database user he is requesting to connect as. This is controlled by the ident map argument that follows the <literal>ident</> key word in the <filename>pg_hba.conf</filename> file. There is a predefined ident map <literal>sameuser</literal>, which allows any operating system user to connect as the database user of the same name (if the latter exists). Other maps must be created manually. </para> <para> Ident maps other than <literal>sameuser</literal> are defined in the ident map file, which by default is named <filename>pg_ident.conf</><indexterm><primary>pg_ident.conf</primary></indexterm> and is stored in the cluster's data directory. (It is possible to place the map file elsewhere, however; see the <xref linkend="guc-ident-file"> configuration parameter.) The ident map file contains lines of the general form:<synopsis><replaceable>map-name</> <replaceable>ident-username</> <replaceable>database-username</></synopsis> Comments and whitespace are handled in the same way as in <filename>pg_hba.conf</>. The <replaceable>map-name</> is an arbitrary name that will be used to refer to this mapping in <filename>pg_hba.conf</filename>. The other two fields specify which operating system user is allowed to connect as which database user. The same <replaceable>map-name</> can be used repeatedly to specify more user-mappings within a single map. There is no restriction regarding how many database users a given operating system user may correspond to, nor vice versa. </para> <para> The <filename>pg_ident.conf</filename> file is read on start-up and when the main server process (<command>postmaster</>) receives a <systemitem>SIGHUP</systemitem><indexterm><primary>SIGHUP</primary></indexterm> signal. If you edit the file on an active system, you will need to signal the <command>postmaster</> (using <literal>pg_ctl reload</> or <literal>kill -HUP</>) to make it re-read the file. </para> <para> A <filename>pg_ident.conf</filename> file that could be used in conjunction with the <filename>pg_hba.conf</> file in <xref linkend="example-pg-hba.conf"> is shown in <xref linkend="example-pg-ident.conf">. In this example setup, anyone logged in to a machine on the 192.168 network that does not have the Unix user name <literal>bryanh</>, <literal>ann</>, or <literal>robert</> would not be granted access. Unix user <literal>robert</> would only be allowed access when he tries to connect as <productname>PostgreSQL</> user <literal>bob</>, not as <literal>robert</> or anyone else. <literal>ann</> would only be allowed to connect as <literal>ann</>. User <literal>bryanh</> would be allowed to connect as either <literal>bryanh</> himself or as <literal>guest1</>. </para> <example id="example-pg-ident.conf"> <title>An example <filename>pg_ident.conf</> file</title><programlisting># MAPNAME IDENT-USERNAME PG-USERNAMEomicron bryanh bryanhomicron ann ann# bob has user name robert on these machinesomicron robert bob# bryanh can also connect as guest1omicron bryanh guest1</programlisting> </example> </sect3> </sect2> <sect2 id="auth-pam"> <title>PAM authentication</title> <indexterm zone="auth-pam"> <primary>PAM</primary> </indexterm> <para> This authentication method operates similarly to <literal>password</literal> except that it uses PAM (Pluggable Authentication Modules) as the authentication mechanism. The default PAM service name is <literal>postgresql</literal>. You can optionally supply your own service name after the <literal>pam</> key word in the file <filename>pg_hba.conf</filename>. PAM is used only to validate user name/password pairs. Therefore the user must already exist in the database before PAM can be used for authentication. For more information about PAM, please read the <ulink url="http://www.kernel.org/pub/linux/libs/pam/"> <productname>Linux-PAM</> Page</ulink> and the <ulink url="http://www.sun.com/software/solaris/pam/"> <systemitem class="osname">Solaris</> PAM Page</ulink>. </para> </sect2> </sect1> <sect1 id="client-authentication-problems"> <title>Authentication problems</title> <para> Genuine authentication failures and related problems generally manifest themselves through error messages like the following. </para> <para><programlisting>FATAL: no pg_hba.conf entry for host "123.123.123.123", user "andym", database "testdb"</programlisting> This is what you are most likely to get if you succeed in contacting the server, but it does not want to talk to you. As the message suggests, the server refused the connection request because it found no matching entry in its <filename>pg_hba.conf</filename> configuration file. </para> <para><programlisting>FATAL: Password authentication failed for user "andym"</programlisting> Messages like this indicate that you contacted the server, and it is willing to talk to you, but not until you pass the authorization method specified in the <filename>pg_hba.conf</filename> file. Check the password you are providing, or check your Kerberos or ident software if the complaint mentions one of those authentication types. </para> <para><programlisting>FATAL: user "andym" does not exist</programlisting> The indicated user name was not found. </para> <para><programlisting>FATAL: database "testdb" does not exist</programlisting> The database you are trying to connect to does not exist. Note that if you do not specify a database name, it defaults to the database user name, which may or may not be the right thing. </para> <tip> <para> The server log may contain more information about an authentication failure than is reported to the client. If you are confused about the reason for a failure, check the log. </para> </tip> </sect1> </chapter>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?