Skip to content

Commit 937f88a

Browse files
author
Mauricio Harley
committed
Barbican Support for Luna HSM
Signed-off-by: Mauricio Harley <[email protected]>
1 parent 5c432fb commit 937f88a

File tree

5 files changed

+93
-13
lines changed

5 files changed

+93
-13
lines changed

api/v1beta1/common_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ type BarbicanPKCS11Template struct {
165165
HSMCertificates map[string]string `json:"hsmCertificates"`
166166

167167
// +kubebuilder:validation:Optional
168+
// +kubebuilder:validation:Items:Enum=trustway;luna;ncipher
168169
// A string containing the HSM type (currently supported: "trustway", "luna", "ncipher").
169170
HSMType string `json:"hsmType"`
170171
}

pkg/barbicanapi/deployment.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
77
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
88
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
9+
maps "golang.org/x/exp/maps"
910
appsv1 "k8s.io/api/apps/v1"
1011
corev1 "k8s.io/api/core/v1"
1112
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -110,6 +111,47 @@ func Deployment(
110111
}
111112
}
112113

114+
// Considering the existence of an HSM.
115+
if instance.Spec.PKCS11.HSMEnabled {
116+
if instance.Spec.PKCS11.HSMType == "luna" {
117+
hsmVolume := corev1.Volume{
118+
Name: "hsm-luna-certificates",
119+
VolumeSource: corev1.VolumeSource{
120+
Secret: &corev1.SecretVolumeSource{
121+
DefaultMode: &config0644AccessMode,
122+
SecretName: maps.Keys(instance.Spec.PKCS11.HSMCertificates)[0],
123+
},
124+
},
125+
}
126+
apiVolumes = append(apiVolumes, hsmVolume)
127+
hsmMountPath := maps.Values(instance.Spec.PKCS11.HSMCertificates)[0]
128+
if string(hsmMountPath[len(hsmMountPath)-1]) != "/" {
129+
hsmMountPath = hsmMountPath + "/"
130+
}
131+
hsmMountPoint := []corev1.VolumeMount{
132+
{
133+
Name: "hsm-luna-certificates",
134+
MountPath: hsmMountPath + instance.Spec.PKCS11.HSMClientAddress + ".pem",
135+
SubPath: instance.Spec.PKCS11.HSMClientAddress + ".pem",
136+
ReadOnly: true,
137+
},
138+
{
139+
Name: "hsm-luna-certificates",
140+
MountPath: hsmMountPath + instance.Spec.PKCS11.HSMClientAddress + "Key.pem",
141+
SubPath: instance.Spec.PKCS11.HSMClientAddress + "Key.pem",
142+
ReadOnly: true,
143+
},
144+
{
145+
Name: "hsm-luna-certificates",
146+
MountPath: hsmMountPath + instance.Spec.PKCS11.HSMIPAddress + "Cert.pem",
147+
SubPath: instance.Spec.PKCS11.HSMIPAddress + "Cert.pem",
148+
ReadOnly: true,
149+
},
150+
}
151+
apiVolumeMounts = append(apiVolumeMounts, hsmMountPoint...)
152+
}
153+
}
154+
113155
deployment := &appsv1.Deployment{
114156
ObjectMeta: metav1.ObjectMeta{
115157
Name: fmt.Sprintf("%s-api", instance.Name),

pkg/barbicanworker/deployment.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
7+
maps "golang.org/x/exp/maps"
78
appsv1 "k8s.io/api/apps/v1"
89
corev1 "k8s.io/api/core/v1"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -86,6 +87,47 @@ func Deployment(
8687
workerVolumeMounts = append(workerVolumeMounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
8788
}
8889

90+
// Considering the existence of an HSM.
91+
if instance.Spec.PKCS11.HSMEnabled {
92+
if instance.Spec.PKCS11.HSMType == "luna" {
93+
hsmVolume := corev1.Volume{
94+
Name: "hsm-luna-certificates",
95+
VolumeSource: corev1.VolumeSource{
96+
Secret: &corev1.SecretVolumeSource{
97+
DefaultMode: &config0644AccessMode,
98+
SecretName: maps.Keys(instance.Spec.PKCS11.HSMCertificates)[0],
99+
},
100+
},
101+
}
102+
workerVolumes = append(workerVolumes, hsmVolume)
103+
hsmMountPath := maps.Values(instance.Spec.PKCS11.HSMCertificates)[0]
104+
if string(hsmMountPath[len(hsmMountPath)-1]) != "/" {
105+
hsmMountPath = hsmMountPath + "/"
106+
}
107+
hsmMountPoint := []corev1.VolumeMount{
108+
{
109+
Name: "hsm-luna-certificates",
110+
MountPath: hsmMountPath + instance.Spec.PKCS11.HSMClientAddress + ".pem",
111+
SubPath: instance.Spec.PKCS11.HSMClientAddress + ".pem",
112+
ReadOnly: true,
113+
},
114+
{
115+
Name: "hsm-luna-certificates",
116+
MountPath: hsmMountPath + instance.Spec.PKCS11.HSMClientAddress + "Key.pem",
117+
SubPath: instance.Spec.PKCS11.HSMClientAddress + "Key.pem",
118+
ReadOnly: true,
119+
},
120+
{
121+
Name: "hsm-luna-certificates",
122+
MountPath: hsmMountPath + instance.Spec.PKCS11.HSMIPAddress + "Cert.pem",
123+
SubPath: instance.Spec.PKCS11.HSMIPAddress + "Cert.pem",
124+
ReadOnly: true,
125+
},
126+
}
127+
workerVolumeMounts = append(workerVolumeMounts, hsmMountPoint...)
128+
}
129+
}
130+
89131
deployment := &appsv1.Deployment{
90132
ObjectMeta: metav1.ObjectMeta{
91133
Name: fmt.Sprintf("%s-worker", instance.Name),

templates/barbican/config/Chrystoki-conf.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

templates/barbican/config/barbican-api-config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@
7777
"perm": "0600",
7878
"optional": true,
7979
"merge": true
80+
},
81+
{
82+
"source": "/var/lib/config-data/default/Crystoki.conf",
83+
"dest": "{{ .HSMLibraryPath }}/config/Crystoki.conf",
84+
"owner": "barbican",
85+
"perm": "0600",
86+
"optional": true,
87+
"merge": true
8088
}
8189
],
8290
"permissions": [

0 commit comments

Comments
 (0)