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

feat: support backend tls settings with envoyproxy #3218

Merged
merged 19 commits into from
Apr 25, 2024
Merged

feat: support backend tls settings with envoyproxy #3218

merged 19 commits into from
Apr 25, 2024

Conversation

alexwo
Copy link
Contributor

@alexwo alexwo commented Apr 18, 2024

What this PR does / why we need it:
This change allows to enhance the security and adaptability of connections to backend services. By allowing administrators to specify TLS settings, such as which cryptographic ciphers and TLS protocol versions to use, it allows to better align their security posture with industry best practices and regulatory requirements.

Approach:

  • Enable specification of default values through a TLS settings section in the EnvoyProxy backend.
  • Use these settings as the default TLS configurations whenever a BackendTLS policy is specified for a backend, applying the EnvoyProxy defaults to affected backends.

Once the BackendTLS policy or an alternative method for providing these settings is implemented/accepted in upstream, opt for more specific settings than those provided by envoyproxy backendtls settings.

Which issue(s) this PR fixes:
#2901

alexwo added 5 commits April 18, 2024 21:17
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
@alexwo alexwo changed the title feat: support backend tls settings in envoyproxy feat: support backend tls settings via envoyproxy Apr 18, 2024
@alexwo alexwo changed the title feat: support backend tls settings via envoyproxy feat: support backend tls settings with envoyproxy Apr 18, 2024
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
@alexwo alexwo marked this pull request as ready for review April 18, 2024 20:15
@alexwo alexwo requested a review from a team as a code owner April 18, 2024 20:15
alexwo added 2 commits April 18, 2024 23:49
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
@guydc
Copy link
Contributor

guydc commented Apr 18, 2024

cc @zhaohuabing who was also looking into backend MTLS in #2984

Copy link
Contributor

@guydc guydc 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 this!
Some comments on reuse of existing types.

ClientCertificateRef *gwapiv1.SecretObjectReference `json:"clientCertificateRef,omitempty"`
// Ciphers defines only support the specified cipher list when negotiating BackendTLS 1.0-1.2 (this setting has no effect when negotiating BackendTLS 1.3).
// +optional
Ciphers []string `json:"ciphers,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we reuse some of the types in tls_types.go that we use in client traffic policy, like TLSVersion? Maybe we can just embed the top-level TLSSettings struct here?

Copy link
Contributor Author

@alexwo alexwo Apr 19, 2024

Choose a reason for hiding this comment

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

We can, it currently contain also ClientValidation and ALPNProtocol, this is less interesting in this context.
Would it make sense to re-structure TLSSettings and include the commons here?

Copy link
Contributor

Choose a reason for hiding this comment

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

we can create a struct that represents the TLSParams and embed that struct in both place and handle the ClientCertificateRef and ClientValidation fields seperately

@@ -78,7 +78,26 @@ func (t *Translator) processBackendTLSPolicy(
}

status.SetAcceptedForPolicyAncestors(&policy.Status, ancestorRefs, t.GatewayControllerName)

// apply defaults as per envoyproxy
if resources.EnvoyProxy != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we apply this logic outside of backendtlspolicy translation, since it's not directly originating from that policy? It's probably most efficient and user-friendly to do it here. But, in the future TLS settings may originate from other resources, as described in kubernetes-sigs/gateway-api#2910

Copy link
Contributor Author

@alexwo alexwo Apr 19, 2024

Choose a reason for hiding this comment

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

Right, it can make sense but maybe we can do it after support for additional resources is implemented in upstream. I guess we can move / extend this logic to other areas as well at any time.

Do you see an advantage in making this change now? Maybe If we want to support a use case of applying this on a gateway level already.

wdyt?

@@ -161,3 +161,17 @@ func createExtServiceXDSCluster(rd *ir.RouteDestination, tCtx *types.ResourceVer
}
return nil
}

func ParseTLSProtocol(tlsVersion ir.TLSVersion) (tlsv3.TlsParameters_TlsProtocol, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse the util that we have in CTP for this mapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, i think we should be able i will check it.

@@ -0,0 +1,133 @@
gateways:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also add MTLS + TLS Settings tests for ext-auth and ext-proc, demonstrating how this applied to these sorts of backends?

@arkodg
Copy link
Contributor

arkodg commented Apr 19, 2024

thanks for working on this @alexwo !
this PR is doing two things

  1. added support for specifying clientCert which doesnt exist in upstream today
  2. added support for specifying tls params such as cipher_suites

both 1. and 2. are added into the global EnvoyProxy API
should 2. live inside BTP, so it can be modified on a per route (per upstream) basis ?

@alexwo
Copy link
Contributor Author

alexwo commented Apr 19, 2024

thanks for working on this @alexwo ! this PR is doing two things

  1. added support for specifying clientCert which doesnt exist in upstream today
  2. added support for specifying tls params such as cipher_suites

both 1. and 2. are added into the global EnvoyProxy API should 2. live inside BTP, so it can be modified on a per route (per upstream) basis ?

Hi @arkodg ,

It can allow for better flexibility, perhaps it can make more sense for (2) settings, @guydc WDYT?

thanks for working on this @alexwo ! this PR is doing two things

  1. added support for specifying clientCert which doesnt exist in upstream today
  2. added support for specifying tls params such as cipher_suites

both 1. and 2. are added into the global EnvoyProxy API should 2. live inside BTP, so it can be modified on a per route (per upstream) basis ?

@guydc
Copy link
Contributor

guydc commented Apr 19, 2024

It can allow for better flexibility, perhaps it can make more sense for (2) settings, @guydc WDYT?

The major downside I see in using BTP is that it can only attach to xRoute backends. So, if we need to apply TLS settings for other backends (extproc, extauth, OTEL, ALS ... ), we will need to add TLS setting in the scope of of #3069.

I'm fine with both options, as long as we can support TLS settings for both xRoute and non-xRoute backends. @arkodg - WDYT?

@guydc guydc mentioned this pull request Apr 19, 2024
@arkodg
Copy link
Contributor

arkodg commented Apr 19, 2024

It can allow for better flexibility, perhaps it can make more sense for (2) settings, @guydc WDYT?

The major downside I see in using BTP is that it can only attach to xRoute backends. So, if we need to apply TLS settings for other backends (extproc, extauth, OTEL, ALS ... ), we will need to add TLS setting in the scope of of #3069.

I'm fine with both options, as long as we can support TLS settings for both xRoute and non-xRoute backends. @arkodg - WDYT?

yeah for non xRoute we'll need to embed it into our backendRef

by moving 2. into BTP, we add the ability to fine tune settings, but now tls settings are spread out in 3 places, which can get confusing

  • clientCertificateRef in EnvoyProxy.Spec.BackendTLS
  • tlsParams in BackendTrafficPolicy.Spec.TLS
  • caCertificateRefs in BackendTLSPolicy.Spec.Validation

@alexwo
Copy link
Contributor Author

alexwo commented Apr 21, 2024

yeah for non xRoute we'll need to embed it into our backendRef

by moving 2. into BTP, we add the ability to fine tune settings, but now tls settings are spread out in 3 places, which can get confusing

  • clientCertificateRef in EnvoyProxy.Spec.BackendTLS
  • tlsParams in BackendTrafficPolicy.Spec.TLS
  • caCertificateRefs in BackendTLSPolicy.Spec.Validation

If we go with the BTP direction, does it make sense to move clientCertificateRef, to BTP as well?
This way we can have things less spread.

@guydc
Copy link
Contributor

guydc commented Apr 22, 2024

If we go with the BTP direction, does it make sense to move clientCertificateRef, to BTP as well? This way we can have things less spread.

I think so. It's possible that different backends will require a different client cert. It's not uncommon for organizations to use private PKI(s) for client certs, and so backends may have different trust stores and CAs. If we go with EnvoyProxy-level config, we basically assume that all backends can be configured to trust the EG client certificate.

@arkodg
Copy link
Contributor

arkodg commented Apr 22, 2024

@guydc @alexwo as platform administrators, would you say that the feature is necessary, because you are trying to enforce specific tls parameters (ciphers, tls versions). If this is true, then the argument of putting it in EnvoyProxy.Spec.BackendTLS can be made for 2. since for this use case, we'd want the platform admin to enforce these settings w/o allowing the app dev (route level BTP owner) to override it.

@guydc
Copy link
Contributor

guydc commented Apr 22, 2024

as platform administrators, would you say that the feature is necessary, because you are trying to enforce specific tls parameters (ciphers, tls versions)

Yes, our use case is related to defining system-wide upstream TLS settings, and so EnvoyProxy makes a lot of sense to me.

@arkodg
Copy link
Contributor

arkodg commented Apr 23, 2024

as platform administrators, would you say that the feature is necessary, because you are trying to enforce specific tls parameters (ciphers, tls versions)

Yes, our use case is related to defining system-wide upstream TLS settings, and so EnvoyProxy makes a lot of sense to me.

cool, i'm a +1 for this as well

alexwo added 5 commits April 24, 2024 10:58
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
@alexwo
Copy link
Contributor Author

alexwo commented Apr 24, 2024

/retest

guydc
guydc previously approved these changes Apr 24, 2024
Copy link
Contributor

@guydc guydc 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!

@@ -768,10 +768,29 @@ func buildXdsUpstreamTLSCASecret(tlsConfig *ir.TLSUpstreamConfig) *tlsv3.Secret
func buildXdsUpstreamTLSSocketWthCert(tlsConfig *ir.TLSUpstreamConfig) (*corev3.TransportSocket, error) {

var tlsCtx *tlsv3.UpstreamTlsContext
var tlsParams *tlsv3.TlsParameters
Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse

func buildTLSParams(tlsConfig *ir.TLSConfig) *tlsv3.TlsParameters {
?

alexwo added 2 commits April 25, 2024 00:26
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
@alexwo
Copy link
Contributor Author

alexwo commented Apr 25, 2024

/retest

@alexwo
Copy link
Contributor Author

alexwo commented Apr 25, 2024

/retest

1 similar comment
@alexwo
Copy link
Contributor Author

alexwo commented Apr 25, 2024

/retest

@guydc
Copy link
Contributor

guydc commented Apr 25, 2024

/retest

2 similar comments
@alexwo
Copy link
Contributor Author

alexwo commented Apr 25, 2024

/retest

@alexwo
Copy link
Contributor Author

alexwo commented Apr 25, 2024

/retest

Copy link
Contributor

@arkodg arkodg 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 !

@arkodg arkodg merged commit a81291e into envoyproxy:main Apr 25, 2024
23 checks passed
@alexwo alexwo deleted the backend_tls branch April 26, 2024 05:56
@guydc guydc mentioned this pull request May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants