Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make webhook tls configuration easy to use #2135

Merged
merged 10 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ spec:
command:
- /usr/local/bin/tidb-admission-webhook
{{- if eq .Values.admissionWebhook.apiservice.insecureSkipTLSVerify false }}
- --tls-cert-file=/var/serving-cert/cert.pem
- --tls-private-key-file=/var/serving-cert/key.pem
- --tls-cert-file=/var/serving-cert/tls.crt
- --tls-private-key-file=/var/serving-cert/tls.key
{{- end }}
{{- if .Values.features }}
- --features={{ join "," .Values.features }}
Expand Down Expand Up @@ -68,6 +68,6 @@ spec:
- name: serving-cert
secret:
defaultMode: 420
secretName: tidb-admission-webhook-certs
secretName: {{ .Values.admissionWebhook.apiservice.tlsSecret }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
{{- if .Values.admissionWebhook.apiservice.insecureSkipTLSVerify }}
insecureSkipTLSVerify: true
{{- else }}
caBundle: {{ .Values.admissionWebhook.apiservice.cert | b64enc }}
caBundle: {{ .Values.admissionWebhook.apiservice.caBundle }}
{{- end }}
group: admission.tidb.pingcap.com
groupPriorityMinimum: 1000
Expand Down Expand Up @@ -49,7 +49,7 @@ webhooks:
namespace: default
path: "/apis/admission.tidb.pingcap.com/v1alpha1/admissionreviews"
{{- if .Values.admissionWebhook.cabundle }}
caBundle: {{ .Values.admissionWebhook.cabundle | b64enc }}
caBundle: {{ .Values.admissionWebhook.cabundle }}
{{- else }}
caBundle: null
{{- end }}
Expand Down Expand Up @@ -86,7 +86,7 @@ webhooks:
namespace: default
path: "/apis/admission.tidb.pingcap.com/v1alpha1/admissionreviews"
{{- if .Values.admissionWebhook.cabundle }}
caBundle: {{ .Values.admissionWebhook.cabundle | b64enc }}
caBundle: {{ .Values.admissionWebhook.cabundle }}
{{- else }}
caBundle: null
{{- end }}
Expand Down Expand Up @@ -121,7 +121,7 @@ webhooks:
namespace: default
path: "/apis/admission.tidb.pingcap.com/v1alpha1/admissionreviews"
{{- if .Values.admissionWebhook.cabundle }}
caBundle: {{ .Values.admissionWebhook.cabundle | b64enc }}
caBundle: {{ .Values.admissionWebhook.cabundle }}
{{- else }}
caBundle: null
{{- end }}
Expand Down Expand Up @@ -152,7 +152,7 @@ webhooks:
namespace: default
path: "/apis/admission.tidb.pingcap.com/v1alpha1/mutatingreviews"
{{- if .Values.admissionWebhook.cabundle }}
caBundle: {{ .Values.admissionWebhook.cabundle | b64enc }}
caBundle: {{ .Values.admissionWebhook.cabundle }}
{{- else }}
caBundle: null
{{- end }}
Expand Down Expand Up @@ -189,7 +189,7 @@ webhooks:
namespace: default
path: "/apis/admission.tidb.pingcap.com/v1alpha1/mutatingreviews"
{{- if .Values.admissionWebhook.cabundle }}
caBundle: {{ .Values.admissionWebhook.cabundle | b64enc }}
caBundle: {{ .Values.admissionWebhook.cabundle }}
{{- else }}
caBundle: null
{{- end }}
Expand Down

This file was deleted.

11 changes: 7 additions & 4 deletions charts/tidb-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,17 @@ admissionWebhook:
## apiservice config
## refer to https://kubernetes.io/docs/tasks/access-kubernetes-api/configure-aggregation-layer/#contacting-the-extension-apiserver
insecureSkipTLSVerify: true
## The key and cert for `tidb-admission-webook.<Release Namespace>` Service.
## The tls key and cert for `tidb-admission-webook.<Release Namespace>.svc` Service in Secret.
Yisaer marked this conversation as resolved.
Show resolved Hide resolved
## If insecureSkipTLSVerify is true, this would be ignored.
cert: ""
key: ""
## You can create the tls secret by kubectl create secret tls tidb-admission-webhook-certs --cert=<path-to-cert> --key=<path-to-key> --namespace <release-namespace>
Yisaer marked this conversation as resolved.
Show resolved Hide resolved
Yisaer marked this conversation as resolved.
Show resolved Hide resolved
tlsSecret: ""
## The caBundle for the webhook apiservice, you could get it by the secret you created previously:
## kubectl get secret tidb-admission-webhook-certs -o=jsonpath='{.data.tls\.crt}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be ca.crt instead of tls.crt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

caBundle: ""
Yisaer marked this conversation as resolved.
Show resolved Hide resolved
## certProvider indicate the key and cert for the webhook configuration to communicate with `kubernetes.default` service.
## If your kube-apiserver's version >= 1.13.0, you can leave cabundle empty and the kube-apiserver
## would trust the roots on the apiserver.
## refer to https://github.com/kubernetes/api/blob/master/admissionregistration/v1/types.go#L529
## or you can get the cabundle by:
## kubectl get configmap -n kube-system extension-apiserver-authentication -o=jsonpath='{.data.client-ca-file}'
## kubectl get configmap -n kube-system extension-apiserver-authentication -o=jsonpath='{.data.client-ca-file}' | base64 | tr -d '\n'
Yisaer marked this conversation as resolved.
Show resolved Hide resolved
cabundle: ""
3 changes: 2 additions & 1 deletion tests/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tests

import (
"encoding/base64"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -41,7 +42,7 @@ func (oa *operatorActions) setCabundleFromApiServer(info *OperatorConfig) error
if !existed {
return fmt.Errorf("failed to get caBundle from configmap[%s/%s]", namespace, name)
}
info.Cabundle = content
info.Cabundle = base64.StdEncoding.EncodeToString([]byte(content))
return nil
}
return nil
Expand Down