Skip to content

tlsutil: Fix check TLS configuration#17481

Merged
david-yu merged 6 commits intohashicorp:mainfrom
beautifulentropy:tlsutil-fix-server-name
Jun 28, 2023
Merged

tlsutil: Fix check TLS configuration#17481
david-yu merged 6 commits intohashicorp:mainfrom
beautifulentropy:tlsutil-fix-server-name

Conversation

@beautifulentropy
Copy link
Copy Markdown
Contributor

@beautifulentropy beautifulentropy commented May 25, 2023

Description

Since the introduction of #5394, the OutgoingTLSConfigForCheck method of tlsutil.Configurator has been setting the ServerName field of TLS configurations used for executing health checks to the Consul node or server name by default.

According to the crypto/tls documentation:

// ServerName is used to verify the hostname on the returned
// certificates unless InsecureSkipVerify is given. It is also included
// in the client's handshake to support virtual hosting unless it is
// an IP address.

Unless the check.tls_server_name indicates otherwise, it is generally better to leave the ServerName field empty. The crypto/tls client will infer the ServerName for SNI from the check address, unless it's an IP (as per RFC 6066, Section 3). There are two common situations where specifying this field can be beneficial:

  1. When the check address is an IP, tls_server_name can be specified for SNI. Note: setting tls_server_name 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 tls_server_name will also override the hostname used for SNI.

This PR also updates the documentation for tls_server_name and tls_skip_verify to indicate that both fields can be used for H2Ping and gRPC checks, not just HTTP and provides a slightly slimmed down version of the above circumstances for tls_server_name.

Testing & Reproduction steps

I encountered this issue while drafting letsencrypt/boulder#6908. After experiencing certificate validation failures due the Consul node name failing to be present in the SAN field of certificate of the component being health checked, we dug into the Consul code and diagnosed the issue above.

Links

Substantiating my claim that crypto/tls client will infer the ServerName based on the address being dialed: link

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

@github-actions github-actions bot added theme/certificates Related to creating, distributing, and rotating certificates in Consul theme/tls Using TLS (Transport Layer Security) or mTLS (mutual TLS) to secure communication type/docs Documentation needs to be created/updated/clarified labels May 25, 2023
@beautifulentropy beautifulentropy marked this pull request as ready for review May 25, 2023 21:36
@beautifulentropy beautifulentropy requested a review from a team as a code owner May 25, 2023 21:36
@beautifulentropy
Copy link
Copy Markdown
Contributor Author

@blake, this PR has been open for a while. Is there someone in particular that I should ping to get a reviewer assigned?

Copy link
Copy Markdown
Contributor

@trujillo-adam trujillo-adam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long delay on reviewing the docs. I made a suggestion and am pre-approving so that you are not blocked.

@david-yu
Copy link
Copy Markdown
Contributor

Thanks @beautifulentropy this change makes sense. This change likely will need to go into a future minor release on Consul instead of a patch release since it is a breaking change.

@beautifulentropy
Copy link
Copy Markdown
Contributor Author

beautifulentropy commented Jun 26, 2023

Thanks @beautifulentropy this change makes sense. This change likely will need to go into a future minor release on Consul instead of a patch release since it is a breaking change.

This is exactly what I figured. It's a super small change with a fairly big blast radius for folks who aren't presently using tls_skip_verify or tls_server_name on all of their gRPC checks.

@david-yu david-yu self-requested a review June 26, 2023 21:34
Copy link
Copy Markdown
Contributor

@david-yu david-yu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but we'll need someone from Eng to also take a pass and review this as well. This will likely land in 1.17.0

@david-yu david-yu requested review from a team, hc-github-team-consul-core and xwa153 and removed request for a team and hc-github-team-consul-core June 26, 2023 22:22
@xwa153
Copy link
Copy Markdown
Member

xwa153 commented Jun 26, 2023

@beautifulentropy Thanks for putting things together! I left very small comments but nothing is blocking. Approved.

@david-yu
Copy link
Copy Markdown
Contributor

david-yu commented Jun 26, 2023

Could you also add a .changelog/17481.txt with a changelog file that looks like the following?

agent: The `enable_central_service_config` option now defaults to true.

@beautifulentropy
Copy link
Copy Markdown
Contributor Author

Thanks for the comments, I'll take a look at this tomorrow.

@beautifulentropy
Copy link
Copy Markdown
Contributor Author

Thank for your patience, yesterday was a pretty packed day. I believe I've addressed all outstanding comments. Let me know if I've missed anything.

@david-yu
Copy link
Copy Markdown
Contributor

Thanks @beautifulentropy. We reviewed the PR and it looks great. Will go ahead and merge. This will be introduced in Consul 1.17.0 as a breaking change. Thank you.