Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: add options to validate SANs and send SNI for upstream hostname #36903

Merged
merged 11 commits into from
Nov 9, 2024

Conversation

ggreenway
Copy link
Contributor

@ggreenway ggreenway commented Oct 29, 2024

These options are related, but do not have to be used together.

The existing auto_sni and auto_san_validation make Envoy set upstream TLS SNI and validate SANs based on the downstream requests's :authority (or override header).

The new auto_host_sni option causes Envoy to set the upstream TLS SNI to the hostname in the cluster for the host being connected to. For example, in a DNS cluster with server1.example.com and server2.example as the cluster members, connections would have SNI of server1.example.com and server2.example.com, respectively.

The new auto_sni_san_validation option causes Envoy to validate that the peer's server certificate has a DNS SAN that matches whatever SNI value was sent (regardless of how it's configured). This is appropriate to set in many/most configurations for normally-behaving upstream servers without special certificate validation requirements.

Risk Level: Low
Testing: New tests
Release Notes: Added

Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @abeyad
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #36903 was opened by ggreenway.

see: more, trace.

Signed-off-by: Greg Greenway <[email protected]>
Signed-off-by: Greg Greenway <[email protected]>
Signed-off-by: Greg Greenway <[email protected]>
Signed-off-by: Greg Greenway <[email protected]>
Signed-off-by: Greg Greenway <[email protected]>
abeyad
abeyad previously approved these changes Oct 31, 2024
Copy link
Contributor

@abeyad abeyad left a comment

Choose a reason for hiding this comment

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

/lgtm api

@abeyad
Copy link
Contributor

abeyad commented Oct 31, 2024

/assign-from @envoyproxy/senior-maintainers

Copy link

@envoyproxy/senior-maintainers assignee is @alyssawilk

🐱

Caused by: a #36903 (comment) was created by @abeyad.

see: more, trace.

Copy link
Contributor

@RyanTheOptimist RyanTheOptimist left a comment

Choose a reason for hiding this comment

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

I think I might be a bit unclear about the use case here. Do we have an issue which explains the motivation? Or maybe we could just flesh out the PR description?

// If true, replace any Subject Alternative Name validations with a validation for a DNS SAN matching
// the SNI value sent. Note that the validation will be against the actual requested SNI, regardless of how it
// is configured.
bool auto_sni_san_validation = 7;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think I quite understand the semantics here. Perhaps we could have an example?

// the hostname is known due to either a DNS cluster type or the
// :ref:`hostname <envoy_v3_api_field_config.endpoint.v3.Endpoint.hostname>` is set on
// the host.
bool auto_host_sni = 6;
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this intended to relate to the auto_sni here:
https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/protocol.proto#config-core-v3-upstreamhttpprotocoloptions
And ditto for auto_san_validation vs auto_sni_san_validation?

@ggreenway
Copy link
Contributor Author

I updated the PR description with a lot more details. That text should probably make it into the docs somewhere; do you have a good idea of the appropriate place for them?

@abeyad
Copy link
Contributor

abeyad commented Nov 7, 2024

auto_san_validation

Maybe here? https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/protocol.proto#config-core-v3-upstreamhttpprotocoloptions

Also, could add to the protocol buffer changes for more elucidation.

@ggreenway
Copy link
Contributor Author

I took a stab at finding a common place to describe the various related options and their interactions, and linked to that from the proto fields. I also made some minor cleanups and corrections.

@@ -60,3 +60,11 @@ static_resources:
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
sni: www.envoyproxy.io
common_tls_context:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this because I didn't want an example to not have a validation_context. That makes it a dangerously-insecure example.

Copy link
Member

Choose a reason for hiding this comment

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

probably we can use 1 config file and just highlight different parts - i can follow up with this

@@ -46,6 +46,7 @@ static_resources:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
sni: proxy-postgres-backend.example.com
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this so that it's a more complete example for how someone should actually configure this

Copy link
Member

Choose a reason for hiding this comment

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

im not sure i agree with this change - this is an example not using sni - also this breaks the highlighting

Copy link
Member

Choose a reason for hiding this comment

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

actually - it doesnt break it - its ~similar in current docs - wondering what should be highlighed here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Want me to revert this one? No SNI with validation is fine. Anything with no validation is probably not-fine.

Copy link
Member

Choose a reason for hiding this comment

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

yeah - understood - on balance i would say keep the status quo on this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, reverted that change

:caption: :download:`envoy-demo-tls-validation.yaml <_include/envoy-demo-tls-validation.yaml>`

.. note::

If the "Subject Alternative Names" for a certificate are for a wildcard domain, eg ``*.example.com``,
Copy link
Contributor Author

@ggreenway ggreenway Nov 7, 2024

Choose a reason for hiding this comment

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

This note didn't make sense; Envoy will correctly validate an expected SAN of test.example.com against a certificate with *.example.com (Envoy considers that a match)

Copy link
Member

@phlax phlax Nov 7, 2024

Choose a reason for hiding this comment

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

it was quite a while ago when i added this - but i thought i added it after testing it out

Copy link
Contributor Author

@ggreenway ggreenway Nov 7, 2024

Choose a reason for hiding this comment

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

It's documented in match_typed_subject_alt_names; this definitely works

// For example if the certificate has "\*.example.com" as DNS SAN entry, to allow only "api.example.com",

Copy link
Member

Choose a reason for hiding this comment

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

hmm - not sure - but im wondering if there are some circumstances where it doesnt work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there are, it's a bug and we should fix it.

Copy link
Member

Choose a reason for hiding this comment

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

if i get some time ill try and retry the steps i might have taken

@phlax
Copy link
Member

phlax commented Nov 7, 2024

/docs

Copy link

Docs for this Pull Request will be rendered here:

https://storage.googleapis.com/envoy-pr/36903/docs/index.html

The docs are (re-)rendered each time the CI envoy-presubmit (precheck docs) job completes.

🐱

Caused by: a #36903 (comment) was created by @phlax.

see: more, trace.

RyanTheOptimist
RyanTheOptimist previously approved these changes Nov 8, 2024
Copy link
Contributor

@RyanTheOptimist RyanTheOptimist left a comment

Choose a reason for hiding this comment

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

Thanks for the new comments and docs. LGTM, though obviously please wait for phlax's review too.

Copy link
Member

@phlax phlax left a comment

Choose a reason for hiding this comment

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

lgtm, thanks @ggreenway

@phlax
Copy link
Member

phlax commented Nov 8, 2024

headsup that CI is currently down 8(

@phlax
Copy link
Member

phlax commented Nov 8, 2024

/retest

@ggreenway ggreenway enabled auto-merge (squash) November 8, 2024 21:00
@ggreenway ggreenway merged commit 8ef1ecc into envoyproxy:main Nov 9, 2024
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants