Skip to content

Commit

Permalink
[TLS] Mount tls cert/key + ca-bundle into /etc
Browse files Browse the repository at this point in the history
Jira: OSP-26299
  • Loading branch information
stuggi committed Oct 9, 2023
1 parent 7fe7fe1 commit 7daa69c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions modules/common/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"
)

// Service contains server-specific TLS secret
Expand Down Expand Up @@ -77,16 +78,23 @@ func (t *TLS) CreateVolumeMounts() []corev1.VolumeMount {

if t.Service != nil && t.Service.SecretName != "" {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "tls-certs",
MountPath: "/var/lib/config-data/tls-certificates",
Name: "tls-crt",
MountPath: "/etc/pki/tls/certs/tls.crt",
SubPath: "tls.crt",
ReadOnly: true,
})
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "tls-key",
MountPath: "/etc/pki/tls/certs/tls.key",
SubPath: "tls.key",
ReadOnly: true,
})
}

if t.Ca != nil && t.Ca.CaSecretName != "" {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "ca-certs",
MountPath: "/var/lib/config-data/ca-certificates",
MountPath: "/etc/pki/ca-trust/extracted/pem",
ReadOnly: true,
})
}
Expand All @@ -97,15 +105,14 @@ func (t *TLS) CreateVolumeMounts() []corev1.VolumeMount {
// CreateVolumes - add volume for TLS certificate and CA certificates
func (t *TLS) CreateVolumes() []corev1.Volume {
var volumes []corev1.Volume
mode := int32(0400)

if t.Service != nil && t.Service.SecretName != "" {
volumes = append(volumes, corev1.Volume{
Name: "tls-certs",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: t.Service.SecretName,
DefaultMode: &mode,
DefaultMode: ptr.To[int32](0440),
},
},
})
Expand All @@ -117,7 +124,7 @@ func (t *TLS) CreateVolumes() []corev1.Volume {
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: t.Ca.CaSecretName,
DefaultMode: &mode,
DefaultMode: ptr.To[int32](0444),
},
},
})
Expand Down
4 changes: 2 additions & 2 deletions modules/common/tls/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestCreateVolumeMounts(t *testing.T) {
name: "Only TLS Secret",
service: &Service{SecretName: "test-tls-secret"},
ca: &Ca{},
wantMountsLen: 1,
wantMountsLen: 2,
},
{
name: "Only CA Secret",
Expand All @@ -49,7 +49,7 @@ func TestCreateVolumeMounts(t *testing.T) {
name: "TLS and CA Secrets",
service: &Service{SecretName: "test-tls-secret"},
ca: &Ca{CaSecretName: "test-ca1"},
wantMountsLen: 2,
wantMountsLen: 3,
},
}

Expand Down

0 comments on commit 7daa69c

Please sign in to comment.