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
14 changes: 12 additions & 2 deletions api/v1alpha1/backend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ type UnixSocket struct {

// BackendSpec describes the desired state of BackendSpec.
// +kubebuilder:validation:XValidation:rule="self.type != 'DynamicResolver' || !has(self.endpoints)",message="DynamicResolver type cannot have endpoints specified"
// +kubebuilder:validation:XValidation:rule="has(self.tls) ? self.type == 'DynamicResolver' : true",message="TLS settings can only be specified for DynamicResolver backends"
type BackendSpec struct {
// Type defines the type of the backend. Defaults to "Endpoints"
//
Expand Down Expand Up @@ -161,7 +160,6 @@ type BackendSpec struct {
}

// BackendTLSSettings holds the TLS settings for the backend.
// Only used for DynamicResolver backends.
// +kubebuilder:validation:XValidation:message="must not contain both CACertificateRefs and WellKnownCACertificates",rule="!(has(self.caCertificateRefs) && size(self.caCertificateRefs) > 0 && has(self.wellKnownCACertificates) && self.wellKnownCACertificates != \"\")"
// +kubebuilder:validation:XValidation:message="must specify either CACertificateRefs or WellKnownCACertificates",rule="(has(self.caCertificateRefs) && size(self.caCertificateRefs) > 0 || has(self.wellKnownCACertificates) && self.wellKnownCACertificates != \"\")"
type BackendTLSSettings struct {
Expand All @@ -176,6 +174,8 @@ type BackendTLSSettings struct {
// specified. Only one of CACertificateRefs or WellKnownCACertificates may be specified,
// not both.
//
// Only used for DynamicResolver backends.
//
// +kubebuilder:validation:MaxItems=8
// +optional
CACertificateRefs []gwapiv1.LocalObjectReference `json:"caCertificateRefs,omitempty"`
Expand All @@ -187,8 +187,18 @@ type BackendTLSSettings struct {
// must be specified with at least one entry for a valid configuration. Only one of
// CACertificateRefs or WellKnownCACertificates may be specified, not both.
//
// Only used for DynamicResolver backends.
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think will work, we'll need to enable this TLS section for all backend, lets raise a GH issue to track it

//
// +optional
WellKnownCACertificates *gwapiv1a3.WellKnownCACertificatesType `json:"wellKnownCACertificates,omitempty"`

// InsecureSkipVerify indicates whether the upstream's certificate verification
// should be skipped. Defaults to "false".
//
// +kubebuilder:default=false
// +optional
// +notImplementedHide
InsecureSkipVerify *bool `json:"insecureSkipVerify,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

im not a fan of this term, but its an industry wide term

Copy link
Contributor

Choose a reason for hiding this comment

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

@envoyproxy/gateway-maintainers thoughts on insecureSkipVerify vs skipValidation ?

Copy link
Member

Choose a reason for hiding this comment

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

+1 insecureSkipVerfiy

}

// 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 @@ -171,6 +171,8 @@ spec:
If CACertificateRefs is empty or unspecified, then WellKnownCACertificates must be
specified. Only one of CACertificateRefs or WellKnownCACertificates may be specified,
not both.

Only used for DynamicResolver backends.
items:
description: |-
LocalObjectReference identifies an API object within the namespace of the
Expand Down Expand Up @@ -208,6 +210,12 @@ spec:
type: object
maxItems: 8
type: array
insecureSkipVerify:
default: false
description: |-
InsecureSkipVerify indicates whether the upstream's certificate verification
should be skipped. Defaults to "false".
type: boolean
wellKnownCACertificates:
description: |-
WellKnownCACertificates specifies whether system CA certificates may be used in
Expand All @@ -216,6 +224,8 @@ spec:
If WellKnownCACertificates is unspecified or empty (""), then CACertificateRefs
must be specified with at least one entry for a valid configuration. Only one of
CACertificateRefs or WellKnownCACertificates may be specified, not both.

Only used for DynamicResolver backends.
enum:
- System
type: string
Expand All @@ -240,8 +250,6 @@ spec:
x-kubernetes-validations:
- message: DynamicResolver type cannot have endpoints specified
rule: self.type != 'DynamicResolver' || !has(self.endpoints)
- message: TLS settings can only be specified for DynamicResolver backends
rule: 'has(self.tls) ? self.type == ''DynamicResolver'' : true'
status:
description: Status defines the current status of Backend.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ spec:
If CACertificateRefs is empty or unspecified, then WellKnownCACertificates must be
specified. Only one of CACertificateRefs or WellKnownCACertificates may be specified,
not both.

Only used for DynamicResolver backends.
items:
description: |-
LocalObjectReference identifies an API object within the namespace of the
Expand Down Expand Up @@ -207,6 +209,12 @@ spec:
type: object
maxItems: 8
type: array
insecureSkipVerify:
default: false
description: |-
InsecureSkipVerify indicates whether the upstream's certificate verification
should be skipped. Defaults to "false".
type: boolean
wellKnownCACertificates:
description: |-
WellKnownCACertificates specifies whether system CA certificates may be used in
Expand All @@ -215,6 +223,8 @@ spec:
If WellKnownCACertificates is unspecified or empty (""), then CACertificateRefs
must be specified with at least one entry for a valid configuration. Only one of
CACertificateRefs or WellKnownCACertificates may be specified, not both.

Only used for DynamicResolver backends.
enum:
- System
type: string
Expand All @@ -239,8 +249,6 @@ spec:
x-kubernetes-validations:
- message: DynamicResolver type cannot have endpoints specified
rule: self.type != 'DynamicResolver' || !has(self.endpoints)
- message: TLS settings can only be specified for DynamicResolver backends
rule: 'has(self.tls) ? self.type == ''DynamicResolver'' : true'
status:
description: Status defines the current status of Backend.
properties:
Expand Down
15 changes: 15 additions & 0 deletions internal/gatewayapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ func validateBackend(backend *egv1a1.Backend) status.Error {
status.RouteReasonInvalidBackendRef,
)
}
} else {
if backend.Spec.TLS != nil {
if backend.Spec.TLS.WellKnownCACertificates != nil {
return status.NewRouteStatusError(
fmt.Errorf("TLS.WellKnownCACertificates settings can only be specified for DynamicResolver backends"),
status.RouteReasonInvalidBackendRef,
)
}
if len(backend.Spec.TLS.CACertificateRefs) > 0 {
return status.NewRouteStatusError(
fmt.Errorf("TLS.CACertificateRefs settings can only be specified for DynamicResolver backends"),
status.RouteReasonInvalidBackendRef,
)
}
}
}

for _, ep := range backend.Spec.Endpoints {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
backends:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
name: backend-1
namespace: default
spec:
tls:
caCertificateRefs:
- name: backend-ca-certificate
group: ""
kind: ConfigMap
endpoints:
- ip:
address: 1.1.1.1
port: 3001
zone: zone1
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
name: backend-2
namespace: default
spec:
tls:
wellKnownCACertificates: System
endpoints:
- ip:
address: 2.2.2.2
port: 3001
zone: zone2
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
backends:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
creationTimestamp: null
name: backend-1
namespace: default
spec:
endpoints:
- ip:
address: 1.1.1.1
port: 3001
zone: zone1
tls:
caCertificateRefs:
- group: ""
kind: ConfigMap
name: backend-ca-certificate
status:
conditions:
- lastTransitionTime: null
message: 'The Backend was not accepted: TLS.CACertificateRefs settings can only
be specified for DynamicResolver backends'
reason: Accepted
status: "False"
type: Invalid
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
creationTimestamp: null
name: backend-2
namespace: default
spec:
endpoints:
- ip:
address: 2.2.2.2
port: 3001
zone: zone2
tls:
wellKnownCACertificates: System
status:
conditions:
- lastTransitionTime: null
message: 'The Backend was not accepted: TLS.WellKnownCACertificates settings
can only be specified for DynamicResolver backends'
reason: Accepted
status: "False"
type: Invalid
infraIR: {}
xdsIR: {}
5 changes: 2 additions & 3 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,14 @@ _Appears in:_


BackendTLSSettings holds the TLS settings for the backend.
Only used for DynamicResolver backends.

_Appears in:_
- [BackendSpec](#backendspec)

| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `caCertificateRefs` | _LocalObjectReference array_ | false | | CACertificateRefs contains one or more references to Kubernetes objects that<br />contain TLS certificates of the Certificate Authorities that can be used<br />as a trust anchor to validate the certificates presented by the backend.<br />A single reference to a Kubernetes ConfigMap or a Kubernetes Secret,<br />with the CA certificate in a key named `ca.crt` is currently supported.<br />If CACertificateRefs is empty or unspecified, then WellKnownCACertificates must be<br />specified. Only one of CACertificateRefs or WellKnownCACertificates may be specified,<br />not both. |
| `wellKnownCACertificates` | _[WellKnownCACertificatesType](#wellknowncacertificatestype)_ | false | | WellKnownCACertificates specifies whether system CA certificates may be used in<br />the TLS handshake between the gateway and backend pod.<br />If WellKnownCACertificates is unspecified or empty (""), then CACertificateRefs<br />must be specified with at least one entry for a valid configuration. Only one of<br />CACertificateRefs or WellKnownCACertificates may be specified, not both. |
| `caCertificateRefs` | _LocalObjectReference array_ | false | | CACertificateRefs contains one or more references to Kubernetes objects that<br />contain TLS certificates of the Certificate Authorities that can be used<br />as a trust anchor to validate the certificates presented by the backend.<br />A single reference to a Kubernetes ConfigMap or a Kubernetes Secret,<br />with the CA certificate in a key named `ca.crt` is currently supported.<br />If CACertificateRefs is empty or unspecified, then WellKnownCACertificates must be<br />specified. Only one of CACertificateRefs or WellKnownCACertificates may be specified,<br />not both.<br />Only used for DynamicResolver backends. |
| `wellKnownCACertificates` | _[WellKnownCACertificatesType](#wellknowncacertificatestype)_ | false | | WellKnownCACertificates specifies whether system CA certificates may be used in<br />the TLS handshake between the gateway and backend pod.<br />If WellKnownCACertificates is unspecified or empty (""), then CACertificateRefs<br />must be specified with at least one entry for a valid configuration. Only one of<br />CACertificateRefs or WellKnownCACertificates may be specified, not both.<br />Only used for DynamicResolver backends. |


#### BackendTelemetry
Expand Down
25 changes: 0 additions & 25 deletions test/cel-validation/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
)
Expand Down Expand Up @@ -284,30 +283,6 @@ func TestBackend(t *testing.T) {
},
wantErrors: []string{"DynamicResolver type cannot have endpoints specified"},
},
{
desc: "tls settings on non-dynamic resolver",
mutate: func(backend *egv1a1.Backend) {
backend.Spec = egv1a1.BackendSpec{
AppProtocols: []egv1a1.AppProtocolType{egv1a1.AppProtocolTypeH2C},
Endpoints: []egv1a1.BackendEndpoint{
{
FQDN: &egv1a1.FQDNEndpoint{
Hostname: "example.com",
Port: 443,
},
},
},
TLS: &egv1a1.BackendTLSSettings{
CACertificateRefs: []gwapiv1.LocalObjectReference{
{
Name: "ca-certificate",
},
},
},
}
},
wantErrors: []string{"TLS settings can only be specified for DynamicResolver backends"},
},
{
desc: "Invalid Unix socket path length",
mutate: func(backend *egv1a1.Backend) {
Expand Down
12 changes: 10 additions & 2 deletions test/helm/gateway-crds-helm/all.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17483,6 +17483,8 @@ spec:
If CACertificateRefs is empty or unspecified, then WellKnownCACertificates must be
specified. Only one of CACertificateRefs or WellKnownCACertificates may be specified,
not both.

Only used for DynamicResolver backends.
items:
description: |-
LocalObjectReference identifies an API object within the namespace of the
Expand Down Expand Up @@ -17520,6 +17522,12 @@ spec:
type: object
maxItems: 8
type: array
insecureSkipVerify:
default: false
description: |-
InsecureSkipVerify indicates whether the upstream's certificate verification
should be skipped. Defaults to "false".
type: boolean
wellKnownCACertificates:
description: |-
WellKnownCACertificates specifies whether system CA certificates may be used in
Expand All @@ -17528,6 +17536,8 @@ spec:
If WellKnownCACertificates is unspecified or empty (""), then CACertificateRefs
must be specified with at least one entry for a valid configuration. Only one of
CACertificateRefs or WellKnownCACertificates may be specified, not both.

Only used for DynamicResolver backends.
enum:
- System
type: string
Expand All @@ -17552,8 +17562,6 @@ spec:
x-kubernetes-validations:
- message: DynamicResolver type cannot have endpoints specified
rule: self.type != 'DynamicResolver' || !has(self.endpoints)
- message: TLS settings can only be specified for DynamicResolver backends
rule: 'has(self.tls) ? self.type == ''DynamicResolver'' : true'
status:
description: Status defines the current status of Backend.
properties:
Expand Down
12 changes: 10 additions & 2 deletions test/helm/gateway-crds-helm/envoy-gateway-crds.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ spec:
If CACertificateRefs is empty or unspecified, then WellKnownCACertificates must be
specified. Only one of CACertificateRefs or WellKnownCACertificates may be specified,
not both.

Only used for DynamicResolver backends.
items:
description: |-
LocalObjectReference identifies an API object within the namespace of the
Expand Down Expand Up @@ -208,6 +210,12 @@ spec:
type: object
maxItems: 8
type: array
insecureSkipVerify:
default: false
description: |-
InsecureSkipVerify indicates whether the upstream's certificate verification
should be skipped. Defaults to "false".
type: boolean
wellKnownCACertificates:
description: |-
WellKnownCACertificates specifies whether system CA certificates may be used in
Expand All @@ -216,6 +224,8 @@ spec:
If WellKnownCACertificates is unspecified or empty (""), then CACertificateRefs
must be specified with at least one entry for a valid configuration. Only one of
CACertificateRefs or WellKnownCACertificates may be specified, not both.

Only used for DynamicResolver backends.
enum:
- System
type: string
Expand All @@ -240,8 +250,6 @@ spec:
x-kubernetes-validations:
- message: DynamicResolver type cannot have endpoints specified
rule: self.type != 'DynamicResolver' || !has(self.endpoints)
- message: TLS settings can only be specified for DynamicResolver backends
rule: 'has(self.tls) ? self.type == ''DynamicResolver'' : true'
status:
description: Status defines the current status of Backend.
properties:
Expand Down
Loading