Skip to content

Commit 5ac38a6

Browse files
Merge pull request #621 from lmiccini/mtls_cronjob
Fix Memcached MTLS certs mountpaths for jobs not using kolla
2 parents b498778 + 96da1f7 commit 5ac38a6

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

controllers/keystoneapi_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ func (r *KeystoneAPIReconciler) reconcileInit(
514514
helper *helper.Helper,
515515
serviceLabels map[string]string,
516516
serviceAnnotations map[string]string,
517+
memcached *memcachedv1.Memcached,
517518
) (ctrl.Result, error) {
518519
Log := r.GetLogger(ctx)
519520
Log.Info("Reconciling Service init")
@@ -702,7 +703,7 @@ func (r *KeystoneAPIReconciler) reconcileInit(
702703
//
703704
// BootStrap Job
704705
//
705-
jobDef = keystone.BootstrapJob(instance, serviceLabels, serviceAnnotations, instance.Status.APIEndpoints)
706+
jobDef = keystone.BootstrapJob(instance, serviceLabels, serviceAnnotations, instance.Status.APIEndpoints, memcached)
706707
bootstrapjob := job.NewJob(
707708
jobDef,
708709
keystonev1.BootstrapHash,
@@ -1070,7 +1071,7 @@ func (r *KeystoneAPIReconciler) reconcileNormal(
10701071
}
10711072

10721073
// Handle service init
1073-
ctrlResult, err := r.reconcileInit(ctx, instance, helper, serviceLabels, serviceAnnotations)
1074+
ctrlResult, err := r.reconcileInit(ctx, instance, helper, serviceLabels, serviceAnnotations, memcached)
10741075
if err != nil {
10751076
return ctrlResult, err
10761077
} else if (ctrlResult != ctrl.Result{}) {

pkg/keystone/bootstrap.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ limitations under the License.
1616
package keystone
1717

1818
import (
19+
memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
1920
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
2021

2122
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
23+
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
2224

2325
batchv1 "k8s.io/api/batch/v1"
2426
corev1 "k8s.io/api/core/v1"
@@ -36,6 +38,7 @@ func BootstrapJob(
3638
labels map[string]string,
3739
annotations map[string]string,
3840
endpoints map[string]string,
41+
memcached *memcachedv1.Memcached,
3942
) *batchv1.Job {
4043
runAsUser := int64(0)
4144

@@ -70,6 +73,27 @@ func BootstrapJob(
7073
volumeMounts = append(volumeMounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
7174
}
7275

76+
// add MTLS cert if defined
77+
if memcached.GetMemcachedMTLSSecret() != "" {
78+
volumes = append(volumes, memcached.CreateMTLSVolume())
79+
volumeMounts = append(volumeMounts, corev1.VolumeMount{
80+
Name: *memcached.Spec.TLS.MTLS.AuthCertSecret.SecretName,
81+
MountPath: "/etc/pki/tls/certs/mtls.crt",
82+
SubPath: tls.CertKey,
83+
ReadOnly: true,
84+
}, corev1.VolumeMount{
85+
Name: *memcached.Spec.TLS.MTLS.AuthCertSecret.SecretName,
86+
MountPath: "/etc/pki/tls/private/mtls.key",
87+
SubPath: tls.PrivateKey,
88+
ReadOnly: true,
89+
}, corev1.VolumeMount{
90+
Name: *memcached.Spec.TLS.MTLS.AuthCertSecret.SecretName,
91+
MountPath: "/etc/pki/tls/certs/mtls-ca.crt",
92+
SubPath: tls.CAKey,
93+
ReadOnly: true,
94+
})
95+
}
96+
7397
job := &batchv1.Job{
7498
ObjectMeta: metav1.ObjectMeta{
7599
Name: ServiceName + "-bootstrap",

pkg/keystone/cronjob.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
2020
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
2121
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
22+
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
2223

2324
batchv1 "k8s.io/api/batch/v1"
2425
corev1 "k8s.io/api/core/v1"
@@ -59,8 +60,26 @@ func CronJob(
5960

6061
// add MTLS cert if defined
6162
if memcached.GetMemcachedMTLSSecret() != "" {
62-
volumes = append(volumes, memcached.CreateMTLSVolume())
63-
volumeMounts = append(volumeMounts, memcached.CreateMTLSVolumeMounts(nil, nil)...)
63+
mtlsVolume := memcached.CreateMTLSVolume()
64+
// Set file permissions to 0440
65+
mtlsVolume.Secret.DefaultMode = func() *int32 { mode := int32(0440); return &mode }()
66+
volumes = append(volumes, mtlsVolume)
67+
volumeMounts = append(volumeMounts, corev1.VolumeMount{
68+
Name: *memcached.Spec.TLS.MTLS.AuthCertSecret.SecretName,
69+
MountPath: "/etc/pki/tls/certs/mtls.crt",
70+
SubPath: tls.CertKey,
71+
ReadOnly: true,
72+
}, corev1.VolumeMount{
73+
Name: *memcached.Spec.TLS.MTLS.AuthCertSecret.SecretName,
74+
MountPath: "/etc/pki/tls/private/mtls.key",
75+
SubPath: tls.PrivateKey,
76+
ReadOnly: true,
77+
}, corev1.VolumeMount{
78+
Name: *memcached.Spec.TLS.MTLS.AuthCertSecret.SecretName,
79+
MountPath: "/etc/pki/tls/certs/mtls-ca.crt",
80+
SubPath: tls.CAKey,
81+
ReadOnly: true,
82+
})
6483
}
6584

6685
cronjob := &batchv1.CronJob{
@@ -98,6 +117,9 @@ func CronJob(
98117
Volumes: volumes,
99118
RestartPolicy: corev1.RestartPolicyNever,
100119
ServiceAccountName: instance.RbacResourceName(),
120+
SecurityContext: &corev1.PodSecurityContext{
121+
FSGroup: func() *int64 { gid := int64(42425); return &gid }(), // keystone group
122+
},
101123
},
102124
},
103125
},

0 commit comments

Comments
 (0)