Set SNI for SSL connections
This allows an SNI-aware proxy to route connections. Patch adds a new connection option (`sslsni`) to opt out of the SNI, to have the same behavior as `libpq` does. See more in `sslsni` sections at <https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS>.
This commit is contained in:
committed by
Jack Christensen
parent
faabb0696f
commit
067771b2e6
@@ -297,6 +297,7 @@ func ParseConfigWithOptions(connString string, options ParseConfigOptions) (*Con
|
|||||||
"sslcert": {},
|
"sslcert": {},
|
||||||
"sslrootcert": {},
|
"sslrootcert": {},
|
||||||
"sslpassword": {},
|
"sslpassword": {},
|
||||||
|
"sslsni": {},
|
||||||
"krbspn": {},
|
"krbspn": {},
|
||||||
"krbsrvname": {},
|
"krbsrvname": {},
|
||||||
"target_session_attrs": {},
|
"target_session_attrs": {},
|
||||||
@@ -424,6 +425,7 @@ func parseEnvSettings() map[string]string {
|
|||||||
"PGSSLMODE": "sslmode",
|
"PGSSLMODE": "sslmode",
|
||||||
"PGSSLKEY": "sslkey",
|
"PGSSLKEY": "sslkey",
|
||||||
"PGSSLCERT": "sslcert",
|
"PGSSLCERT": "sslcert",
|
||||||
|
"PGSSLSNI": "sslsni",
|
||||||
"PGSSLROOTCERT": "sslrootcert",
|
"PGSSLROOTCERT": "sslrootcert",
|
||||||
"PGSSLPASSWORD": "sslpassword",
|
"PGSSLPASSWORD": "sslpassword",
|
||||||
"PGTARGETSESSIONATTRS": "target_session_attrs",
|
"PGTARGETSESSIONATTRS": "target_session_attrs",
|
||||||
@@ -619,11 +621,15 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P
|
|||||||
sslcert := settings["sslcert"]
|
sslcert := settings["sslcert"]
|
||||||
sslkey := settings["sslkey"]
|
sslkey := settings["sslkey"]
|
||||||
sslpassword := settings["sslpassword"]
|
sslpassword := settings["sslpassword"]
|
||||||
|
sslsni := settings["sslsni"]
|
||||||
|
|
||||||
// Match libpq default behavior
|
// Match libpq default behavior
|
||||||
if sslmode == "" {
|
if sslmode == "" {
|
||||||
sslmode = "prefer"
|
sslmode = "prefer"
|
||||||
}
|
}
|
||||||
|
if sslsni == "" {
|
||||||
|
sslsni = "1"
|
||||||
|
}
|
||||||
|
|
||||||
tlsConfig := &tls.Config{}
|
tlsConfig := &tls.Config{}
|
||||||
|
|
||||||
@@ -756,6 +762,10 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P
|
|||||||
tlsConfig.Certificates = []tls.Certificate{cert}
|
tlsConfig.Certificates = []tls.Certificate{cert}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sslsni == "1" {
|
||||||
|
tlsConfig.ServerName = host
|
||||||
|
}
|
||||||
|
|
||||||
switch sslmode {
|
switch sslmode {
|
||||||
case "allow":
|
case "allow":
|
||||||
return []*tls.Config{nil, tlsConfig}, nil
|
return []*tls.Config{nil, tlsConfig}, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user