Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bad7c8f

Browse files
committed
Merge branch 'PGPRO10' into PGPROEE10
2 parents 1d8a45b + cd58d36 commit bad7c8f

File tree

4 files changed

+163
-77
lines changed

4 files changed

+163
-77
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,8 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
10091009
</para>
10101010

10111011
<para>
1012-
A comma-separated list of <literal>hostaddrs</> is also accepted, in
1013-
which case each host in the list is tried in order. See
1012+
A comma-separated list of <literal>hostaddr</literal> values is also
1013+
accepted, in which case each host in the list is tried in order. See
10141014
<xref linkend="libpq-multiple-hosts"> for details.
10151015
</para>
10161016
<para>
@@ -7599,17 +7599,37 @@ ldap://ldap.acme.com/cn=dbserver,cn=hosts?pgconnectinfo?base?(objectclass=*)
75997599
the server certificate. This means that it is possible to spoof the server
76007600
identity (for example by modifying a DNS record or by taking over the server
76017601
IP address) without the client knowing. In order to prevent spoofing,
7602-
<acronym>SSL</> certificate verification must be used.
7602+
the client must be able to verify the server's identity via a chain of
7603+
trust. A chain of trust is established by placing a root (self-signed)
7604+
certificate authority (<acronym>CA</>) certificate on one
7605+
computer and a leaf certificate <emphasis>signed</> by the
7606+
root certificate on another computer. It is also possible to use an
7607+
<quote>intermediate</> certificate which is signed by the root
7608+
certificate and signs leaf certificates.
76037609
</para>
76047610

76057611
<para>
7612+
To allow the client to verify the identity of the server, place a root
7613+
certificate on the client and a leaf certificate signed by the root
7614+
certificate on the server. To allow the server to verify the identity
7615+
of the client, place a root certificate on the server and a leaf and
7616+
optional intermediate certificates signed by the root certificate on
7617+
the client. Intermediate certificates (usually stored with the leaf
7618+
certificate) can also be used to link the leaf certificate to the
7619+
root certificate.
7620+
</para>
7621+
7622+
<para>
7623+
Once a chain of trust has been established, there are two ways for
7624+
the client to validate the leaf certificate sent by the server.
76067625
If the parameter <literal>sslmode</> is set to <literal>verify-ca</>,
76077626
libpq will verify that the server is trustworthy by checking the
7608-
certificate chain up to a trusted certificate authority
7609-
(<acronym>CA</>). If <literal>sslmode</> is set to <literal>verify-full</>,
7610-
libpq will <emphasis>also</> verify that the server host name matches its
7611-
certificate. The SSL connection will fail if the server certificate cannot
7612-
be verified. <literal>verify-full</> is recommended in most
7627+
certificate chain up to the root certificate stored on the client.
7628+
If <literal>sslmode</> is set to <literal>verify-full</>,
7629+
libpq will <emphasis>also</> verify that the server host
7630+
name matches the name stored in the server certificate. The
7631+
SSL connection will fail if the server certificate cannot be
7632+
verified. <literal>verify-full</> is recommended in most
76137633
security-sensitive environments.
76147634
</para>
76157635

@@ -7626,13 +7646,13 @@ ldap://ldap.acme.com/cn=dbserver,cn=hosts?pgconnectinfo?base?(objectclass=*)
76267646
</para>
76277647

76287648
<para>
7629-
To allow server certificate verification, the certificate(s) of one or more
7630-
trusted <acronym>CA</>s must be
7631-
placed in the file <filename>~/.postgresql/root.crt</> in the user's home
7632-
directory. If intermediate <acronym>CA</>s appear in
7633-
<filename>root.crt</filename>, the file must also contain certificate
7634-
chains to their root <acronym>CA</>s. (On Microsoft Windows the file is named
7635-
<filename>%APPDATA%\postgresql\root.crt</filename>.)
7649+
To allow server certificate verification, one or more root certificates
7650+
must be placed in the file <filename>~/.postgresql/root.crt</>
7651+
in the user's home directory. (On Microsoft Windows the file is named
7652+
<filename>%APPDATA%\postgresql\root.crt</>.) Intermediate
7653+
certificates should also be added to the file if they are needed to link
7654+
the certificate chain sent by the server to the root certificates
7655+
stored on the client.
76367656
</para>
76377657

76387658
<para>
@@ -7666,11 +7686,12 @@ ldap://ldap.acme.com/cn=dbserver,cn=hosts?pgconnectinfo?base?(objectclass=*)
76667686
<title>Client Certificates</title>
76677687

76687688
<para>
7669-
If the server requests a trusted client certificate,
7670-
<application>libpq</application> will send the certificate stored in
7689+
If the server attempts to verify the identity of the
7690+
client by requesting the client's leaf certificate,
7691+
<application>libpq</> will send the certificates stored in
76717692
file <filename>~/.postgresql/postgresql.crt</> in the user's home
7672-
directory. The certificate must be signed by one of the certificate
7673-
authorities (<acronym>CA</acronym>) trusted by the server. A matching
7693+
directory. The certificates must chain to the root certificate trusted
7694+
by the server. A matching
76747695
private key file <filename>~/.postgresql/postgresql.key</> must also
76757696
be present. The private
76767697
key file must not allow any access to world or group; achieve this by the
@@ -7685,23 +7706,17 @@ ldap://ldap.acme.com/cn=dbserver,cn=hosts?pgconnectinfo?base?(objectclass=*)
76857706
</para>
76867707

76877708
<para>
7688-
In some cases, the client certificate might be signed by an
7689-
<quote>intermediate</> certificate authority, rather than one that is
7690-
directly trusted by the server. To use such a certificate, append the
7691-
certificate of the signing authority to the <filename>postgresql.crt</>
7692-
file, then its parent authority's certificate, and so on up to a certificate
7693-
authority, <quote>root</> or <quote>intermediate</>, that is trusted by
7694-
the server, i.e. signed by a certificate in the server's
7695-
<filename>root.crt</filename> file.
7709+
The first certificate in <filename>postgresql.crt</> must be the
7710+
client's certificate because it must match the client's private key.
7711+
<quote>Intermediate</> certificates can be optionally appended
7712+
to the file &mdash; doing so avoids requiring storage of intermediate
7713+
certificates on the server's <filename>root.crt</filename> file.
76967714
</para>
76977715

76987716
<para>
7699-
Note that the client's <filename>~/.postgresql/root.crt</> lists the top-level CAs
7700-
that are considered trusted for signing server certificates. In principle it need
7701-
not list the CA that signed the client's certificate, though in most cases
7702-
that CA would also be trusted for server certificates.
7717+
For instructions on creating certificates, see <xref
7718+
linkend="ssl-certificate-creation">.
77037719
</para>
7704-
77057720
</sect2>
77067721

77077722
<sect2 id="libpq-ssl-protection">

doc/src/sgml/runtime.sgml

Lines changed: 111 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,40 +2254,46 @@ pg_dumpall -p 5432 | psql -d postgres -p 5433
22542254
</para>
22552255

22562256
<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.
22652270
</para>
22662271

22672272
<sect2 id="ssl-client-certificates">
22682273
<title>Using Client Certificates</title>
22692274

22702275
<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
22742279
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
22812286
verify that the client's certificate is signed by one of the trusted
22822287
certificate authorities.
22832288
</para>
22842289

22852290
<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.
22912297
<!-- If this URL changes replace it with a URL to www.archive.org. -->
22922298
(See <ulink
22932299
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
23032309
it will not insist that a client certificate be presented.
23042310
</para>
23052311

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-
23142312
<para>
23152313
If you are setting up client certificates, you may wish to use
23162314
the <literal>cert</> authentication method, so that the certificates
@@ -2392,15 +2390,16 @@ pg_dumpall -p 5432 | psql -d postgres -p 5433
23922390
</sect2>
23932391

23942392
<sect2 id="ssl-certificate-creation">
2395-
<title>Creating a Self-signed Certificate</title>
2393+
<title>Creating Certificates</title>
23962394

23972395
<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
23992397
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:
24012400
<programlisting>
24022401
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</>"
24042403
</programlisting>
24052404
Then do:
24062405
<programlisting>
@@ -2413,14 +2412,86 @@ chmod og-rwx server.key
24132412
</para>
24142413

24152414
<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.
24222418
</para>
24232419

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>
24242495
</sect2>
24252496

24262497
</sect1>

src/backend/commands/tablecmds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static void MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel
304304
static void StoreCatalogInheritance(Oid relationId, List *supers,
305305
bool child_is_partition);
306306
static void StoreCatalogInheritance1(Oid relationId, Oid parentOid,
307-
int16 seqNumber, Relation inhRelation,
307+
int32 seqNumber, Relation inhRelation,
308308
bool child_is_partition);
309309
static int findAttrByName(const char *attributeName, List *schema);
310310
static void AlterIndexNamespaces(Relation classRel, Relation rel,
@@ -2342,7 +2342,7 @@ StoreCatalogInheritance(Oid relationId, List *supers,
23422342
bool child_is_partition)
23432343
{
23442344
Relation relation;
2345-
int16 seqNumber;
2345+
int32 seqNumber;
23462346
ListCell *entry;
23472347

23482348
/*
@@ -2383,7 +2383,7 @@ StoreCatalogInheritance(Oid relationId, List *supers,
23832383
*/
23842384
static void
23852385
StoreCatalogInheritance1(Oid relationId, Oid parentOid,
2386-
int16 seqNumber, Relation inhRelation,
2386+
int32 seqNumber, Relation inhRelation,
23872387
bool child_is_partition)
23882388
{
23892389
TupleDesc desc = RelationGetDescr(inhRelation);
@@ -2398,7 +2398,7 @@ StoreCatalogInheritance1(Oid relationId, Oid parentOid,
23982398
*/
23992399
values[Anum_pg_inherits_inhrelid - 1] = ObjectIdGetDatum(relationId);
24002400
values[Anum_pg_inherits_inhparent - 1] = ObjectIdGetDatum(parentOid);
2401-
values[Anum_pg_inherits_inhseqno - 1] = Int16GetDatum(seqNumber);
2401+
values[Anum_pg_inherits_inhseqno - 1] = Int32GetDatum(seqNumber);
24022402

24032403
memset(nulls, 0, sizeof(nulls));
24042404

src/interfaces/libpq/fe-connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ connectOptions2(PGconn *conn)
10611061
{
10621062
conn->status = CONNECTION_BAD;
10631063
printfPQExpBuffer(&conn->errorMessage,
1064-
libpq_gettext("could not match %d host names to %d hostaddrs\n"),
1064+
libpq_gettext("could not match %d host names to %d hostaddr values\n"),
10651065
count_comma_separated_elems(conn->pghost), conn->nconnhost);
10661066
return false;
10671067
}

0 commit comments

Comments
 (0)