@@ -2276,40 +2276,46 @@ pg_dumpall -p 5432 | psql -d postgres -p 5433
2276
2276
</para>
2277
2277
2278
2278
<para>
2279
- In some cases, the server certificate might be signed by an
2280
- <quote>intermediate</> certificate authority, rather than one that is
2281
- directly trusted by clients. To use such a certificate, append the
2282
- certificate of the signing authority to the <filename>server.crt</> file,
2283
- then its parent authority's certificate, and so on up to a certificate
2284
- authority, <quote>root</> or <quote>intermediate</>, that is trusted by
2285
- clients, i.e. signed by a certificate in the clients'
2286
- <filename>root.crt</filename> files.
2279
+ The first certificate in <filename>server.crt</> must be the
2280
+ server's certificate because it must match the server's private key.
2281
+ The certificates of <quote>intermediate</> certificate authorities
2282
+ can also be appended to the file. Doing this avoids the necessity of
2283
+ storing intermediate certificates on clients, assuming the root and
2284
+ intermediate certificates were created with <literal>v3_ca</>
2285
+ extensions. This allows easier expiration of intermediate certificates.
2286
+ </para>
2287
+
2288
+ <para>
2289
+ It is not necessary to add the root certificate to
2290
+ <filename>server.crt</>. Instead, clients must have the root
2291
+ certificate of the server's certificate chain.
2287
2292
</para>
2288
2293
2289
2294
<sect2 id="ssl-client-certificates">
2290
2295
<title>Using Client Certificates</title>
2291
2296
2292
2297
<para>
2293
- To require the client to supply a trusted certificate, place
2294
- certificates of the certificate authorities (<acronym>CA</acronym>s)
2295
- you trust in the file <filename>root.crt</filename> in the data
2298
+ To require the client to supply a trusted certificate,
2299
+ place certificates of the root certificate authorities
2300
+ (<acronym>CA</>s) you trust in a file in the data
2296
2301
directory, set the parameter <xref linkend="guc-ssl-ca-file"> in
2297
- <filename>postgresql.conf</filename > to <literal>root.crt</literal>,
2298
- and add the authentication option <literal>clientcert=1</literal > to the
2299
- appropriate <literal>hostssl</> line(s) in <filename>pg_hba.conf</>.
2300
- A certificate will then be requested from the client during
2301
- SSL connection startup. (See <xref linkend="libpq-ssl"> for a
2302
- description of how to set up certificates on the client.) The server will
2302
+ <filename>postgresql.conf</> to the new file name, and add the
2303
+ authentication option <literal>clientcert=1</> to the appropriate
2304
+ <literal>hostssl</> line(s) in <filename>pg_hba.conf</>.
2305
+ A certificate will then be requested from the client during SSL
2306
+ connection startup. (See <xref linkend="libpq-ssl"> for a description
2307
+ of how to set up certificates on the client.) The server will
2303
2308
verify that the client's certificate is signed by one of the trusted
2304
2309
certificate authorities.
2305
2310
</para>
2306
2311
2307
2312
<para>
2308
- If intermediate <acronym>CA</>s appear in
2309
- <filename>root.crt</filename>, the file must also contain certificate
2310
- chains to their root <acronym>CA</>s. Certificate Revocation List
2311
- (CRL) entries
2312
- are also checked if the parameter <xref linkend="guc-ssl-crl-file"> is set.
2313
+ Intermediate certificates that chain up to existing root certificates
2314
+ can also appear in the file <filename>root.crt</filename> if
2315
+ you wish to avoid storing them on clients (assuming the root and
2316
+ intermediate certificates were created with <literal>v3_ca</>
2317
+ extensions). Certificate Revocation List (CRL) entries are also
2318
+ checked if the parameter <xref linkend="guc-ssl-crl-file"> is set.
2313
2319
<!-- If this URL changes replace it with a URL to www.archive.org. -->
2314
2320
(See <ulink
2315
2321
url="http://h71000.www7.hp.com/doc/83final/ba554_90007/ch04s02.html"></>
@@ -2325,14 +2331,6 @@ pg_dumpall -p 5432 | psql -d postgres -p 5433
2325
2331
it will not insist that a client certificate be presented.
2326
2332
</para>
2327
2333
2328
- <para>
2329
- Note that the server's <filename>root.crt</filename> lists the top-level
2330
- CAs that are considered trusted for signing client certificates.
2331
- In principle it need
2332
- not list the CA that signed the server's certificate, though in most cases
2333
- that CA would also be trusted for client certificates.
2334
- </para>
2335
-
2336
2334
<para>
2337
2335
If you are setting up client certificates, you may wish to use
2338
2336
the <literal>cert</> authentication method, so that the certificates
@@ -2405,31 +2403,18 @@ pg_dumpall -p 5432 | psql -d postgres -p 5433
2405
2403
</sect2>
2406
2404
2407
2405
<sect2 id="ssl-certificate-creation">
2408
- <title>Creating a Self-signed Certificate </title>
2406
+ <title>Creating Certificates </title>
2409
2407
2410
2408
<para>
2411
- To create a quick self-signed certificate for the server, use the
2412
- following <productname>OpenSSL</productname> command:
2413
- <programlisting>
2414
- openssl req -new -text -out server.req
2415
- </programlisting>
2416
- Fill out the information that <application>openssl</> asks for. Make sure
2417
- you enter the local host name as <quote>Common Name</>; the challenge
2418
- password can be left blank. The program will generate a key that is
2419
- passphrase protected; it will not accept a passphrase that is less
2420
- than four characters long. To remove the passphrase (as you must if
2421
- you want automatic start-up of the server), run the commands:
2422
- <programlisting>
2423
- openssl rsa -in privkey.pem -out server.key
2424
- rm privkey.pem
2425
- </programlisting>
2426
- Enter the old passphrase to unlock the existing key. Now do:
2409
+ To create a simple self-signed certificate for the server, valid for 365
2410
+ days, use the following <productname>OpenSSL</productname> command,
2411
+ replacing <replaceable>dbhost.yourdomain.com</> with the
2412
+ server's host name:
2427
2413
<programlisting>
2428
- openssl req -x509 -in server.req -text -key server.key -out server.crt
2414
+ openssl req -new -x509 -days 365 -nodes -text -out server.crt \
2415
+ -keyout server.key -subj "/CN=<replaceable>dbhost.yourdomain.com</>"
2429
2416
</programlisting>
2430
- to turn the certificate into a self-signed certificate and to copy
2431
- the key and certificate to where the server will look for them.
2432
- Finally do:
2417
+ Then do:
2433
2418
<programlisting>
2434
2419
chmod og-rwx server.key
2435
2420
</programlisting>
@@ -2440,14 +2425,86 @@ chmod og-rwx server.key
2440
2425
</para>
2441
2426
2442
2427
<para>
2443
- A self-signed certificate can be used for testing, but a certificate
2444
- signed by a certificate authority (<acronym>CA</>) (either one of the
2445
- global <acronym>CAs</> or a local one) should be used in production
2446
- so that clients can verify the server's identity. If all the clients
2447
- are local to the organization, using a local <acronym>CA</> is
2448
- recommended.
2428
+ While a self-signed certificate can be used for testing, a certificate
2429
+ signed by a certificate authority (<acronym>CA</>) (usually an
2430
+ enterprise-wide root <acronym>CA</>) should be used in production.
2449
2431
</para>
2450
2432
2433
+ <para>
2434
+ To create a server certificate whose identity can be validated
2435
+ by clients, first create a certificate signing request
2436
+ (<acronym>CSR</>) and a public/private key file:
2437
+ <programlisting>
2438
+ openssl req -new -nodes -text -out root.csr \
2439
+ -keyout root.key -subj "/CN=<replaceable>root.yourdomain.com</>"
2440
+ chmod og-rwx root.key
2441
+ </programlisting>
2442
+ Then, sign the request with the key to create a root certificate
2443
+ authority (using the default <productname>OpenSSL</>
2444
+ configuration file location on <productname>Linux</>):
2445
+ <programlisting>
2446
+ openssl x509 -req -in root.csr -text -days 3650 \
2447
+ -extfile /etc/ssl/openssl.cnf -extensions v3_ca \
2448
+ -signkey root.key -out root.crt
2449
+ </programlisting>
2450
+ Finally, create a server certificate signed by the new root certificate
2451
+ authority:
2452
+ <programlisting>
2453
+ openssl req -new -nodes -text -out server.csr \
2454
+ -keyout server.key -subj "/CN=<replaceable>dbhost.yourdomain.com</>"
2455
+ chmod og-rwx server.key
2456
+
2457
+ openssl x509 -req -in server.csr -text -days 365 \
2458
+ -CA root.crt -CAkey root.key -CAcreateserial \
2459
+ -out server.crt
2460
+ </programlisting>
2461
+ <filename>server.crt</> and <filename>server.key</>
2462
+ should be stored on the server, and <filename>root.crt</> should
2463
+ be stored on the client so the client can verify that the server's leaf
2464
+ certificate was signed by its trusted root certificate.
2465
+ <filename>root.key</> should be stored offline for use in
2466
+ creating future certificates.
2467
+ </para>
2468
+
2469
+ <para>
2470
+ It is also possible to create a chain of trust that includes
2471
+ intermediate certificates:
2472
+ <programlisting>
2473
+ # root
2474
+ openssl req -new -nodes -text -out root.csr \
2475
+ -keyout root.key -subj "/CN=<replaceable>root.yourdomain.com</>"
2476
+ chmod og-rwx root.key
2477
+ openssl x509 -req -in root.csr -text -days 3650 \
2478
+ -extfile /etc/ssl/openssl.cnf -extensions v3_ca \
2479
+ -signkey root.key -out root.crt
2480
+
2481
+ # intermediate
2482
+ openssl req -new -nodes -text -out intermediate.csr \
2483
+ -keyout intermediate.key -subj "/CN=<replaceable>intermediate.yourdomain.c
CEEF
om</>"
2484
+ chmod og-rwx intermediate.key
2485
+ openssl x509 -req -in intermediate.csr -text -days 1825 \
2486
+ -extfile /etc/ssl/openssl.cnf -extensions v3_ca \
2487
+ -CA root.crt -CAkey root.key -CAcreateserial \
2488
+ -out intermediate.crt
2489
+
2490
+ # leaf
2491
+ openssl req -new -nodes -text -out server.csr \
2492
+ -keyout server.key -subj "/CN=<replaceable>dbhost.yourdomain.com</>"
2493
+ chmod og-rwx server.key
2494
+ openssl x509 -req -in server.csr -text -days 365 \
2495
+ -CA intermediate.crt -CAkey intermediate.key -CAcreateserial \
2496
+ -out server.crt
2497
+ </programlisting>
2498
+ <filename>server.crt</> and
2499
+ <filename>intermediate.crt</> should be concatenated
2500
+ into a certificate file bundle and stored on the server.
2501
+ <filename>server.key</> should also be stored on the server.
2502
+ <filename>root.crt</> should be stored on the client so
2503
+ the client can verify that the server's leaf certificate was signed
2504
+ by a chain of certificates linked to its trusted root certificate.
2505
+ <filename>root.key</> and <filename>intermediate.key</>
2506
+ should be stored offline for use in creating future certificates.
2507
+ </para>
2451
2508
</sect2>
2452
2509
2453
2510
</sect1>
0 commit comments