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

Auto generate and sign certificates for TLS enabled cluster #782

Merged
merged 70 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
f31172f
discovery: add HTTPS URL support
AstroProfundis Aug 5, 2019
5bb2384
tls: add basic support of certis
AstroProfundis Aug 5, 2019
99956b7
tls: support tls client for pd
AstroProfundis Aug 6, 2019
84cc8bd
tls: support tls client for controller
AstroProfundis Aug 6, 2019
71bf08d
tls: update startup script templates
AstroProfundis Aug 7, 2019
ecfe87e
tls: fix configs
AstroProfundis Aug 7, 2019
926073e
tls: fix health check for tidb
AstroProfundis Aug 8, 2019
e4b319a
tls: create new pd client when scheme changed
AstroProfundis Aug 8, 2019
4da9be3
tls: fix return value when loading CAs
AstroProfundis Aug 9, 2019
451011a
Merge branch 'master' into tls-stage1
AstroProfundis Aug 9, 2019
b6cd879
tls: fix test errors
AstroProfundis Aug 9, 2019
030a04c
tls: fix typo in scripts
AstroProfundis Aug 12, 2019
b392aa2
Merge branch 'master' into tls-stage1
cofyc Aug 16, 2019
4b27ddd
fix test errors
AstroProfundis Aug 17, 2019
665e2fa
Merge branch 'tls-stage1' of github.com:AstroProfundis/tidb-operator …
AstroProfundis Aug 17, 2019
57ff597
tls: change config name and use better layout
AstroProfundis Aug 21, 2019
d8e982e
tls: refine scheme detection
AstroProfundis Aug 21, 2019
4f9bea5
tls: fix keys in templates
AstroProfundis Aug 21, 2019
04a9b59
tls: fix test cases
AstroProfundis Aug 21, 2019
0602bb5
Merge remote-tracking branch 'upstream' into tls-stage1
AstroProfundis Aug 23, 2019
eea2feb
Merge branch 'master' into tls-stage1
AstroProfundis Aug 26, 2019
7d9d03b
tls: update coding styles
AstroProfundis Aug 27, 2019
990b357
Merge branch 'master' into tls-stage1
AstroProfundis Aug 28, 2019
8e5ba66
[WIP] tls: add basic cert generation functions
AstroProfundis Aug 8, 2019
2d5dd87
tls: add basic definitions of cert controller
AstroProfundis Aug 14, 2019
f5cbf7f
tls: add auto approver for CSRs
AstroProfundis Aug 15, 2019
93402b0
tls: save certificates to secrets
AstroProfundis Aug 15, 2019
65f2567
tls: add generating cert for pd
AstroProfundis Aug 15, 2019
d7eb4f4
tls: add generating cert for tidb and tikv
AstroProfundis Aug 15, 2019
8675b05
tls: update statefulset and configs
AstroProfundis Aug 15, 2019
dfaa79b
tls: generate and sign certs automatically for new statefulsets
AstroProfundis Aug 16, 2019
813eb6b
tls: cleanup approved csr object after saving key pair to secret
AstroProfundis Aug 16, 2019
6380c96
tls: add labels to secrets
AstroProfundis Aug 20, 2019
fc44046
tls: rewrite exist csr if it was created by us
AstroProfundis Aug 20, 2019
8862e18
tls: generate client certs for discovery
AstroProfundis Aug 21, 2019
327b53b
tls: generate client certs for discovery
AstroProfundis Aug 21, 2019
ad7e4ad
tls: generate client certs for controller manager
AstroProfundis Aug 21, 2019
a8d526c
tls: read client certs from secret directly
AstroProfundis Aug 23, 2019
9b7d18c
tls: fix messed variable names after rebase
AstroProfundis Aug 23, 2019
227def6
tls: update charts and secret names
AstroProfundis Aug 23, 2019
6eae832
tls: fix certificate generating and loading for client requests
AstroProfundis Aug 26, 2019
12a60ea
tls: apply changes to other chart templates
AstroProfundis Aug 26, 2019
5b2a1c3
tls: fix monitoring when TLS clueter is enabled
AstroProfundis Aug 26, 2019
78b2860
tls: use seperate certs for tidb client and server
AstroProfundis Aug 26, 2019
5a12d06
tls: fix test errors
AstroProfundis Aug 26, 2019
2aaa919
tls: validate certs in exist secrets
AstroProfundis Aug 26, 2019
6a1dd49
tls: an workaround to get tikv metrics when TLS is enabled
AstroProfundis Aug 27, 2019
2c95860
tls: fix more template coding styles
AstroProfundis Aug 28, 2019
92a8e98
tls: refine csr & secret management
AstroProfundis Aug 28, 2019
4525e37
tls: update regex in prometheus config
AstroProfundis Aug 28, 2019
ee807e9
tests: basic support for TLS in e2e tests
AstroProfundis Aug 29, 2019
fce4683
Merge branch 'master' into tls-auto-sign
AstroProfundis Sep 4, 2019
a243d90
Merge branch 'master' into tls-auto-sign
AstroProfundis Sep 4, 2019
0280899
tls: update coding styles
AstroProfundis Sep 4, 2019
f206b08
tls: remove cert generating for controller manager
AstroProfundis Sep 4, 2019
9c45b97
Merge branch 'master' into tls-auto-sign
AstroProfundis Sep 4, 2019
5c65005
tls: fix test errors
AstroProfundis Sep 4, 2019
d847d40
e2e: disable PD scaling for TLS enabled cluster
AstroProfundis Sep 5, 2019
43578ee
Merge branch 'master' into tls-auto-sign
AstroProfundis Sep 6, 2019
0e455fe
Merge branch 'master' into tls-auto-sign
AstroProfundis Sep 24, 2019
1a7a78b
Revert "e2e: disable PD scaling for TLS enabled cluster"
AstroProfundis Sep 24, 2019
53d9656
Merge branch 'master' into tls-auto-sign
AstroProfundis Nov 13, 2019
2536060
tls: update dependency of glog to klog
AstroProfundis Nov 13, 2019
3ddbe77
tls: update e2e test
AstroProfundis Nov 13, 2019
8dbb955
tls: fix secret name for tidb server TLS cert
AstroProfundis Nov 13, 2019
7067a6d
tls: fix go tidy
AstroProfundis Nov 13, 2019
26edb7e
tls: fix test errors
AstroProfundis Nov 13, 2019
a80e244
tls: use a global scheme template in manifests
AstroProfundis Nov 13, 2019
deb628c
Merge branch 'master' into tls-auto-sign
AstroProfundis Nov 13, 2019
8bb8f53
Merge branch 'master' into tls-auto-sign
tennix Nov 15, 2019
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
28 changes: 28 additions & 0 deletions charts/tidb-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ config-file: |-
{{- if .Values.pd.config }}
{{ .Values.pd.config | indent 2 }}
{{- end -}}
{{- if .Values.enableTLSCluster }}
[security]
cacert-path = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
cert-path = "/var/lib/pd-tls/cert"
key-path = "/var/lib/pd-tls/key"
{{- end -}}

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Adding security config section here is fragile, users may provide this section in the .Values.pd.config too thus causing invalid configuration file.

{{- end -}}

{{- define "pd-configmap.data-digest" -}}
Expand All @@ -53,6 +60,13 @@ config-file: |-
{{- if .Values.tikv.config }}
{{ .Values.tikv.config | indent 2 }}
{{- end -}}
{{- if .Values.enableTLSCluster }}
[security]
ca-path = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
cert-path = "/var/lib/tikv-tls/cert"
key-path = "/var/lib/tikv-tls/key"
{{- end -}}

{{- end -}}

{{- define "tikv-configmap.data-digest" -}}
Expand All @@ -73,6 +87,20 @@ config-file: |-
{{- if .Values.tidb.config }}
{{ .Values.tidb.config | indent 2 }}
{{- end -}}
{{- if or .Values.enableTLSCluster .Values.enableTLSClient }}
[security]
{{- end -}}
{{- if .Values.enableTLSCluster }}
cluster-ssl-ca = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
cluster-ssl-cert = "/var/lib/tidb-tls/cert"
cluster-ssl-key = "/var/lib/tidb-tls/key"
{{- end -}}
{{- if .Values.tidb.enableTLSClient }}
ssl-ca = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
ssl-cert = "/var/lib/tidb-server-tls/cert"
ssl-key = "/var/lib/tidb-server-tls/key"
{{- end -}}

{{- end -}}

{{- define "tidb-configmap.data-digest" -}}
Expand Down
2 changes: 1 addition & 1 deletion charts/tidb-cluster/templates/config/_drainer-config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ detect-interval = {{ .Values.binlog.drainer.detectInterval | default 10 }}
data-dir = "/data"

# a comma separated list of PD endpoints
pd-urls = "http://{{ template "cluster.name" . }}-pd:2379"
pd-urls = "{{ if .Values.enableTLSCluster }}https{{ else }}http{{ end }}://{{ template "cluster.name" . }}-pd:2379"
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's an YAML template, not a shell script here

Copy link
Member

Choose a reason for hiding this comment

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

You can define a SCHEME macro in _helpers.tpl to avoid repeating the if-else block again and again.


# Use the specified compressor to compress payload between pump and drainer
compressor = ""
Expand Down
59 changes: 59 additions & 0 deletions charts/tidb-cluster/templates/config/_prometheus-config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ scrape_configs:
- {{ .Release.Namespace }}
tls_config:
insecure_skip_verify: true
{{- if .Values.enableTLSCluster }}
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
cert_file: /var/lib/pd-client-tls/cert
key_file: /var/lib/pd-client-tls/key

scheme: https
{{- end }}
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
action: keep
Expand All @@ -44,11 +51,63 @@ scrape_configs:
- source_labels: [__meta_kubernetes_pod_ip]
action: replace
target_label: kubernetes_pod_ip
{{- if .Values.enableTLSCluster }}
AstroProfundis marked this conversation as resolved.
Show resolved Hide resolved
- source_labels: [__meta_kubernetes_pod_name]
action: drop
regex: .*\-tikv\-\d*$
{{- end }}
- source_labels: [__meta_kubernetes_pod_name]
action: replace
target_label: instance
- source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
action: replace
target_label: cluster
{{- if .Values.enableTLSCluster }}
- job_name: 'tidb-cluster-tikv'
scrape_interval: 15s
honor_labels: true
kubernetes_sd_configs:
- role: pod
namespaces:
names:
- {{ .Release.Namespace }}
tls_config:
insecure_skip_verify: true
scheme: http
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
action: keep
regex: {{ .Release.Name }}
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
action: keep
regex: true
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
target_label: __address__
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: kubernetes_namespace
- source_labels: [__meta_kubernetes_pod_node_name]
action: replace
target_label: kubernetes_node
- source_labels: [__meta_kubernetes_pod_ip]
action: replace
target_label: kubernetes_pod_ip
- source_labels: [__meta_kubernetes_pod_name]
action: keep
regex: .*\-tikv\-\d*$
- source_labels: [__meta_kubernetes_pod_name]
action: replace
target_label: instance
- source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
action: replace
target_label: cluster
{{- end }}
rule_files:
- '/prometheus-rules/rules/*.rules.yml'
2 changes: 1 addition & 1 deletion charts/tidb-cluster/templates/config/_pump-config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data-dir = "/data"
heartbeat-interval = {{ .Values.binlog.pump.heartbeatInterval | default 2 }}

# a comma separated list of PD endpoints
pd-urls = "http://{{ template "cluster.name" . }}-pd:2379"
pd-urls = "{{ if .Values.enableTLSCluster }}https{{ else }}http{{ end }}://{{ template "cluster.name" . }}-pd:2379"
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto


#[security]
# Path of file that contains list of trusted SSL CAs for connection with cluster components.
Expand Down
1 change: 0 additions & 1 deletion charts/tidb-cluster/templates/discovery-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace

3 changes: 3 additions & 0 deletions charts/tidb-cluster/templates/discovery-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ rules:
resources: ["tidbclusters"]
resourceNames: [{{ template "cluster.name" . }}]
verbs: ["get"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
Expand Down
11 changes: 11 additions & 0 deletions charts/tidb-cluster/templates/monitor-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ spec:
- name: prometheus-rules
mountPath: /prometheus-rules
readOnly: false
{{- if .Values.enableTLSCluster }}
- name: tls-pd-client
tennix marked this conversation as resolved.
Show resolved Hide resolved
mountPath: /var/lib/pd-client-tls
readOnly: true
{{- end }}
{{- if .Values.monitor.grafana.create }}
- name: reloader
image: {{ .Values.monitor.reloader.image }}
Expand Down Expand Up @@ -208,6 +213,12 @@ spec:
- emptyDir: {}
name: grafana-dashboard
{{- end }}
{{- if .Values.enableTLSCluster }}
- name: tls-pd-client
secret:
defaultMode: 420
secretName: {{ .Release.Name }}-pd-client
{{- end }}
{{- if .Values.monitor.tolerations }}
tolerations:
{{ toYaml .Values.monitor.tolerations | indent 6 }}
Expand Down
4 changes: 3 additions & 1 deletion charts/tidb-cluster/templates/scripts/_start_drainer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ while true; do
fi
done

SCHEME={{ if .Values.enableTLSCluster }}"https"{{ else }}"http"{{ end }}

/drainer \
-L={{ .Values.binlog.drainer.logLevel | default "info" }} \
-pd-urls=http://{{ template "cluster.name" . }}-pd:2379 \
-pd-urls=${SCHEME}://{{ template "cluster.name" . }}-pd:2379 \
-addr=`echo ${HOSTNAME}`.{{ template "cluster.name" . }}-drainer:8249 \
-config=/etc/drainer/drainer.toml \
-disable-detect={{ .Values.binlog.drainer.disableDetect | default false }} \
Expand Down
10 changes: 6 additions & 4 deletions charts/tidb-cluster/templates/scripts/_start_pd.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ while true; do
fi
done

SCHEME={{ if .Values.enableTLSCluster }}"https"{{ else }}"http"{{ end }}

ARGS="--data-dir=/var/lib/pd \
--name=${POD_NAME} \
--peer-urls=http://0.0.0.0:2380 \
--advertise-peer-urls=http://${domain}:2380 \
--client-urls=http://0.0.0.0:2379 \
--advertise-client-urls=http://${domain}:2379 \
--peer-urls=${SCHEME}://0.0.0.0:2380 \
--advertise-peer-urls=${SCHEME}://${domain}:2380 \
--client-urls=${SCHEME}://0.0.0.0:2379 \
--advertise-client-urls=${SCHEME}://${domain}:2379 \
--config=/etc/pd/pd.toml \
AstroProfundis marked this conversation as resolved.
Show resolved Hide resolved
"

Expand Down
5 changes: 4 additions & 1 deletion charts/tidb-cluster/templates/scripts/_start_pump.sh.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
set -euo pipefail

SCHEME={{ if .Values.enableTLSCluster }}"https"{{ else }}"http"{{ end }}

/pump \
-pd-urls=http://{{ template "cluster.name" . }}-pd:2379 \
-pd-urls=${SCHEME}://{{ template "cluster.name" . }}-pd:2379 \
-L={{ .Values.binlog.pump.logLevel | default "info" }} \
-advertise-addr=`echo ${HOSTNAME}`.{{ template "cluster.name" . }}-pump:8250 \
-config=/etc/pump/pump.toml \
Expand Down
4 changes: 3 additions & 1 deletion charts/tidb-cluster/templates/scripts/_start_tikv.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ then
tail -f /dev/null
fi

SCHEME={{ if .Values.enableTLSCluster }}"https"{{ else }}"http"{{ end }}

# Use HOSTNAME if POD_NAME is unset for backward compatibility.
POD_NAME=${POD_NAME:-$HOSTNAME}
ARGS="--pd=${CLUSTER_NAME}-pd:2379 \
ARGS="--pd=${SCHEME}://${CLUSTER_NAME}-pd:2379 \
--advertise-addr=${POD_NAME}.${HEADLESS_SERVICE_NAME}.${NAMESPACE}.svc:20160 \
--addr=0.0.0.0:20160 \
--status-addr=0.0.0.0:20180 \
Expand Down
2 changes: 2 additions & 0 deletions charts/tidb-cluster/templates/tidb-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ metadata:
spec:
pvReclaimPolicy: {{ .Values.pvReclaimPolicy }}
timezone: {{ .Values.timezone | default "UTC" }}
enableTLSCluster: {{ .Values.enableTLSCluster | default false }}
services:
{{ toYaml .Values.services | indent 4 }}
schedulerName: {{ .Values.schedulerName | default "default-scheduler" }}
Expand Down Expand Up @@ -70,6 +71,7 @@ spec:
{{- end }}
hostNetwork: {{ .Values.tikv.hostNetwork }}
tidb:
enableTLSClient: {{ .Values.tidb.enableTLSClient | default false }}
replicas: {{ .Values.tidb.replicas }}
image: {{ .Values.tidb.image }}
imagePullPolicy: {{ .Values.tidb.imagePullPolicy | default "IfNotPresent" }}
Expand Down
12 changes: 12 additions & 0 deletions charts/tidb-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ discovery:
# if the ConfigMap was not changed.
enableConfigMapRollout: true

# Whether enable TLS connections between server nodes.
# When enabled, PD/TiDB/TiKV will use TLS encrypted connections to transfer data between each node,
# certificates will be generated automatically (if not already present).
enableTLSCluster: false
AstroProfundis marked this conversation as resolved.
Show resolved Hide resolved

pd:
# Please refer to https://github.com/pingcap/pd/blob/master/conf/config.toml for the default
# pd configurations (change to the tags of your pd version),
Expand Down Expand Up @@ -245,6 +250,7 @@ tidb:
config: |
[log]
level = "info"

# # Here are some parameters you MUST customize (Please configure in the above 'tidb.config' section):
# [performance]
# # Normally it should be tuned to `tidb.resources.limits.cpu`, for example: 16000m -> 16
Expand Down Expand Up @@ -319,6 +325,12 @@ tidb:
# the start argument to specify the plugin id (name "-" version) that needs to be loaded, e.g. 'conn_limit-1'.
list: ["whitelist-1"]

# Whether enable TLS connection between TiDB server and MySQL client.
# When enabled, TiDB will accept TLS encrypted connections from MySQL client, certificates will be generated
# automatically.
# Note: TLS connection is not forced on the server side, plain connections are also accepted after enableing.
enableTLSClient: false

# mysqlClient is used to set password for TiDB
# it must has Python MySQL client installed
mysqlClient:
Expand Down
10 changes: 8 additions & 2 deletions charts/tidb-operator/templates/controller-manager-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ rules:
verbs: ["get", "list", "watch", "create", "update", "delete"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list", "watch"]
verbs: ["create", "get", "list", "watch"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "create", "update", "delete"]
Expand Down Expand Up @@ -63,6 +63,12 @@ rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "patch","update"]
- apiGroups: ["certificates.k8s.io"]
resources: ["certificatesigningrequests"]
verbs: ["create", "get", "watch", "delete"]
- apiGroups: ["certificates.k8s.io"]
resources: ["certificatesigningrequests/approval", "certificatesigningrequests/status"]
verbs: ["update"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
Expand Down Expand Up @@ -108,7 +114,7 @@ rules:
verbs: ["get", "list", "watch", "create", "update", "delete"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list", "watch"]
verbs: ["create", "get", "list", "watch"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "create", "update", "delete"]
Expand Down
29 changes: 29 additions & 0 deletions cmd/controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func main() {
}

tcController := tidbcluster.NewController(kubeCli, cli, informerFactory, kubeInformerFactory, autoFailover, pdFailoverPeriod, tikvFailoverPeriod, tidbFailoverPeriod)
secControl := controller.NewRealSecretControl(kubeCli, kubeInformerFactory.Core().V1().Secrets().Lister())
certController := controller.NewRealCertControl(kubeCli,
AstroProfundis marked this conversation as resolved.
Show resolved Hide resolved
kubeInformerFactory.Certificates().V1beta1().CertificateSigningRequests().Lister(),
secControl)
backupController := backup.NewController(kubeCli, cli, informerFactory, kubeInformerFactory)
restoreController := restore.NewController(kubeCli, cli, informerFactory, kubeInformerFactory)
bsController := backupschedule.NewController(kubeCli, cli, informerFactory, kubeInformerFactory)
Expand All @@ -145,6 +149,9 @@ func main() {
go kubeInformerFactory.Start(controllerCtx.Done())

onStarted := func(ctx context.Context) {
if err := generateClientCert(ns, "tidb-operator", certController); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend creating the operator client certificate in the tidb-operator installation.

return
}
go wait.Forever(func() { backupController.Run(workers, ctx.Done()) }, waitDuration)
go wait.Forever(func() { restoreController.Run(workers, ctx.Done()) }, waitDuration)
go wait.Forever(func() { bsController.Run(workers, ctx.Done()) }, waitDuration)
Expand All @@ -170,3 +177,25 @@ func main() {

glog.Fatal(http.ListenAndServe(":6060", nil))
}

func generateClientCert(ns string, commonName string, certController controller.CertControlInterface) error {
secretName := "tidb-operator-pd-client"
if certController.CheckSecret(ns, secretName) {
return nil
}

hostList := []string{
commonName,
}

certOpts := &controller.TiDBClusterCertOptions{
Namespace: ns,
Instance: commonName,
CommonName: commonName,
HostList: hostList,
Component: "tidb-operator",
Suffix: "pd-client",
}

return certController.Create(certOpts)
}
7 changes: 6 additions & 1 deletion cmd/discovery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/pingcap/tidb-operator/version"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/util/logs"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

Expand Down Expand Up @@ -46,9 +47,13 @@ func main() {
if err != nil {
glog.Fatalf("failed to create Clientset: %v", err)
}
kubeCli, err := kubernetes.NewForConfig(cfg)
if err != nil {
glog.Fatalf("failed to get kubernetes Clientset: %v", err)
}

go wait.Forever(func() {
server.StartServer(cli, port)
server.StartServer(cli, kubeCli, port)
}, 5*time.Second)
glog.Fatal(http.ListenAndServe(":6060", nil))
}
Loading