Skip to content

Commit 8fe8316

Browse files
authored
Add ResolvedRefs condition for BackendTLSPolicy (#3994)
* Add ResolvedRefs condition for BackendTLSPolicy Signed-off-by: Norwin Schnyder <norwin.schnyder+github@gmail.com> * Apply PR feedback Signed-off-by: Norwin Schnyder <norwin.schnyder+github@gmail.com> * Refined implementation-specific behavior of CACertificateRefs Signed-off-by: Norwin Schnyder <norwin.schnyder+github@gmail.com> * Apply PR suggestions Signed-off-by: Norwin Schnyder <norwin.schnyder+github@gmail.com> --------- Signed-off-by: Norwin Schnyder <norwin.schnyder+github@gmail.com>
1 parent c703df9 commit 8fe8316

File tree

4 files changed

+110
-21
lines changed

4 files changed

+110
-21
lines changed

apis/v1alpha3/backendtlspolicy_types.go

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,32 @@ type BackendTLSPolicyValidation struct {
121121
// not both. If CACertificateRefs is empty or unspecified, the configuration for
122122
// WellKnownCACertificates MUST be honored instead if supported by the implementation.
123123
//
124-
// References to a resource in a different namespace are invalid for the
125-
// moment, although we will revisit this in the future.
124+
// A CACertificateRef is invalid if:
125+
//
126+
// * It refers to a resource that cannot be resolved (e.g., the referenced resource
127+
// does not exist) or is misconfigured (e.g., a ConfigMap does not contain a key
128+
// named `ca.crt`). In this case, the Reason must be set to `InvalidCACertificateRef`
129+
// and the Message of the Condition must indicate which reference is invalid and why.
130+
//
131+
// * It refers to an unknown or unsupported kind of resource. In this case, the Reason
132+
// must be set to `InvalidKind` and the Message of the Condition must explain which
133+
// kind of resource is unknown or unsupported.
134+
//
135+
// * It refers to a resource in another namespace. This may change in future
136+
// spec updates.
137+
//
138+
// Implementations MAY choose to perform further validation of the certificate
139+
// content (e.g., checking expiry or enforcing specific formats). In such cases,
140+
// an implementation-specific Reason and Message must be set for the invalid reference.
141+
//
142+
// In all cases, the implementation MUST ensure the `ResolvedRefs` Condition on
143+
// the BackendTLSPolicy is set to `status: False`, with a Reason and Message
144+
// that indicate the cause of the error. Connections using an invalid
145+
// CACertificateRef MUST fail, and the client MUST receive an HTTP 5xx error
146+
// response. If ALL CACertificateRefs are invalid, the implementation MUST also
147+
// ensure the `Accepted` Condition on the BackendTLSPolicy is set to
148+
// `status: False`, with a Reason `NoValidCACertificate`.
149+
//
126150
//
127151
// A single CACertificateRef to a Kubernetes ConfigMap kind has "Core" support.
128152
// Implementations MAY choose to support attaching multiple certificates to
@@ -131,8 +155,8 @@ type BackendTLSPolicyValidation struct {
131155
// Support: Core - An optional single reference to a Kubernetes ConfigMap,
132156
// with the CA certificate in a key named `ca.crt`.
133157
//
134-
// Support: Implementation-specific (More than one reference, or other kinds
135-
// of resources).
158+
// Support: Implementation-specific - More than one reference, other kinds
159+
// of resources, or a single reference that includes multiple certificates.
136160
//
137161
// +optional
138162
// +listType=atomic
@@ -144,10 +168,11 @@ type BackendTLSPolicyValidation struct {
144168
//
145169
// If WellKnownCACertificates is unspecified or empty (""), then CACertificateRefs
146170
// must be specified with at least one entry for a valid configuration. Only one of
147-
// CACertificateRefs or WellKnownCACertificates may be specified, not both. If an
148-
// implementation does not support the WellKnownCACertificates field or the value
149-
// supplied is not supported, the Status Conditions on the Policy MUST be
150-
// updated to include an Accepted: False Condition with Reason: Invalid.
171+
// CACertificateRefs or WellKnownCACertificates may be specified, not both.
172+
// If an implementation does not support the WellKnownCACertificates field, or
173+
// the supplied value is not recognized, the implementation MUST ensure the
174+
// `Accepted` Condition on the BackendTLSPolicy is set to `status: False`, with
175+
// a Reason `Invalid`.
151176
//
152177
// Support: Implementation-specific
153178
//
@@ -235,3 +260,43 @@ const (
235260
// Support: Core
236261
URISubjectAltNameType SubjectAltNameType = "URI"
237262
)
263+
264+
const (
265+
// This reason is used with the "Accepted" condition when it is
266+
// set to false because all CACertificateRefs of the
267+
// BackendTLSPolicy are invalid.
268+
BackendTLSPolicyReasonNoValidCACertificate v1alpha2.PolicyConditionReason = "NoValidCACertificate"
269+
)
270+
271+
const (
272+
// This condition indicates whether the controller was able to resolve all
273+
// object references for the BackendTLSPolicy.
274+
//
275+
// Possible reasons for this condition to be True are:
276+
//
277+
// * "ResolvedRefs"
278+
//
279+
// Possible reasons for this condition to be False are:
280+
//
281+
// * "InvalidCACertificateRef"
282+
// * "InvalidKind"
283+
//
284+
// Controllers may raise this condition with other reasons, but should
285+
// prefer to use the reasons listed above to improve interoperability.
286+
BackendTLSPolicyConditionResolvedRefs v1alpha2.PolicyConditionType = "ResolvedRefs"
287+
288+
// This reason is used with the "ResolvedRefs" condition when the condition
289+
// is true.
290+
BackendTLSPolicyReasonResolvedRefs v1alpha2.PolicyConditionReason = "ResolvedRefs"
291+
292+
// This reason is used with the "ResolvedRefs" condition when one of the
293+
// BackendTLSPolicy's CACertificateRefs is invalid.
294+
// A CACertificateRef is considered invalid when it refers to a nonexistent
295+
// resource or when the data within that resource is malformed.
296+
BackendTLSPolicyReasonInvalidCACertificateRef v1alpha2.PolicyConditionReason = "InvalidCACertificateRef"
297+
298+
// This reason is used with the "ResolvedRefs" condition when one of the
299+
// BackendTLSPolicy's CACertificateRefs references an unknown or unsupported
300+
// Group and/or Kind.
301+
BackendTLSPolicyReasonInvalidKind v1alpha2.PolicyConditionReason = "InvalidKind"
302+
)

config/crd/experimental/gateway.networking.k8s.io_backendtlspolicies.yaml

Lines changed: 32 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

geps/gep-1897/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ named object references, each containing a single cert. We originally proposed t
215215
[CertificateRefs field on Gateway](https://github.com/kubernetes-sigs/gateway-api/blob/18e79909f7310aafc625ba7c862dfcc67b385250/apis/v1beta1/gateway_types.go#L340)
216216
, but the CertificateRef requires both a tls.key and tls.crt and a certificate reference only requires the tls.crt.
217217
If any of the CACertificateRefs cannot be resolved (e.g., the referenced resource does not exist) or is misconfigured (e.g., ConfigMap does not contain a key named `ca.crt`), the `ResolvedRefs` status condition MUST be set to `False` with `Reason: InvalidCACertificateRef`. Connections using that CACertificateRef MUST fail, and the client MUST receive an HTTP 5xx error response.
218-
References to objects with an unsupported Group and Kind are not valid, and MUST be rejected by the implementation with the `ResolvedRefs` status condition set to `False` and `Reason: UnsupportedFeature`.
218+
References to objects with an unsupported Group and Kind are not valid, and MUST be rejected by the implementation with the `ResolvedRefs` status condition set to `False` and `Reason: InvalidKind`.
219219
Implementations MAY perform further validation of the certificate content (i.e., checking expiry or enforcing specific formats). If they do, they MUST ensure that the `ResolvedRefs` Condition is `False` and use an implementation-specific `Reason`, like `ExpiredCertificate` or similar.
220220
If `ResolvedRefs` Condition is `False` implementations SHOULD include a message specifying which references are invalid and explaining why.
221221

222-
If all CertificateRefs cannot be resolved, the BackendTLSPolicy is considered invalid and the implementation MUST set the `Accepted` Condition to `False`, with a reason of `NoCACertificates` and a message explaining this.
222+
If all CertificateRefs cannot be resolved, the BackendTLSPolicy is considered invalid and the implementation MUST set the `Accepted` Condition to `False`, with a reason of `NoValidCACertificate` and a message explaining this.
223223

224224
WellKnownCACertificates is an optional enum that allows users to specify whether to use the set of CA certificates trusted by the
225225
Gateway (WellKnownCACertificates specified as "System"), or to use the existing CACertificateRefs (WellKnownCACertificates
@@ -229,7 +229,7 @@ references to Kubernetes objects that contain PEM-encoded TLS certificates, whic
229229
between the gateway and backend pod. References to a resource in a different namespace are invalid.
230230
If ClientCertificateRefs is unspecified, then WellKnownCACertificates must be set to "System" for a valid configuration.
231231
If WellKnownCACertificates is unspecified, then CACertificateRefs must be specified with at least one entry for a valid configuration.
232-
If an implementation does not support the WellKnownCACertificates, or the provided value is unsupported,the BackendTLSPolicy is considered invalid, and the implementation MUST set the `Accepted` Condition to `False`, with a reason of `UnsupportedFeature` and a message explaining this.
232+
If an implementation does not support the WellKnownCACertificates, or the provided value is unsupported,the BackendTLSPolicy is considered invalid, and the implementation MUST set the `Accepted` Condition to `False`, with a reason of `Invalid` and a message explaining this.
233233

234234
For an invalid BackendTLSPolicy, implementations MUST NOT fall back to unencrypted (plaintext) connections.
235235
Instead, the corresponding TLS connection MUST fail, and the client MUST receive an HTTP 5xx error response.

pkg/generated/openapi/zz_generated.openapi.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)