Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions api/v1alpha1/envoyproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

const (
Expand Down Expand Up @@ -116,6 +117,34 @@ type EnvoyProxySpec struct {
// +optional
// +notImplementedHide
FilterOrder []FilterPosition `json:"filterOrder,omitempty"`
// BackendTLS is the TLS configuration for the Envoy proxy to use when connecting to backends.
// These settings are applied on backends for which TLS policies are specified.
// +optional
BackendTLS *BackendTLSConfig `json:"backendTLS,omitempty"`
}

// BackendTLSConfig describes the BackendTLS configuration for Envoy Proxy.
type BackendTLSConfig struct {
// ClientCertificateRef defines the reference to a Kubernetes Secret that contains
// the client certificate and private key for Envoy to use when connecting to
// backend services and external services, such as ExtAuth, ALS, OpenTelemetry, etc.
// +optional
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

// ECDHCurves specifies the set of supported ECDH curves.
// +optional
EcdhCurves []string `json:"ecdhCurves,omitempty"`
// MinVersion specifies the minimal tls protocol to allow.
// +optional
MinVersion string `json:"minVersion,omitempty"`
// MaxVersion specifies the maximal tls protocol version to allow
// +optional
MaxVersion string `json:"maxVersion,omitempty"`
// SignatureAlgorithms specifies which signature algorithms the listener should support.
// +optional
SignatureAlgorithms []string `json:"signatureAlgorithms,omitempty"`
}

// FilterPosition defines the position of an Envoy HTTP filter in the filter chain.
Expand Down
40 changes: 40 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,84 @@ spec:
spec:
description: EnvoyProxySpec defines the desired state of EnvoyProxy.
properties:
backendTLS:
description: |-
BackendTLS is the TLS configuration for the Envoy proxy to use when connecting to backends.
These settings are applied on backends for which TLS policies are specified.
properties:
ciphers:
description: 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).
items:
type: string
type: array
clientCertificateRef:
description: |-
ClientCertificateRef defines the reference to a Kubernetes Secret that contains
the client certificate and private key for Envoy to use when connecting to
backend services and external services, such as ExtAuth, ALS, OpenTelemetry, etc.
properties:
group:
default: ""
description: |-
Group is the group of the referent. For example, "gateway.networking.k8s.io".
When unspecified or empty string, core API group is inferred.
maxLength: 253
pattern: ^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
kind:
default: Secret
description: Kind is kind of the referent. For example "Secret".
maxLength: 63
minLength: 1
pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$
type: string
name:
description: Name is the name of the referent.
maxLength: 253
minLength: 1
type: string
namespace:
description: |-
Namespace is the namespace of the referenced object. When unspecified, the local
namespace is inferred.


Note that when a namespace different than the local namespace is specified,
a ReferenceGrant object is required in the referent namespace to allow that
namespace's owner to accept the reference. See the ReferenceGrant
documentation for details.


Support: Core
maxLength: 63
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
required:
- name
type: object
ecdhCurves:
description: ECDHCurves specifies the set of supported ECDH curves.
items:
type: string
type: array
maxVersion:
description: MaxVersion specifies the maximal tls protocol version
to allow
type: string
minVersion:
description: MinVersion specifies the minimal tls protocol to
allow.
type: string
signatureAlgorithms:
description: SignatureAlgorithms specifies which signature algorithms
the listener should support.
items:
type: string
type: array
type: object
bootstrap:
description: |-
Bootstrap defines the Envoy Bootstrap as a YAML string.
Expand Down
21 changes: 20 additions & 1 deletion internal/gatewayapi/backendtlspolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?

if resources.EnvoyProxy.Spec.BackendTLS != nil {
if len(resources.EnvoyProxy.Spec.BackendTLS.Ciphers) > 0 {
tlsBundle.Ciphers = resources.EnvoyProxy.Spec.BackendTLS.Ciphers
}
if len(resources.EnvoyProxy.Spec.BackendTLS.EcdhCurves) > 0 {
tlsBundle.EcdhCurves = resources.EnvoyProxy.Spec.BackendTLS.EcdhCurves
}
if len(resources.EnvoyProxy.Spec.BackendTLS.SignatureAlgorithms) > 0 {
tlsBundle.SignatureAlgorithms = resources.EnvoyProxy.Spec.BackendTLS.SignatureAlgorithms
}
if resources.EnvoyProxy.Spec.BackendTLS.MinVersion != "" {
tlsBundle.MinVersion = ptr.To(ir.TLSVersion(resources.EnvoyProxy.Spec.BackendTLS.MinVersion))
}
if resources.EnvoyProxy.Spec.BackendTLS.MaxVersion != "" {
tlsBundle.MaxVersion = ptr.To(ir.TLSVersion(resources.EnvoyProxy.Spec.BackendTLS.MaxVersion))
}
}
}
return tlsBundle
}

Expand Down
133 changes: 133 additions & 0 deletions internal/gatewayapi/testdata/envoyproxy-tls-settings.in.yaml
Original file line number Diff line number Diff line change
@@ -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?

- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway-tls
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
listeners:
- protocol: HTTPS
port: 443
tls:
mode: Terminate
certificateRefs:
- kind: Secret
namespace: envoy-gateway
group: ""
name: default-cert
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: httproute-tls
namespace: envoy-gateway
spec:
parentRefs:
- namespace: envoy-gateway
name: gateway-tls
rules:
- backendRefs:
- name: https-backend
namespace: default
port: 443
referenceGrants:
- apiVersion: gateway.networking.k8s.io/v1alpha2
kind: ReferenceGrant
metadata:
name: refg-route-svc
namespace: default
spec:
from:
- group: gateway.networking.k8s.io
kind: HTTPRoute
namespace: envoy-gateway
- group: gateway.networking.k8s.io
kind: Gateway
namespace: envoy-gateway
- group: gateway.networking.k8s.io
kind: BackendTLSPolicy
namespace: default
to:
- group: ""
kind: Service
services:
- apiVersion: v1
kind: Service
metadata:
name: https-backend
namespace: default
spec:
clusterIP: 10.11.12.13
ports:
- port: 443
name: https
protocol: TCP
targetPort: 443

endpointSlices:
- apiVersion: discovery.k8s.io/v1
kind: EndpointSlice
metadata:
name: endpointslice-https-backend
namespace: default
labels:
kubernetes.io/service-name: https-backend
addressType: IPv4
ports:
- name: https
protocol: TCP
port: 443
endpoints:
- addresses:
- "10.244.0.11"
conditions:
ready: true
backendTLSPolicies:
- apiVersion: gateway.networking.k8s.io/v1alpha2
kind: BackendTLSPolicy
metadata:
name: policy-tls
namespace: default
spec:
targetRef:
group: ''
kind: Service
name: https-backend
tls:
wellKnownCACerts: System
hostname: example.com
envoyproxy:
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
namespace: envoy-gateway-system
name: test
spec:
backendTLS:
clientCertificateRef:
group: ""
kind: Secret
namespace: default
name: secret.yaml
ciphers:
- ECDHE-RSA-AES128-GCM-SHA256
- ECDHE-ECDSA-AES256-GCM-SHA384
ecdhCurves:
- ECDHE-RSA-AES128-GCM-SHA256
- ECDHE-ECDSA-AES256-GCM-SHA384
maxVersion: tls1.3
minVersion: tls1.2
SignatureAlgorithms:
- RSA-PSS-RSAE-SHA256
- ECDSA-SECP256R1-SHA256
secrets:
- apiVersion: v1
kind: Secret
metadata:
name: default-cert
namespace: envoy-gateway
type: kubernetes.io/tls
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURKRENDQWd5Z0F3SUJBZ0lVU3JTYktMZjBiTEVHb2dXeC9nQ3cyR0N0dnhFd0RRWUpLb1pJaHZjTkFRRUwKQlFBd0V6RVJNQThHQTFVRUF3d0lWR1Z6ZENCSmJtTXdIaGNOTWpRd01qSTVNRGt6TURFd1doY05NelF3TWpJMgpNRGt6TURFd1dqQVRNUkV3RHdZRFZRUUREQWhVWlhOMElFbHVZekNDQVNJd0RRWUpLb1pJaHZjTkFRRUJCUUFECmdnRVBBRENDQVFvQ2dnRUJBSzFKempQSWlXZzNxb0hTckFkZ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