Skip to content

Commit 4c573bf

Browse files
committed
start CEL webhook matchConditions
1 parent 993de21 commit 4c573bf

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

charts/gmsa/templates/_helpers.tpl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,30 @@ apiVersion: cert-manager.io/v1
4545
INSERT_CERTIFICATE_FROM_SECRET
4646
{{- end -}}
4747
{{- end }}
48+
49+
# https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#matching-requests-matchconditions
50+
{{- define "webhook.matchConditions" -}}
51+
matchConditions:
52+
- name: 'has-gmsa-credspec'
53+
expression: |
54+
object.spec.containers.exists(
55+
container,
56+
has(container.securityContext) &&
57+
has(container.securityContext.windowsOptions) &&
58+
has(container.securityContext.windowsOptions.gmsaCredentialSpecName) &&
59+
size(container.securityContext.windowsOptions.gmsaCredentialSpecName) >= 1
60+
)
61+
{{- end -}}
62+
63+
{{- define "kube.versionMinor" -}}
64+
{{- $v := .Capabilities.KubeVersion.Version -}}
65+
{{- if (and .Values.overrideKubeVersion.enabled .Values.overrideKubeVersion.version) -}}
66+
{{- $v = .Values.overrideKubeVersion.version -}}
67+
{{- end -}}
68+
{{- $kubeVersion := $v | replace "v" "" | split "." -}}
69+
{{- if eq (len $kubeVersion) 3 -}}
70+
{{- $kubeVersion._1 -}}
71+
{{- else -}}
72+
{{- fail (printf "Invalid KubeVersion: %s" $v) -}}
73+
{{- end -}}
74+
{{- end -}}

charts/gmsa/templates/mutatingwebhook.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ webhooks:
2525
failurePolicy: Fail
2626
admissionReviewVersions: ["v1", "v1beta1"]
2727
sideEffects: None
28+
{{- if ge ((include "kube.versionMinor" .) | int) 30 }}
29+
{{- (include "webhook.matchConditions" .) | nindent 4 }}
30+
{{- end }}
2831
# don't run on ${NAMESPACE}
2932
namespaceSelector:
3033
matchExpressions:

charts/gmsa/templates/validatingwebhook.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ webhooks:
2525
failurePolicy: Fail
2626
admissionReviewVersions: ["v1", "v1beta1"]
2727
sideEffects: None
28+
{{- if ge ((include "kube.versionMinor" .) | int) 30 }}
29+
{{- (include "webhook.matchConditions" .) | nindent 4 }}
30+
{{- end }}
2831
# don't run on ${NAMESPACE}
2932
namespaceSelector:
3033
matchExpressions:

charts/gmsa/values.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ certificates:
1313

1414
credential:
1515
enabled: false
16-
hostAccountConfig: {}
16+
hostAccountConfig:
17+
{}
1718
# pluginGUID: "" # CCG Plugin GUID
1819
# portableCcgVersion: "1" # This needs to equal the current version of CCG which right now is '1'
1920
# pluginInput: "" # Format of this field is dependent upon specific CCG Plugin
@@ -56,3 +57,9 @@ tolerations: []
5657
qps: 30.0
5758
burst: 50
5859
randomHostname: false
60+
61+
# override kubernetes server version rather than rely on kubectl / helm Capabilities.KubeVersion.*
62+
# - sometimes client kubectl might be version skewed from target cluster
63+
overrideKubeVersion:
64+
enabled: true
65+
version: v1.29.16

0 commit comments

Comments
 (0)