Skip to content

Commit

Permalink
[tlse] TLS database connection
Browse files Browse the repository at this point in the history
The my.cnf file gets added to the secret holding the service configs.
The content of my.cnf is centrally managed in the mariadb-operator
and retrieved calling db.GetDatabaseClientConfig(tlsCfg)

Depends-On: openstack-k8s-operators/mariadb-operator#190
Depends-On: openstack-k8s-operators/mariadb-operator#191

Jira: OSPRH-4547
  • Loading branch information
stuggi committed Feb 19, 2024
1 parent eec429b commit 32dae3f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
17 changes: 16 additions & 1 deletion controllers/keystoneapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1168,12 +1168,27 @@ func (r *KeystoneAPIReconciler) generateServiceConfigMaps(

cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(keystone.ServiceName), map[string]string{})

db, err := mariadbv1.GetDatabaseByName(
ctx,
h,
instance.Name,
)
if err != nil {
return err
}

tlsCfg, err := instance.Spec.TLS.API.Internal.ToService()
if err != nil {
return err
}

// customData hold any customization for the service.
// custom.conf is going to /etc/<service>/<service>.conf.d
// all other files get placed into /etc/<service> to allow overwrite of e.g. policy.json
// TODO: make sure custom.conf can not be overwritten
customData := map[string]string{
common.CustomServiceConfigFileName: instance.Spec.CustomServiceConfig,
"my.cnf": db.GetDatabaseClientConfig(tlsCfg),
}
for key, data := range instance.Spec.DefaultConfigOverwrite {
customData[key] = data
Expand All @@ -1192,7 +1207,7 @@ func (r *KeystoneAPIReconciler) generateServiceConfigMaps(
templateParameters := map[string]interface{}{
"memcachedServers": strings.Join(mc.Status.ServerList, ","),
"TransportURL": string(transportURLSecret.Data["transport_url"]),
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s",
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf",
instance.Spec.DatabaseUser,
string(ospSecret.Data[instance.Spec.PasswordSelectors.Database]),
instance.Status.DatabaseHostname,
Expand Down
6 changes: 6 additions & 0 deletions templates/keystoneapi/config/keystone-api-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
"dest": "/etc/keystone/",
"owner": "keystone:keystone",
"perm": "0700"
},
{
"source": "/var/lib/config-data/default/my.cnf",
"dest": "/etc/my.cnf",
"owner": "keystone",
"perm": "0600"
}
]
}
14 changes: 10 additions & 4 deletions tests/functional/keystoneapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,16 @@ var _ = Describe("Keystone controller", func() {
)
})

It("should create a Secret for keystone.conf", func() {
It("should create a Secret for keystone.conf and my.cnf", func() {
scrt := th.GetSecret(keystoneApiConfigDataName)
configData := string(scrt.Data["keystone.conf"])
Expect(configData).To(
ContainSubstring("memcache_servers=memcached-0.memcached:11211,memcached-1.memcached:11211,memcached-2.memcached:11211"))
Expect(configData).To(
ContainSubstring(fmt.Sprintf("connection=mysql+pymysql://keystone:12345678@hostname-for-openstack.%s.svc/keystone", namespace)))
ContainSubstring(fmt.Sprintf("connection=mysql+pymysql://keystone:12345678@hostname-for-openstack.%s.svc/keystone?read_default_file=/etc/my.cnf", namespace)))
configData = string(scrt.Data["my.cnf"])
Expect(configData).To(
ContainSubstring("[client]\nssl=0"))
})
It("should create a Secret for fernet keys", func() {
th.GetSecret(types.NamespacedName{
Expand Down Expand Up @@ -904,13 +907,16 @@ var _ = Describe("Keystone controller", func() {
th.AssertVolumeMountExists(caBundleSecretName.Name, "tls-ca-bundle.pem", j.Spec.Template.Spec.Containers[0].VolumeMounts)
})

It("should create a Secret for keystone.conf", func() {
It("should create a Secret for keystone.conf and my.cnf", func() {
scrt := th.GetSecret(keystoneApiConfigDataName)
configData := string(scrt.Data["keystone.conf"])
Expect(configData).To(
ContainSubstring("memcache_servers=memcached-0.memcached:11211,memcached-1.memcached:11211,memcached-2.memcached:11211"))
Expect(configData).To(
ContainSubstring(fmt.Sprintf("connection=mysql+pymysql://keystone:12345678@hostname-for-openstack.%s.svc/keystone", namespace)))
ContainSubstring(fmt.Sprintf("connection=mysql+pymysql://keystone:12345678@hostname-for-openstack.%s.svc/keystone?read_default_file=/etc/my.cnf", namespace)))
configData = string(scrt.Data["my.cnf"])
Expect(configData).To(
ContainSubstring("[client]\nssl-ca=/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem\nssl=1"))
})

It("it creates deployment with CA and service certs mounted", func() {
Expand Down

0 comments on commit 32dae3f

Please sign in to comment.