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

add more SANs to tidb server certificate #1702

Merged
merged 5 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions charts/tidb-cluster/templates/tidb-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ spec:
maxFailoverCount: {{ .Values.tikv.maxFailoverCount | default 3 }}
tidb:
enableTLSClient: {{ .Values.tidb.enableTLSClient | default false }}
{{- if .Values.tidb.extraSANIPList }}
extraSANIPList:
{{- range .Values.tidb.extraSANIPList }}
- {{ . }}
{{- end }}
{{- end }}
{{- if .Values.tidb.extraSANDomainList }}
extraSANDomainList:
{{- range .Values.tidb.extraSANDomainList }}
- {{ . }}
{{- end }}
{{- end }}
replicas: {{ .Values.tidb.replicas }}
image: {{ .Values.tidb.image }}
imagePullPolicy: {{ .Values.tidb.imagePullPolicy | default "IfNotPresent" }}
Expand Down
8 changes: 8 additions & 0 deletions charts/tidb-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,14 @@ tidb:
# automatically.
# Note: TLS connection is not forced on the server side, plain connections are also accepted after enableing.
enableTLSClient: false
# # extra SAN IP list when you set tidb.enableTLSClient to true
# extraSANIPList:
# - 1.1.1.1
# - 2.2.2.2
# # extra SAN Domain List when you set tidb.enableTLSClient to true
# extraSANDomainList:
# - example1.com
# - example2.com

# mysqlClient is used to set password for TiDB
# it must has Python MySQL client installed
Expand Down
11 changes: 11 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3783,6 +3783,17 @@ spec:
description: 'Whether enable the TLS connection between the SQL
client and TiDB server Optional: Defaults to false'
type: boolean
extraSANDomainList:
description: extra SAN Domain list when setting EnableTLSClient
to true
items:
type: string
type: array
extraSANIPList:
description: extra SAN IP list when setting EnableTLSClient to true
items:
type: string
type: array
hostNetwork:
description: 'Whether Hostnetwork of the component is enabled. Override
the cluster-level setting if present Optional: Defaults to cluster-level
Expand Down
28 changes: 28 additions & 0 deletions pkg/apis/pingcap/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ type TiDBSpec struct {
// +optional
EnableTLSClient *bool `json:"enableTLSClient,omitempty"`

// extra SAN IP list when setting EnableTLSClient to true
ExtraSANIPList []string `json:"extraSANIPList,omitempty"`

// extra SAN Domain list when setting EnableTLSClient to true
ExtraSANDomainList []string `json:"extraSANDomainList,omitempty"`

// The spec of the slow log tailer sidecar
// +optional
SlowLogTailer *TiDBSlowLogTailerSpec `json:"slowLogTailer,omitempty"`
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion pkg/manager/member/tidb_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@ func (tmm *tidbMemberManager) syncTiDBClusterCerts(tc *v1alpha1.TidbCluster) err
svcName,
peerName,
fmt.Sprintf("%s.%s", svcName, ns),
fmt.Sprintf("%s.%s.svc", svcName, ns),
fmt.Sprintf("%s.%s", peerName, ns),
fmt.Sprintf("%s.%s.svc", peerName, ns),
fmt.Sprintf("*.%s.%s", peerName, ns),
fmt.Sprintf("*.%s.%s.svc", peerName, ns),
}

ipList := []string{
Expand All @@ -268,22 +271,37 @@ func (tmm *tidbMemberManager) syncTiDBServerCerts(tc *v1alpha1.TidbCluster) erro
suffix := "tidb-server"
ns := tc.GetNamespace()
tcName := tc.GetName()
svcName := fmt.Sprintf("%s-%s", tcName, suffix)
svcName := controller.TiDBMemberName(tcName)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the Service name is <tcName>-tidb? If so, just change suffix to tidb would work, otherwise the suffix variable is no longer used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The suffix is used to construct the CSR Name, it must be distinguished from the tidb client certificate:


if tmm.certControl.CheckSecret(ns, svcName) {
return nil
}

svc, err := tmm.svcLister.Services(ns).Get(svcName)
if err != nil {
return err
}

hostList := []string{
svcName,
fmt.Sprintf("%s.%s", svcName, ns),
fmt.Sprintf("%s.%s.svc", svcName, ns),
"localhost",
}
hostList = append(hostList, tc.Spec.TiDB.ExtraSANDomainList...)

ipList := []string{
"127.0.0.1", "::1",
svc.Spec.ClusterIP,
}
ipList = append(ipList, tc.Spec.TiDB.ExtraSANIPList...)

certOpts := &controller.TiDBClusterCertOptions{
Namespace: ns,
Instance: tcName,
CommonName: svcName,
HostList: hostList,
IPList: ipList,
Component: "tidb",
Suffix: suffix,
}
Expand Down