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