Skip to content

Commit

Permalink
Create certificate for webhook with "kube-webhook-certgen"
Browse files Browse the repository at this point in the history
  • Loading branch information
muffl0n committed Apr 7, 2022
1 parent d7bd787 commit d9ce06c
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 39 deletions.
2 changes: 1 addition & 1 deletion helm/kanister-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
volumes:
- name: webhook-certs
secret:
secretName: kanister-webhook-certs
secretName: {{ include "kanister-operator.fullname" . }}-admission
{{- end }}
containers:
- name: {{ template "kanister-operator.fullname" . }}
Expand Down
38 changes: 0 additions & 38 deletions helm/kanister-operator/templates/validating-webhook.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions helm/kanister-operator/templates/webhook/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.bpValidatingWebhook.enabled -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "kanister-operator.fullname" . }}-admission
annotations:
"helm.sh/hook": pre-install,pre-upgrade,post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
rules:
- apiGroups:
- admissionregistration.k8s.io
resources:
- validatingwebhookconfigurations
verbs:
- get
- update
{{- end }}
17 changes: 17 additions & 0 deletions helm/kanister-operator/templates/webhook/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.bpValidatingWebhook.enabled -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "kanister-operator.fullname" . }}-admission
annotations:
"helm.sh/hook": pre-install,pre-upgrade,post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "kanister-operator.fullname" . }}-admission
subjects:
- kind: ServiceAccount
name: {{ include "kanister-operator.fullname" . }}-admission
namespace: {{ .Release.Namespace | quote }}
{{- end }}
47 changes: 47 additions & 0 deletions helm/kanister-operator/templates/webhook/job-createSecret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{- if .Values.bpValidatingWebhook.enabled -}}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "kanister-operator.fullname" . }}-admission-create
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
{{- if .Capabilities.APIVersions.Has "batch/v1alpha1" }}
# Alpha feature since k8s 1.12
ttlSecondsAfterFinished: 0
{{- end }}
template:
metadata:
name: {{ include "kanister-operator.fullname" . }}-admission-create
spec:
containers:
- name: create
{{- with .Values.bpValidatingWebhook.image }}
image: "{{ .repository }}/{{ .image }}:{{ .tag }}"
{{- end }}
imagePullPolicy: {{ .Values.bpValidatingWebhook.image.pullPolicy }}
args:
- create
- --host={{ include "kanister-operator.fullname" . }},{{ include "kanister-operator.fullname" . }}.$(POD_NAMESPACE).svc
- --namespace=$(POD_NAMESPACE)
- --secret-name={{ include "kanister-operator.fullname" . }}-admission
- --key-name=tls.key
- --cert-name=tls.crt
env:
- name: foo
value: bar
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
securityContext:
allowPrivilegeEscalation: false
restartPolicy: OnFailure
serviceAccountName: {{ include "kanister-operator.fullname" . }}-admission
securityContext:
runAsNonRoot: true
runAsUser: {{ .Values.bpValidatingWebhook.runAsUser }}
fsGroup: {{ .Values.bpValidatingWebhook.fsGroup }}
{{- end }}
45 changes: 45 additions & 0 deletions helm/kanister-operator/templates/webhook/job-patchWebhook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{- if .Values.bpValidatingWebhook.enabled -}}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "kanister-operator.fullname" . }}-admission-patch
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
{{- if .Capabilities.APIVersions.Has "batch/v1alpha1" }}
# Alpha feature since k8s 1.12
ttlSecondsAfterFinished: 0
{{- end }}
template:
metadata:
name: {{ include "kanister-operator.fullname" . }}-admission-patch
spec:
containers:
- name: patch
{{- with .Values.bpValidatingWebhook.image }}
image: "{{ .repository }}/{{ .image }}:{{ .tag }}"
{{- end }}
imagePullPolicy: {{ .Values.bpValidatingWebhook.image.pullPolicy }}
args:
- patch
- --webhook-name=blueprints.cr.kanister.io
- --namespace=$(POD_NAMESPACE)
- --patch-mutating=false
- --secret-name={{ include "kanister-operator.fullname" . }}-admission
- --patch-failure-policy={{ .Values.bpValidatingWebhook.failurePolicy }}
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
securityContext:
allowPrivilegeEscalation: false
restartPolicy: OnFailure
serviceAccountName: {{ include "kanister-operator.fullname" . }}-admission
securityContext:
runAsNonRoot: true
runAsUser: {{ .Values.bpValidatingWebhook.runAsUser }}
fsGroup: {{ .Values.bpValidatingWebhook.fsGroup }}
{{- end }}
18 changes: 18 additions & 0 deletions helm/kanister-operator/templates/webhook/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if .Values.bpValidatingWebhook.enabled -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "kanister-operator.fullname" . }}-admission
namespace: {{ .Release.Namespace | quote }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade,post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- create
{{- end }}
17 changes: 17 additions & 0 deletions helm/kanister-operator/templates/webhook/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.bpValidatingWebhook.enabled -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "kanister-operator.fullname" . }}-admission
namespace: {{ .Release.Namespace | quote }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade,post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ include "kanister-operator.fullname" . }}-admission
subjects:
- kind: ServiceAccount
name: {{ include "kanister-operator.fullname" . }}-admission
{{- end }}
10 changes: 10 additions & 0 deletions helm/kanister-operator/templates/webhook/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if .Values.bpValidatingWebhook.enabled -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "kanister-operator.fullname" . }}-admission
namespace: {{ .Release.Namespace | quote }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade,post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
{{- end }}
23 changes: 23 additions & 0 deletions helm/kanister-operator/templates/webhook/validating-webhook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- if .Values.bpValidatingWebhook.enabled -}}
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: "blueprints.cr.kanister.io"
webhooks:
- name: "blueprints.cr.kanister.io"
rules:
- apiGroups: ["cr.kanister.io"]
apiVersions: ["v1alpha1"]
operations: ["CREATE", "UPDATE"]
resources: ["blueprints"]
scope: "Namespaced"
clientConfig:
service:
namespace: {{ .Release.Namespace }}
name: {{ template "kanister-operator.fullname" . }}
path: "/validate/v1alpha1/blueprint"
port: {{ .Values.controller.service.port }}
admissionReviewVersions: ["v1", "v1beta1"]
sideEffects: None
timeoutSeconds: 5
{{- end -}}
8 changes: 8 additions & 0 deletions helm/kanister-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ controller:
updateCRDs: true
bpValidatingWebhook:
enabled: true
failurePolicy: Fail
image:
repository: k8s.gcr.io/ingress-nginx
image: kube-webhook-certgen
tag: v1.1.1
pullPolicy: IfNotPresent
runAsUser: 2000
fsGroup: 2000
resources:
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
Expand Down

0 comments on commit d9ce06c

Please sign in to comment.