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