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

chore: support to get ca-key file when enabling tls #8840

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions apis/apps/v1/componentdefinition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,13 @@ type TLS struct {
// +optional
CAFile *string `json:"caFile,omitempty"`

// The CA key file of the TLS.
//
// This field is immutable once set.
//
// +optional
CAKeyFile *string `json:"caKeyFile,omitempty"`

// The certificate file of the TLS.
//
// This field is immutable once set.
Expand Down
5 changes: 5 additions & 0 deletions apis/apps/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -16780,6 +16780,13 @@ spec:
The CA file of the TLS.


This field is immutable once set.
type: string
caKeyFile:
description: |-
The CA key file of the TLS.


This field is immutable once set.
type: string
certFile:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16780,6 +16780,13 @@ spec:
The CA file of the TLS.


This field is immutable once set.
type: string
caKeyFile:
description: |-
The CA key file of the TLS.


This field is immutable once set.
type: string
certFile:
Expand Down
13 changes: 13 additions & 0 deletions docs/developer_docs/api-reference/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -11385,6 +11385,19 @@ string
</tr>
<tr>
<td>
<code>caKeyFile</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>The CA key file of the TLS.</p>
<p>This field is immutable once set.</p>
</td>
</tr>
<tr>
<td>
<code>certFile</code><br/>
<em>
string
Expand Down
13 changes: 9 additions & 4 deletions pkg/controller/plan/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,32 @@ func ComposeTLSSecret(compDef *appsv1.ComponentDefinition, synthesizedComp compo
{{- $cert := genSignedCert "%s peer" (list "127.0.0.1" "::1") (list "localhost" "*.%s-%s-headless.%s.svc.cluster.local") 36500 $ca -}}
{{- $ca.Cert -}}
{{- print "%s" -}}
{{- $ca.Key -}}
{{- print "%s" -}}
{{- $cert.Cert -}}
{{- print "%s" -}}
{{- $cert.Key -}}
`, compName, clusterName, compName, namespace, spliter, spliter)
`, compName, clusterName, compName, namespace, spliter, spliter, spliter)
out, err := buildFromTemplate(SignedCertTpl, nil)
if err != nil {
return nil, err
}
parts := strings.Split(out, spliter)
if len(parts) != 3 {
if len(parts) != 4 {
return nil, errors.Errorf("generate TLS certificates failed with cluster name %s, component name %s in namespace %s",
clusterName, compName, namespace)
}
if compDef.Spec.TLS.CAFile != nil {
secret.StringData[*compDef.Spec.TLS.CAFile] = parts[0]
}
if compDef.Spec.TLS.CAKeyFile != nil {
secret.StringData[*compDef.Spec.TLS.CAKeyFile] = parts[1]
}
if compDef.Spec.TLS.CertFile != nil {
secret.StringData[*compDef.Spec.TLS.CertFile] = parts[1]
secret.StringData[*compDef.Spec.TLS.CertFile] = parts[2]
}
if compDef.Spec.TLS.KeyFile != nil {
secret.StringData[*compDef.Spec.TLS.KeyFile] = parts[2]
secret.StringData[*compDef.Spec.TLS.KeyFile] = parts[3]
}
return secret, nil
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/controller/plan/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ var _ = Describe("TLSUtilsTest", func() {
compDef := &appsv1.ComponentDefinition{
Spec: appsv1.ComponentDefinitionSpec{
TLS: &appsv1.TLS{
CAFile: ptr.To("ca.pem"),
CertFile: ptr.To("cert.pem"),
KeyFile: ptr.To("key.pem"),
CAFile: ptr.To("ca.pem"),
CAKeyFile: ptr.To("ca-key.pem"),
CertFile: ptr.To("cert.pem"),
KeyFile: ptr.To("key.pem"),
},
},
}
Expand All @@ -67,6 +68,7 @@ var _ = Describe("TLSUtilsTest", func() {
Expect(secret.Labels[constant.KBAppComponentLabelKey]).Should(Equal(synthesizedComp.Name))
Expect(secret.StringData).ShouldNot(BeNil())
Expect(secret.StringData[*compDef.Spec.TLS.CAFile]).ShouldNot(BeZero())
Expect(secret.StringData[*compDef.Spec.TLS.CAKeyFile]).ShouldNot(BeZero())
Expect(secret.StringData[*compDef.Spec.TLS.CertFile]).ShouldNot(BeZero())
Expect(secret.StringData[*compDef.Spec.TLS.KeyFile]).ShouldNot(BeZero())
})
Expand Down
Loading