diff --git a/.changelog/17481.txt b/.changelog/17481.txt new file mode 100644 index 000000000000..89ad16998e83 --- /dev/null +++ b/.changelog/17481.txt @@ -0,0 +1,3 @@ +```release-note:bug +tlsutil: Default setting of ServerName field in outgoing TLS configuration for checks now handled by crypto/tls. +``` diff --git a/tlsutil/config.go b/tlsutil/config.go index 5cdaf7633eca..a52d6b6ad829 100644 --- a/tlsutil/config.go +++ b/tlsutil/config.go @@ -857,10 +857,23 @@ func (c *Configurator) IncomingHTTPSConfig() *tls.Config { return config } -// OutgoingTLSConfigForCheck generates a *tls.Config for outgoing TLS connections -// for checks. This function is separated because there is an extra flag to -// consider for checks. EnableAgentTLSForChecks and InsecureSkipVerify has to -// be checked for checks. +// OutgoingTLSConfigForCheck creates a client *tls.Config for executing checks. +// It is RECOMMENDED that the serverName be left unspecified. The crypto/tls +// client will deduce the ServerName (for SNI) from the check address unless +// it's an IP (RFC 6066, Section 3). However, there are two instances where +// supplying a serverName is useful: +// +// 1. When the check address is an IP, a serverName can be supplied for SNI. +// Note: setting serverName will also override the hostname used to verify +// the certificate presented by the server being checked. +// +// 2. When the hostname in the check address won't be present in the SAN +// (Subject Alternative Name) field of the certificate presented by the +// server being checked. Note: setting serverName will also override the +// ServerName used for SNI. +// +// Setting skipVerify will disable verification of the server's certificate +// chain and hostname, which is generally not suitable for production use. func (c *Configurator) OutgoingTLSConfigForCheck(skipVerify bool, serverName string) *tls.Config { c.log("OutgoingTLSConfigForCheck") @@ -875,13 +888,9 @@ func (c *Configurator) OutgoingTLSConfigForCheck(skipVerify bool, serverName str } } - if serverName == "" { - serverName = c.serverNameOrNodeName() - } config := c.internalRPCTLSConfig(false) config.InsecureSkipVerify = skipVerify config.ServerName = serverName - return config } diff --git a/tlsutil/config_test.go b/tlsutil/config_test.go index 30ebd62c206b..721198afe83b 100644 --- a/tlsutil/config_test.go +++ b/tlsutil/config_test.go @@ -1376,7 +1376,7 @@ func TestConfigurator_OutgoingTLSConfigForCheck(t *testing.T) { }, }, { - name: "agent tls, default server name", + name: "agent tls, default consul server name, no override", conf: func() (*Configurator, error) { return NewConfigurator(Config{ InternalRPC: ProtocolConfig{ @@ -1389,11 +1389,11 @@ func TestConfigurator_OutgoingTLSConfigForCheck(t *testing.T) { }, expected: &tls.Config{ MinVersion: tls.VersionTLS12, - ServerName: "servername", + ServerName: "", }, }, { - name: "agent tls, skip verify, node name for server name", + name: "agent tls, skip verify, consul node name for server name, no override", conf: func() (*Configurator, error) { return NewConfigurator(Config{ InternalRPC: ProtocolConfig{ @@ -1407,7 +1407,7 @@ func TestConfigurator_OutgoingTLSConfigForCheck(t *testing.T) { expected: &tls.Config{ InsecureSkipVerify: true, MinVersion: tls.VersionTLS12, - ServerName: "nodename", + ServerName: "", }, }, { diff --git a/website/content/docs/services/configuration/checks-configuration-reference.mdx b/website/content/docs/services/configuration/checks-configuration-reference.mdx index fee071de51b0..c0d3e24cfde6 100644 --- a/website/content/docs/services/configuration/checks-configuration-reference.mdx +++ b/website/content/docs/services/configuration/checks-configuration-reference.mdx @@ -35,8 +35,8 @@ Specify health check options in the `check` block. To register two or more heath | `h2ping` | String value that specifies the HTTP2 endpoint, including port number, to send HTTP2 requests to. |