Skip to content

Commit 95952fe

Browse files
Add TLS support for Cassandra (#183)
Signed-off-by: sabbir <[email protected]>
1 parent 524e267 commit 95952fe

File tree

62 files changed

+1484
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1484
-74
lines changed

cassandra/kubedb_client_builder.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cassandra
22

33
import (
44
"context"
5+
"crypto/tls"
6+
"crypto/x509"
57
"errors"
68
"fmt"
79

@@ -76,10 +78,54 @@ func (o *KubeDBClientBuilder) GetCassandraClient() (*Client, error) {
7678
Password: password,
7779
}
7880
}
81+
if o.db.Spec.TLS != nil {
82+
tlsConfig, err := o.GetTLSConfig()
83+
if err != nil {
84+
return nil, err
85+
}
86+
cluster.SslOpts = &gocql.SslOptions{
87+
Config: tlsConfig,
88+
}
89+
}
7990
session, err := cluster.CreateSession()
8091
if err != nil {
8192
return nil, fmt.Errorf("unable to connect to Cassandra cluster: %v", err)
8293
}
8394

8495
return &Client{session}, nil
8596
}
97+
98+
func (o *KubeDBClientBuilder) GetTLSConfig() (*tls.Config, error) {
99+
var certSecret core.Secret
100+
err := o.kc.Get(o.ctx, types.NamespacedName{
101+
Namespace: o.db.Namespace,
102+
Name: o.db.GetCertSecretName(api.CassandraClientCert),
103+
}, &certSecret)
104+
if err != nil {
105+
klog.Error(err, "failed to get clientCert secret")
106+
return nil, err
107+
}
108+
109+
// get tls cert, clientCA and rootCA for tls config
110+
// use server cert ca for rootca as issuer ref is not taken into account
111+
clientCA := x509.NewCertPool()
112+
rootCA := x509.NewCertPool()
113+
114+
crt, err := tls.X509KeyPair(certSecret.Data[core.TLSCertKey], certSecret.Data[core.TLSPrivateKeyKey])
115+
if err != nil {
116+
klog.Error(err, "failed to create certificate for TLS config")
117+
return nil, err
118+
}
119+
clientCA.AppendCertsFromPEM(certSecret.Data[kubedb.CACert])
120+
rootCA.AppendCertsFromPEM(certSecret.Data[kubedb.CACert])
121+
122+
tlsConfig := &tls.Config{
123+
ServerName: o.db.ServiceName(),
124+
Certificates: []tls.Certificate{crt},
125+
ClientAuth: tls.RequireAndVerifyClientCert,
126+
ClientCAs: clientCA,
127+
RootCAs: rootCA,
128+
MaxVersion: tls.VersionTLS13,
129+
}
130+
return tlsConfig, nil
131+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ require (
3737
k8s.io/klog/v2 v2.130.1
3838
kmodules.xyz/client-go v0.32.6
3939
kmodules.xyz/custom-resources v0.32.0
40-
kubedb.dev/apimachinery v0.55.1-0.20250627044625-8ce5da487c01
40+
kubedb.dev/apimachinery v0.55.1-0.20250630051705-117e2306d4e2
4141
sigs.k8s.io/controller-runtime v0.20.4
4242
xorm.io/xorm v1.3.9
4343
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ kmodules.xyz/monitoring-agent-api v0.32.0 h1:cMQbWvbTc4JWeLI/zYE0HLefsdFYBzqvATL
546546
kmodules.xyz/monitoring-agent-api v0.32.0/go.mod h1:zgRKiJcuK7FOHy0Y1TsONRbJfgnPCs8t4Zh/6Afr+yU=
547547
kmodules.xyz/offshoot-api v0.32.0 h1:gogc5scSZe2JoXtZof72UGRl3Tit0kFaFRMkLLT1D8o=
548548
kmodules.xyz/offshoot-api v0.32.0/go.mod h1:tled7OxYZ3SkUJcrVFVVYyd+zXjsRSEm1R6Q3k4gcx0=
549-
kubedb.dev/apimachinery v0.55.1-0.20250627044625-8ce5da487c01 h1:mZ/amsE16eesPExYL6TZo8mc3CHzvcphtanSdmj3xbg=
550-
kubedb.dev/apimachinery v0.55.1-0.20250627044625-8ce5da487c01/go.mod h1:/GY1pDR/Y9C1qY83KI9DBHLS+JFO/TYq4zLxk/+UJy0=
549+
kubedb.dev/apimachinery v0.55.1-0.20250630051705-117e2306d4e2 h1:8qKjiiVduUTH14u5iu5Emg4sCf79NOo1ykOnXgbzWZU=
550+
kubedb.dev/apimachinery v0.55.1-0.20250630051705-117e2306d4e2/go.mod h1:iiqMOpMi8H4SZkD3vw5BS3V0t2UmIde4RnotjJ7VeNE=
551551
kubeops.dev/petset v0.0.10 h1:sNaqmHrD9bW7pcrWnwPoiQrKvdRwRX0BaRQc5QA78Bg=
552552
kubeops.dev/petset v0.0.10/go.mod h1:uHL83kggwmtSxdlIfxNbY2isV22iYV6YjADv0y+Z7YA=
553553
kubeops.dev/sidekick v0.0.11 h1:OydXdIH6cYSiWxKIWvrywk95WhhHSERkc7RNPOmTekc=

vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/cassandra_version_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ type CassandraVersionSpec struct {
7474

7575
// +optional
7676
UI []ChartInfo `json:"ui,omitempty"`
77+
78+
// update constraints
79+
UpdateConstraints UpdateConstraints `json:"updateConstraints,omitempty"`
7780
}
7881

7982
// CassandraVersionExporter is the image for the Cassandra exporter

vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/clickhouse_version_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ type ClickHouseVersionSpec struct {
7272

7373
// +optional
7474
UI []ChartInfo `json:"ui,omitempty"`
75+
76+
// update constraints
77+
UpdateConstraints UpdateConstraints `json:"updateConstraints,omitempty"`
7578
}
7679

7780
// ClickHouseVersionDatabase is the ClickHouse Database image

vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/druid_version_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type DruidVersionSpec struct {
6161
SecurityContext SecurityContext `json:"securityContext"`
6262
// +optional
6363
UI []ChartInfo `json:"ui,omitempty"`
64+
// update constraints
65+
UpdateConstraints UpdateConstraints `json:"updateConstraints,omitempty"`
6466
}
6567

6668
// DruidVersionDatabase is the Druid Database image

vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/ignite_version_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ type IgniteVersionSpec struct {
6363
SecurityContext IgniteSecurityContext `json:"securityContext"`
6464
// +optional
6565
UI []ChartInfo `json:"ui,omitempty"`
66+
67+
// update constraints
68+
UpdateConstraints UpdateConstraints `json:"updateConstraints,omitempty"`
6669
}
6770

6871
// IgniteSecurityContext is for the additional config for the DB container

vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/openapi_generated.go

Lines changed: 40 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/rabbitmqversion_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ type RabbitMQVersionSpec struct {
6363
SecurityContext SecurityContext `json:"securityContext"`
6464
// +optional
6565
UI []ChartInfo `json:"ui,omitempty"`
66+
// update constraints
67+
UpdateConstraints UpdateConstraints `json:"updateConstraints,omitempty"`
6668
}
6769

6870
// RabbitMQVersionDatabase is the RabbitMQ Database image

vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)