Skip to content

Commit

Permalink
maskinporten: add validation rule for exposed scopes with delegationS…
Browse files Browse the repository at this point in the history
…ource set

The `delegationSource` field for exposed scopes is optional.
However, if `delegationSource` is set, the separator field must accordingly be set to `"/"` due to some arcane validation logic in Altinn (see previous PR: #214)

This commit adds a CEL validation rule to the CRD schema that enforces this logic.

See also:
- https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation-rules
- https://kubernetes.io/docs/reference/access-authn-authz/validating-admission-policy/#optional-parameters
  • Loading branch information
tronghn committed Jun 4, 2024
1 parent 29bde14 commit 4f74631
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions charts/templates/nais.io_applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,11 @@ spec:
- name
- product
type: object
x-kubernetes-validations:
- message: scopes.exposes[].separator must be set to "/"
when scopes.exposes[].delegationSource is set
rule: '!has(self.delegationSource) || (has(self.separator)
&& self.separator == "/")'
type: array
type: object
required:
Expand Down
5 changes: 5 additions & 0 deletions charts/templates/nais.io_maskinportenclients.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ spec:
- name
- product
type: object
x-kubernetes-validations:
- message: scopes.exposes[].separator must be set to "/" when
scopes.exposes[].delegationSource is set
rule: '!has(self.delegationSource) || (has(self.separator)
&& self.separator == "/")'
type: array
type: object
secretName:
Expand Down
5 changes: 5 additions & 0 deletions charts/templates/nais.io_naisjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,11 @@ spec:
- name
- product
type: object
x-kubernetes-validations:
- message: scopes.exposes[].separator must be set to "/"
when scopes.exposes[].delegationSource is set
rule: '!has(self.delegationSource) || (has(self.separator)
&& self.separator == "/")'
type: array
type: object
required:
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/nais.io_applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,11 @@ spec:
- name
- product
type: object
x-kubernetes-validations:
- message: scopes.exposes[].separator must be set to "/"
when scopes.exposes[].delegationSource is set
rule: '!has(self.delegationSource) || (has(self.separator)
&& self.separator == "/")'
type: array
type: object
required:
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/nais.io_maskinportenclients.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ spec:
- name
- product
type: object
x-kubernetes-validations:
- message: scopes.exposes[].separator must be set to "/" when
scopes.exposes[].delegationSource is set
rule: '!has(self.delegationSource) || (has(self.separator)
&& self.separator == "/")'
type: array
type: object
secretName:
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/nais.io_naisjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,11 @@ spec:
- name
- product
type: object
x-kubernetes-validations:
- message: scopes.exposes[].separator must be set to "/"
when scopes.exposes[].delegationSource is set
rule: '!has(self.delegationSource) || (has(self.separator)
&& self.separator == "/")'
type: array
type: object
required:
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/nais.io/v1/digdirator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type ConsumedScope struct {
Name string `json:"name"`
}

// +kubebuilder:validation:XValidation:rule="!has(self.delegationSource) || (has(self.separator) && self.separator == \"/\")",message="scopes.exposes[].separator must be set to \"/\" when scopes.exposes[].delegationSource is set"
type ExposedScope struct {
// If Enabled the configured scope is available to be used and consumed by organizations granted access.
// +kubebuilder:validation:Required
Expand Down

0 comments on commit 4f74631

Please sign in to comment.