@@ -583,6 +583,12 @@ false
583583 value: {{ include " wiz-admission-controller.globalLeaderLeaseName" . }}
584584- name: WIZ_SCRAPE_API_SERVER_METRICS_ENABLED
585585 value: {{ include " wiz-admission-controller.scrapeAPIServerMetricsEnabled" . | trim | quote }}
586+ {{- if and .Values.wizManager.enabled .Values.wizManager.selfLoop.enabled }}
587+ - name: WIZ_SELFLOOP_ENABLED
588+ value: " true"
589+ - name: WIZ_SELFLOOP_PROBE_LABEL
590+ value: {{ .Values.wizManager.selfLoop.probeLabel | quote }}
591+ {{- end }}
586592{{- end -}}
587593
588594{{- define " wiz-admission-controller.image" -}}
@@ -632,7 +638,7 @@ Lookup existing TLS secret, with support for mocking in tests
632638Determine if scraping API server metrics is enabled, considering K8s version >= 1.21 (GA API for EndpointSlices)
633639*/ }}
634640{{- define " wiz-admission-controller.scrapeAPIServerMetricsEnabled" -}}
635- {{- if and .Values.scrapeAPIServerMetricsEnabled (semverCompare " >=1.21-0" (include " wiz-admission-controller.kubeVersion" . )) -}}
641+ {{- if and .Values.scrapeAPIServerMetrics.enabled (semverCompare " >=1.21-0" (include " wiz-admission-controller.kubeVersion" . )) -}}
636642true
637643{{- else -}}
638644false
@@ -711,3 +717,102 @@ Usage: include "wiz-admission-controller.crdCacheEnvVars" "enforcer"
711717- name: WIZ_CRD_CACHE_NAME_PREFIX
712718 value: {{ include " wiz-admission-controller.cacheNamePrefix" $runnerType }}
713719{{- end -}}
720+
721+ {{/*
722+ Renders a webhook entry from a config dict.
723+ Params:
724+ root - root context (.)
725+ webhookName - e.g. "misconfigurationsadmissionvalidator"
726+ serviceName - K8s service name
727+ path - webhook path, e.g. "/opa-validator"
728+ tlsCrt - base64-encoded CA cert
729+ useCertManagerCerts - bool, skip caBundle if true
730+ rules - list of RuleWithOperations
731+ additionalRules - optional extra rules to append
732+ namespaceSelector - namespace selector dict
733+ objectSelector - optional object selector dict
734+ timeoutSeconds - webhook timeout
735+ sideEffects - e.g. "None"
736+ */ }}
737+ {{- define " wiz-admission-controller.webhookEntry" -}}
738+ - name: {{ .webhookName }}
739+ admissionReviewVersions: [" v1" , " v1beta1" ]
740+ clientConfig:
741+ service:
742+ namespace: {{ .root.Release.Namespace }}
743+ name: {{ .serviceName }}
744+ path: {{ .path }}
745+ port: {{ .root.Values.service.port }}
746+ {{- if not .useCertManagerCerts }}
747+ caBundle: {{ .tlsCrt }}
748+ {{- end }}
749+ {{- with .rules }}
750+ rules:
751+ {{- toYaml . | nindent 4 }}
752+ {{- with $ .additionalRules }}
753+ {{- toYaml . | nindent 4 }}
754+ {{- end }}
755+ {{- end }}
756+ {{- with .namespaceSelector }}
757+ namespaceSelector:
758+ {{- toYaml . | nindent 4 }}
759+ {{- end }}
760+ {{- with .objectSelector }}
761+ objectSelector:
762+ {{- toYaml . | nindent 4 }}
763+ {{- end }}
764+ timeoutSeconds: {{ .timeoutSeconds }}
765+ failurePolicy: {{ .failurePolicy | default " Ignore" }}
766+ sideEffects: {{ .sideEffects }}
767+ {{- end -}}
768+
769+ {{/*
770+ Fixed rules for the sensor webhook — only watches pod creates.
771+ */ }}
772+ {{- define " wiz-admission-controller.sensor.rules" -}}
773+ - operations: [" CREATE" ]
774+ apiGroups: [" *" ]
775+ apiVersions: [" *" ]
776+ resources: [" pods" ]
777+ {{- end -}}
778+
779+ {{/*
780+ Fixed rules for self-loop webhook entries — only watches deployment updates.
781+ */ }}
782+ {{- define " wiz-admission-controller.selfLoop.rules" -}}
783+ - operations: [" UPDATE" ]
784+ apiGroups: [" apps" ]
785+ apiVersions: [" v1" ]
786+ resources: [" deployments" ]
787+ {{- end -}}
788+
789+ {{/*
790+ Self-loop webhook names — the unique identifier for each self-loop entry.
791+ Used in: webhook entry name, objectSelector label value, and manager env vars.
792+ */ }}
793+ {{- define " wiz-admission-controller.selfLoop.name.misconfiguration" -}}selfloop.misconfigurationsadmissionvalidator.wiz.io {{- end -}}
794+ {{- define " wiz-admission-controller.selfLoop.name.imageIntegrity" -}}selfloop.imageintegrityadmissionvalidator.wiz.io {{- end -}}
795+ {{- define " wiz-admission-controller.selfLoop.name.kdr" -}}selfloop.kubernetesauditlogs.wiz.io {{- end -}}
796+
797+ {{/*
798+ objectSelector for self-loop webhook entries.
799+ Params (passed as a list): [root, selfLoopName]
800+ */ }}
801+ {{- define " wiz-admission-controller.selfLoop.objectSelector" -}}
802+ {{- $root := index . 0 -}}
803+ {{- $selfLoopName := index . 1 -}}
804+ matchLabels:
805+ {{ $root .Values.wizManager.selfLoop.probeLabel }}: {{ $selfLoopName | quote }}
806+ {{- end -}}
807+
808+ {{/*
809+ namespaceSelector for self-loop webhook entries — locked to release namespace.
810+ */ }}
811+ {{- define " wiz-admission-controller.selfLoop.namespaceSelector" -}}
812+ matchExpressions:
813+ - key: kubernetes.io /metadata.name
814+ operator: In
815+ values:
816+ - {{ .Release.Namespace }}
817+ {{- end -}}
818+
0 commit comments