Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions api/v1alpha1/backend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ type BackendTLSSettings struct {
// +kubebuilder:default=false
// +optional
InsecureSkipVerify *bool `json:"insecureSkipVerify,omitempty"`

// SNI is specifies the SNI value used when establishing an upstream TLS connection to the backend.
//
// Envoy Gateway will use the HTTP host header value for SNI, when all resources referenced in BackendRefs are:
// 1. Backend resources that do not set SNI, or
// 2. Service/ServiceImport resources that do not have a BackendTLSPolicy attached to them
//
// When a BackendTLSPolicy attaches to a Backend resource, the BackendTLSPolicy's Hostname value takes precedence
// over this value.
//
// +optional
SNI *gwapiv1.PreciseHostname `json:"sni,omitempty"`
}

// BackendType defines the type of the Backend.
Expand Down
5 changes: 5 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 @@ -223,6 +223,20 @@ spec:
InsecureSkipVerify indicates whether the upstream's certificate verification
should be skipped. Defaults to "false".
type: boolean
sni:
description: |-
SNI is specifies the SNI value used when establishing an upstream TLS connection to the backend.
Envoy Gateway will use the HTTP host header value for SNI, when all resources referenced in BackendRefs are:
1. Backend resources that do not set SNI, or
2. Service/ServiceImport resources that do not have a BackendTLSPolicy attached to them
When a BackendTLSPolicy attaches to a Backend resource, the BackendTLSPolicy's Hostname value takes precedence
over this value.
maxLength: 253
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
wellKnownCACertificates:
description: |-
WellKnownCACertificates specifies whether system CA certificates may be used in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,20 @@ spec:
InsecureSkipVerify indicates whether the upstream's certificate verification
should be skipped. Defaults to "false".
type: boolean
sni:
description: |-
SNI is specifies the SNI value used when establishing an upstream TLS connection to the backend.
Envoy Gateway will use the HTTP host header value for SNI, when all resources referenced in BackendRefs are:
1. Backend resources that do not set SNI, or
2. Service/ServiceImport resources that do not have a BackendTLSPolicy attached to them
When a BackendTLSPolicy attaches to a Backend resource, the BackendTLSPolicy's Hostname value takes precedence
over this value.
maxLength: 253
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
wellKnownCACertificates:
description: |-
WellKnownCACertificates specifies whether system CA certificates may be used in
Expand Down
8 changes: 7 additions & 1 deletion internal/gatewayapi/backendtlspolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func (t *Translator) applyBackendTLSSetting(
return t.applyEnvoyProxyBackendTLSSetting(upstreamConfig, resources, envoyProxy)
}

// Merges TLS settings from Gateway API BackendTLSPolicy and Envoy Gateway Backend TL.
// BackendTLSPolicy takes precedence for identical attributes that are set in both.
func mergeBackendTLSConfigs(
backendTLSSettingsConfig *ir.TLSUpstreamConfig,
backendTLSPolicyConfig *ir.TLSUpstreamConfig,
Expand All @@ -91,8 +93,8 @@ func mergeBackendTLSConfigs(
return backendTLSSettingsConfig
}

// If both are set, we merge them, with BackendTLSPolicy settings taking precedence
mergedConfig := backendTLSSettingsConfig.DeepCopy()

if backendTLSPolicyConfig.CACertificate != nil {
mergedConfig.CACertificate = backendTLSPolicyConfig.CACertificate
}
Expand All @@ -117,6 +119,10 @@ func (t *Translator) processBackendTLSSettings(
InsecureSkipVerify: ptr.Deref(backend.Spec.TLS.InsecureSkipVerify, false),
}

if backend.Spec.TLS.SNI != nil {
tlsConfig.SNI = ptr.To(string(*backend.Spec.TLS.SNI))
}

if !tlsConfig.InsecureSkipVerify {
tlsConfig.UseSystemTrustStore = ptr.Deref(backend.Spec.TLS.WellKnownCACertificates, "") == gwapiv1a3.WellKnownCACertificatesSystem

Expand Down
1 change: 1 addition & 0 deletions internal/gatewayapi/ext_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (t *Translator) translateExtServiceBackendRefs(
if rs.HasMixedEndpoints() {
return nil, errors.New("external service destinations having multiple endpoint types are not supported")
}

return rs, nil
}

Expand Down
225 changes: 225 additions & 0 deletions internal/gatewayapi/testdata/backend-with-auto-san-sni.in.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway-btls
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: httproute-backend-without-sni
namespace: envoy-gateway
spec:
parentRefs:
- namespace: envoy-gateway
name: gateway-btls
sectionName: http
hostnames:
- backend-without-sni.example.com
rules:
- matches:
- path:
type: Exact
value: "/backend-without-sni"
backendRefs:
- kind: Backend
group: gateway.envoyproxy.io
name: backend-without-sni
namespace: backends
port: 8080
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: httproute-backend-with-sni
namespace: envoy-gateway
spec:
parentRefs:
- namespace: envoy-gateway
name: gateway-btls
sectionName: http
hostnames:
- backend-with-sni.example.com
rules:
- matches:
- path:
type: Exact
value: "/backend-with-sni"
backendRefs:
- kind: Backend
group: gateway.envoyproxy.io
name: backend-with-sni
namespace: backends
port: 8080
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: httproute-backend-with-sni-and-btlsp
namespace: envoy-gateway
spec:
parentRefs:
- namespace: envoy-gateway
name: gateway-btls
sectionName: http
hostnames:
- backend-with-sni-and-btlsp.example.com
rules:
- matches:
- path:
type: Exact
value: "/backend-with-sni-and-btlsp"
backendRefs:
- kind: Backend
group: gateway.envoyproxy.io
name: backend-with-sni-and-btlsp
namespace: backends
port: 8080
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: httproute-backend-without-sni-and-btlsp
namespace: envoy-gateway
spec:
parentRefs:
- namespace: envoy-gateway
name: gateway-btls
sectionName: http
hostnames:
- "backend-without-sni-and-btlsp.example.com"
rules:
- matches:
- path:
type: Exact
value: "/backend-without-sni-and-btlsp"
backendRefs:
- kind: Backend
group: gateway.envoyproxy.io
name: backend-without-sni-and-btlsp
namespace: backends
port: 8080
referenceGrants:
- apiVersion: gateway.networking.k8s.io/v1alpha2
kind: ReferenceGrant
metadata:
name: refg-route-svc
namespace: backends
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: policies
to:
- group: gateway.envoyproxy.io
kind: Backend

backends:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
name: backend-without-sni
namespace: backends
spec:
endpoints:
- ip:
address: 1.1.1.1
port: 3001
tls:
caCertificateRefs:
- name: ca-secret
group: ""
kind: Secret
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
name: backend-with-sni
namespace: backends
spec:
endpoints:
- ip:
address: 1.1.1.1
port: 3001
tls:
caCertificateRefs:
- name: ca-secret
group: ""
kind: Secret
sni: "backend.sni.com"
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
name: backend-without-sni-and-btlsp
namespace: backends
spec:
endpoints:
- ip:
address: 1.1.1.1
port: 3001
tls:
caCertificateRefs:
- name: ca-secret
group: ""
kind: Secret
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
name: backend-with-sni-and-btlsp
namespace: backends
spec:
endpoints:
- ip:
address: 1.1.1.1
port: 3001
tls:
caCertificateRefs:
- name: ca-secret
group: ""
kind: Secret
sni: "backend.sni.com"
secrets:
- apiVersion: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2txaGtpRzl3MEJBUXNGQUFPQ0FRRUFNTHhyZ0ZWTXVOUnEyd0F3Y0J0N1NuTlI1Q2Z6CjJNdlhxNUVVbXVhd0lVaTlrYVlqd2RWaURSRUdTams3SlcxN3ZsNTc2SGpEa2RmUndpNEUyOFN5ZFJJblpmNkoKaThIWmNaN2NhSDZEeFIzMzVmZ0hWekxpNU5pVGNlL09qTkJRelEyTUpYVkRkOERCbUc1ZnlhdEppT0pRNGJXRQpBN0ZsUDBSZFAzQ08zR1dFME01aVhPQjJtMXFXa0UyZXlPNFVIdndUcU5RTGRyZEFYZ0RRbGJhbTllNEJHM0dnCmQvNnRoQWtXRGJ0L1FOVCtFSkhEQ3ZoRFJLaDFSdUdIeWcrWSsvbmViVFdXckZXc2t0UnJiT29IQ1ppQ3BYSTEKM2VYRTZudDBZa2d0RHhHMjJLcW5ocEFnOWdVU3MyaGxob3h5dmt6eUYwbXU2TmhQbHdBZ25xNysvUT09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K

backendTLSPolicies:
- apiVersion: gateway.networking.k8s.io/v1alpha2
kind: BackendTLSPolicy
metadata:
name: policy-btls
namespace: backends
spec:
targetRefs:
- kind: Backend
group: gateway.envoyproxy.io
name: backend-without-sni-and-btlsp
- kind: Backend
group: gateway.envoyproxy.io
name: backend-with-sni-and-btlsp
validation:
caCertificateRefs:
- name: ca-secret
group: ""
kind: Secret
hostname: example.com
subjectAltNames:
- type: URI
uri: spiffe://cluster.local/ns/istio-demo/sa/echo-v1
- hostname: subdomain.secondexample.com
Loading
Loading