@@ -2247,40 +2247,46 @@ pg_dumpall -p 5432 | psql -d postgres -p 5433
22472247 </para>
22482248
22492249 <para>
2250- In some cases, the server certificate might be signed by an
2251- <quote>intermediate</quote> certificate authority, rather than one that is
2252- directly trusted by clients. To use such a certificate, append the
2253- certificate of the signing authority to the <filename>server.crt</filename> file,
2254- then its parent authority's certificate, and so on up to a certificate
2255- authority, <quote>root</quote> or <quote>intermediate</quote>, that is trusted by
2256- clients, i.e. signed by a certificate in the clients'
2257- <filename>root.crt</filename> files.
2250+ The first certificate in <filename>server.crt</filename> must be the
2251+ server's certificate because it must match the server's private key.
2252+ The certificates of <quote>intermediate</quote> certificate authorities
2253+ can also be appended to the file. Doing this avoids the necessity of
2254+ storing intermediate certificates on clients, assuming the root and
2255+ intermediate certificates were created with <literal>v3_ca</literal>
2256+ extensions. This allows easier expiration of intermediate certificates.
2257+ </para>
2258+
2259+ <para>
2260+ It is not necessary to add the root certificate to
2261+ <filename>server.crt</filename>. Instead, clients must have the root
2262+ certificate of the server's certificate chain.
22582263 </para>
22592264
22602265 <sect2 id="ssl-client-certificates">
22612266 <title>Using Client Certificates</title>
22622267
22632268 <para>
2264- To require the client to supply a trusted certificate, place
2265- certificates of the certificate authorities (<acronym>CA</acronym>s)
2266- you trust in a file named <filename>root.crt</filename> in the data
2269+ To require the client to supply a trusted certificate,
2270+ place certificates of the root certificate authorities
2271+ (<acronym>CA</acronym>s) you trust in a file in the data
22672272 directory, set the parameter <xref linkend="guc-ssl-ca-file"/> in
2268- <filename>postgresql.conf</filename> to <literal>root.crt</literal>,
2269- and add the authentication option <literal>clientcert=1</literal> to the
2270- appropriate <literal>hostssl</literal> line(s) in <filename>pg_hba.conf</filename>.
2271- A certificate will then be requested from the client during
2272- SSL connection startup. (See <xref linkend="libpq-ssl"/> for a
2273- description of how to set up certificates on the client.) The server will
2273+ <filename>postgresql.conf</filename> to the new file name, and add the
2274+ authentication option <literal>clientcert=1</literal> to the appropriate
2275+ <literal>hostssl</literal> line(s) in <filename>pg_hba.conf</filename>.
2276+ A certificate will then be requested from the client during SSL
2277+ connection startup. (See <xref linkend="libpq-ssl"/> for a description
2278+ of how to set up certificates on the client.) The server will
22742279 verify that the client's certificate is signed by one of the trusted
22752280 certificate authorities.
22762281 </para>
22772282
22782283 <para>
2279- If intermediate <acronym>CA</acronym>s appear in
2280- <filename>root.crt</filename>, the file must also contain certificate
2281- chains to their root <acronym>CA</acronym>s. Certificate Revocation List
2282- (CRL) entries
2283- are also checked if the parameter <xref linkend="guc-ssl-crl-file"/> is set.
2284+ Intermediate certificates that chain up to existing root certificates
2285+ can also appear in the <xref linkend="guc-ssl-ca-file"/> file if
2286+ you wish to avoid storing them on clients (assuming the root and
2287+ intermediate certificates were created with <literal>v3_ca</literal>
2288+ extensions). Certificate Revocation List (CRL) entries are also
2289+ checked if the parameter <xref linkend="guc-ssl-crl-file"/> is set.
22842290 <!-- If this URL changes replace it with a URL to www.archive.org. -->
22852291 (See <ulink
22862292 url="http://h71000.www7.hp.com/doc/83final/ba554_90007/ch04s02.html"></ulink>
@@ -2296,14 +2302,6 @@ pg_dumpall -p 5432 | psql -d postgres -p 5433
22962302 it will not insist that a client certificate be presented.
22972303 </para>
22982304
2299- <para>
2300- Note that the server's <filename>root.crt</filename> lists the top-level
2301- CAs that are considered trusted for signing client certificates.
2302- In principle it need
2303- not list the CA that signed the server's certificate, though in most cases
2304- that CA would also be trusted for client certificates.
2305- </para>
2306-
23072305 <para>
23082306 If you are setting up client certificates, you may wish to use
23092307 the <literal>cert</literal> authentication method, so that the certificates
@@ -2385,15 +2383,16 @@ pg_dumpall -p 5432 | psql -d postgres -p 5433
23852383 </sect2>
23862384
23872385 <sect2 id="ssl-certificate-creation">
2388- <title>Creating a Self-signed Certificate </title>
2386+ <title>Creating Certificates </title>
23892387
23902388 <para>
2391- To create a quick self-signed certificate for the server, valid for 365
2389+ To create a simple self-signed certificate for the server, valid for 365
23922390 days, use the following <productname>OpenSSL</productname> command,
2393- replacing <replaceable>yourdomain.com</replaceable> with the server's host name:
2391+ replacing <replaceable>dbhost.yourdomain.com</replaceable> with the
2392+ server's host name:
23942393<programlisting>
23952394openssl req -new -x509 -days 365 -nodes -text -out server.crt \
2396- -keyout server.key -subj "/CN=<replaceable>yourdomain.com</replaceable>"
2395+ -keyout server.key -subj "/CN=<replaceable>dbhost. yourdomain.com</replaceable>"
23972396</programlisting>
23982397 Then do:
23992398<programlisting>
@@ -2406,14 +2405,86 @@ chmod og-rwx server.key
24062405 </para>
24072406
24082407 <para>
2409- A self-signed certificate can be used for testing, but a certificate
2410- signed by a certificate authority (<acronym>CA</acronym>) (either one of the
2411- global <acronym>CAs</acronym> or a local one) should be used in production
2412- so that clients can verify the server's identity. If all the clients
2413- are local to the organization, using a local <acronym>CA</acronym> is
2414- recommended.
2408+ While a self-signed certificate can be used for testing, a certificate
2409+ signed by a certificate authority (<acronym>CA</acronym>) (usually an
2410+ enterprise-wide root <acronym>CA</acronym>) should be used in production.
24152411 </para>
24162412
2413+ <para>
2414+ To create a server certificate whose identity can be validated
2415+ by clients, first create a certificate signing request
2416+ (<acronym>CSR</acronym>) and a public/private key file:
2417+ <programlisting>
2418+ openssl req -new -nodes -text -out root.csr \
2419+ -keyout root.key -subj "/CN=<replaceable>root.yourdomain.com</replaceable>"
2420+ chmod og-rwx root.key
2421+ </programlisting>
2422+ Then, sign the request with the key to create a root certificate
2423+ authority (using the default <productname>OpenSSL</productname>
2424+ configuration file location on <productname>Linux</productname>):
2425+ <programlisting>
2426+ openssl x509 -req -in root.csr -text -days 3650 \
2427+ -extfile /etc/ssl/openssl.cnf -extensions v3_ca \
2428+ -signkey root.key -out root.crt
2429+ </programlisting>
2430+ Finally, create a server certificate signed by the new root certificate
2431+ authority:
2432+ <programlisting>
2433+ openssl req -new -nodes -text -out server.csr \
2434+ -keyout server.key -subj "/CN=<replaceable>dbhost.yourdomain.com</replaceable>"
2435+ chmod og-rwx server.key
2436+
2437+ openssl x509 -req -in server.csr -text -days 365 \
2438+ -CA root.crt -CAkey root.key -CAcreateserial \
2439+ -out server.crt
2440+ </programlisting>
2441+ <filename>server.crt</filename> and <filename>server.key</filename>
2442+ should be stored on the server, and <filename>root.crt</filename> should
2443+ be stored on the client so the client can verify that the server's leaf
2444+ certificate was signed by its trusted root certificate.
2445+ <filename>root.key</filename> should be stored offline for use in
2446+ creating future certificates.
2447+ </para>
2448+
2449+ <para>
2450+ It is also possible to create a chain of trust that includes
2451+ intermediate certificates:
2452+ <programlisting>
2453+ # root
2454+ openssl req -new -nodes -text -out root.csr \
2455+ -keyout root.key -subj "/CN=<replaceable>root.yourdomain.com</replaceable>"
2456+ chmod og-rwx root.key
2457+ openssl x509 -req -in root.csr -text -days 3650 \
2458+ -extfile /etc/ssl/openssl.cnf -extensions v3_ca \
2459+ -signkey root.key -out root.crt
2460+
2461+ # intermediate
2462+ openssl req -new -nodes -text -out intermediate.csr \
2463+ -keyout intermediate.key -subj "/CN=<replaceable>intermediate.yourdomain.com</replaceable>"
2464+ chmod og-rwx intermediate.key
2465+ openssl x509 -req -in intermediate.csr -text -days 1825 \
2466+ -extfile /etc/ssl/openssl.cnf -extensions v3_ca \
2467+ -CA root.crt -CAkey root.key -CAcreateserial \
2468+ -out intermediate.crt
2469+
2470+ # leaf
2471+ openssl req -new -nodes -text -out server.csr \
2472+ -keyout server.key -subj "/CN=<replaceable>dbhost.yourdomain.com</replaceable>"
2473+ chmod og-rwx server.key
2474+ openssl x509 -req -in server.csr -text -days 365 \
2475+ -CA intermediate.crt -CAkey intermediate.key -CAcreateserial \
2476+ -out server.crt
2477+ </programlisting>
2478+ <filename>server.crt</filename> and
2479+ <filename>intermediate.crt</filename> should be concatenated
2480+ into a certificate file bundle and stored on the server.
2481+ <filename>server.key</filename> should also be stored on the server.
2482+ <filename>root.crt</filename> should be stored on the client so
2483+ the client can verify that the server's leaf certificate was signed
2484+ by a chain of certificates linked to its trusted root certificate.
2485+ <filename>root.key</filename> and <filename>intermediate.key</filename>
2486+ should be stored offline for use in creating future certificates.
2487+ </para>
24172488 </sect2>
24182489
24192490 </sect1>
0 commit comments