Skip to content

Commit 55e3c22

Browse files
committed
crd: identityProvider <-> authenticate constraints
Add two CEL constraints on the Pomerium CRD to enforce that if the identityProvider field is set, the authenticate field must be set as well (and vice versa). Logically, this could be expressed as the single constraint has(self.identityProvider) == has(self.authenticate), but if we split it into two we can customize the error message depending on the case.
1 parent b95abdb commit 55e3c22

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

apis/ingress/v1/pomerium_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ type DownstreamMTLS struct {
221221
}
222222

223223
// PomeriumSpec defines Pomerium-specific configuration parameters.
224+
// +kubebuilder:validation:XValidation:rule="!has(self.identityProvider) || has(self.authenticate)",message="authenticate is required if identityProvider is set",reason="FieldValueRequired",fieldPath=".authenticate"
225+
// +kubebuilder:validation:XValidation:rule="!has(self.authenticate) || has(self.identityProvider)",message="identityProvider is required if authenticate is set",reason="FieldValueRequired",fieldPath=".identityProvider"
224226
type PomeriumSpec struct {
225227
// AccessLogFields sets the <a href="https://www.pomerium.com/docs/reference/access-log-fields">access fields</a> to log.
226228
AccessLogFields *[]string `json:"accessLogFields,omitempty"`

config/crd/bases/ingress.pomerium.io_pomerium.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,15 @@ spec:
613613
required:
614614
- secrets
615615
type: object
616+
x-kubernetes-validations:
617+
- fieldPath: .authenticate
618+
message: authenticate is required if identityProvider is set
619+
reason: FieldValueRequired
620+
rule: '!has(self.identityProvider) || has(self.authenticate)'
621+
- fieldPath: .identityProvider
622+
message: identityProvider is required if authenticate is set
623+
reason: FieldValueRequired
624+
rule: '!has(self.authenticate) || has(self.identityProvider)'
616625
status:
617626
description: PomeriumStatus represents configuration and Ingress status.
618627
properties:

deployment.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,15 @@ spec:
755755
required:
756756
- secrets
757757
type: object
758+
x-kubernetes-validations:
759+
- fieldPath: .authenticate
760+
message: authenticate is required if identityProvider is set
761+
reason: FieldValueRequired
762+
rule: '!has(self.identityProvider) || has(self.authenticate)'
763+
- fieldPath: .identityProvider
764+
message: identityProvider is required if authenticate is set
765+
reason: FieldValueRequired
766+
rule: '!has(self.authenticate) || has(self.identityProvider)'
758767
status:
759768
description: PomeriumStatus represents configuration and Ingress status.
760769
properties:

0 commit comments

Comments
 (0)