Skip to content

Commit 8d70a75

Browse files
Merge pull request #779 from stuggi/introduce_libvirt_ca
[tls] introduce dedicated CA for libvirt and update default cert durations
2 parents 5d262fb + 9bb7f2a commit 8d70a75

12 files changed

Lines changed: 246 additions & 39 deletions

‎apis/bases/core.openstack.org_openstackcontrolplanes.yaml‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17103,22 +17103,27 @@ spec:
1710317103
default:
1710417104
ingress:
1710517105
ca:
17106-
duration: 43800h
17106+
duration: 87600h
1710717107
cert:
17108-
duration: 8760h
17108+
duration: 10950h
1710917109
enabled: true
1711017110
podLevel:
1711117111
enabled: true
1711217112
internal:
1711317113
ca:
17114-
duration: 43800h
17114+
duration: 87600h
1711517115
cert:
17116-
duration: 8760h
17117-
ovn:
17116+
duration: 10950h
17117+
libvirt:
1711817118
ca:
17119+
duration: 87600h
17120+
cert:
1711917121
duration: 43800h
17122+
ovn:
17123+
ca:
17124+
duration: 87600h
1712017125
cert:
17121-
duration: 8760h
17126+
duration: 10950h
1712217127
properties:
1712317128
caBundleSecretName:
1712417129
type: string
@@ -17166,6 +17171,25 @@ spec:
1716617171
type: string
1716717172
type: object
1716817173
type: object
17174+
libvirt:
17175+
properties:
17176+
ca:
17177+
properties:
17178+
customIssuer:
17179+
type: string
17180+
duration:
17181+
type: string
17182+
renewBefore:
17183+
type: string
17184+
type: object
17185+
cert:
17186+
properties:
17187+
duration:
17188+
type: string
17189+
renewBefore:
17190+
type: string
17191+
type: object
17192+
type: object
1716917193
ovn:
1717017194
properties:
1717117195
ca:

‎apis/core/v1beta1/openstackcontrolplane_types.go‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const (
5656

5757
// OvnDbCaName -
5858
OvnDbCaName = tls.DefaultCAPrefix + "ovn"
59+
// LibvirtCaName -
60+
LibvirtCaName = tls.DefaultCAPrefix + "libvirt"
5961
)
6062

6163
// OpenStackControlPlaneSpec defines the desired state of OpenStackControlPlane
@@ -78,7 +80,7 @@ type OpenStackControlPlaneSpec struct {
7880

7981
// +kubebuilder:validation:Optional
8082
// +operator-sdk:csv:customresourcedefinitions:type=spec
81-
// +kubebuilder:default={ingress: {enabled: true, ca: {duration: "43800h"}, cert: {duration: "8760h"}}, podLevel: {enabled: true, internal:{ca: {duration: "43800h"}, cert: {duration: "8760h"}}, ovn: {ca: {duration: "43800h"}, cert: {duration: "8760h"}}}}
83+
// +kubebuilder:default={ingress: {enabled: true, ca: {duration: "87600h"}, cert: {duration: "10950h"}}, podLevel: {enabled: true, internal:{ca: {duration: "87600h"}, cert: {duration: "10950h"}}, libvirt: {ca: {duration: "87600h"}, cert: {duration: "43800h"}}, ovn: {ca: {duration: "87600h"}, cert: {duration: "10950h"}}}}
8284
// TLS - Parameters related to the TLS
8385
TLS TLSSection `json:"tls"`
8486

@@ -227,6 +229,11 @@ type TLSPodLevelConfig struct {
227229
// except OVN related CA and certs
228230
Internal CertSection `json:"internal,omitempty"`
229231

232+
// +kubebuilder:validation:Optional
233+
// +operator-sdk:csv:customresourcedefinitions:type=spec
234+
// Libvirt - CA used for libvirt/qemu services on OpenStackControlPlane and OpenStackDataplane
235+
Libvirt CertSection `json:"libvirt,omitempty"`
236+
230237
// +kubebuilder:validation:Optional
231238
// +operator-sdk:csv:customresourcedefinitions:type=spec
232239
// Ovn - CA used for all OVN services on OpenStackControlPlane and OpenStackDataplane
@@ -882,3 +889,13 @@ func (instance OpenStackControlPlane) GetOvnIssuer() string {
882889

883890
return OvnDbCaName
884891
}
892+
893+
// GetLibvirtIssuer - returns the libvirt CA issuer name or custom if configured
894+
func (instance OpenStackControlPlane) GetLibvirtIssuer() string {
895+
// use custom issuer if set
896+
if instance.Spec.TLS.PodLevel.Libvirt.Ca.IsCustomIssuer() {
897+
return *instance.Spec.TLS.PodLevel.Libvirt.Ca.CustomIssuer
898+
}
899+
900+
return LibvirtCaName
901+
}

‎apis/core/v1beta1/zz_generated.deepcopy.go‎

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

‎config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17103,22 +17103,27 @@ spec:
1710317103
default:
1710417104
ingress:
1710517105
ca:
17106-
duration: 43800h
17106+
duration: 87600h
1710717107
cert:
17108-
duration: 8760h
17108+
duration: 10950h
1710917109
enabled: true
1711017110
podLevel:
1711117111
enabled: true
1711217112
internal:
1711317113
ca:
17114-
duration: 43800h
17114+
duration: 87600h
1711517115
cert:
17116-
duration: 8760h
17117-
ovn:
17116+
duration: 10950h
17117+
libvirt:
1711817118
ca:
17119+
duration: 87600h
17120+
cert:
1711917121
duration: 43800h
17122+
ovn:
17123+
ca:
17124+
duration: 87600h
1712017125
cert:
17121-
duration: 8760h
17126+
duration: 10950h
1712217127
properties:
1712317128
caBundleSecretName:
1712417129
type: string
@@ -17166,6 +17171,25 @@ spec:
1716617171
type: string
1716717172
type: object
1716817173
type: object
17174+
libvirt:
17175+
properties:
17176+
ca:
17177+
properties:
17178+
customIssuer:
17179+
type: string
17180+
duration:
17181+
type: string
17182+
renewBefore:
17183+
type: string
17184+
type: object
17185+
cert:
17186+
properties:
17187+
duration:
17188+
type: string
17189+
renewBefore:
17190+
type: string
17191+
type: object
17192+
type: object
1716917193
ovn:
1717017194
properties:
1717117195
ca:

‎config/manifests/bases/openstack-operator.clusterserviceversion.yaml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ spec:
435435
- description: Cert - defines details for cert config
436436
displayName: Cert
437437
path: tls.podLevel.internal.cert
438+
- description: Libvirt - CA used for libvirt/qemu services on OpenStackControlPlane
439+
and OpenStackDataplane
440+
displayName: Libvirt
441+
path: tls.podLevel.libvirt
442+
- description: Ca - defines details for CA cert config
443+
displayName: Ca
444+
path: tls.podLevel.libvirt.ca
445+
- description: Cert - defines details for cert config
446+
displayName: Cert
447+
path: tls.podLevel.libvirt.cert
438448
- description: Ovn - CA used for all OVN services on OpenStackControlPlane and
439449
OpenStackDataplane
440450
displayName: Ovn

‎pkg/openstack/ca.go‎

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,79 @@ func ReconcileCAs(ctx context.Context, instance *corev1.OpenStackControlPlane, h
224224

225225
}
226226

227+
// create CA for libvirt
228+
issuerLabels = map[string]string{certmanager.RootCAIssuerLibvirtLabel: ""}
229+
if !instance.Spec.TLS.PodLevel.Libvirt.Ca.IsCustomIssuer() {
230+
ctrlResult, err = ensureRootCA(
231+
ctx,
232+
instance,
233+
helper,
234+
issuerReq,
235+
corev1.LibvirtCaName,
236+
issuerLabels,
237+
bundle,
238+
caOnlyBundle,
239+
instance.Spec.TLS.PodLevel.Libvirt.Ca.CertConfig,
240+
)
241+
if err != nil {
242+
return ctrlResult, err
243+
} else if (ctrlResult != ctrl.Result{}) {
244+
return ctrlResult, nil
245+
}
246+
} else {
247+
customIssuer := *instance.Spec.TLS.PodLevel.Libvirt.Ca.CustomIssuer
248+
// add CA labelselector to issuer
249+
caCertSecretName, err := addIssuerLabel(ctx, helper, customIssuer, instance.Namespace, issuerLabels)
250+
if err != nil {
251+
instance.Status.Conditions.Set(condition.FalseCondition(
252+
corev1.OpenStackControlPlaneCAReadyCondition,
253+
condition.ErrorReason,
254+
condition.SeverityWarning,
255+
corev1.OpenStackControlPlaneCAReadyErrorMessage,
256+
"issuer",
257+
customIssuer,
258+
err.Error()))
259+
if k8s_errors.IsNotFound(err) {
260+
timeout := time.Second * 10
261+
Log.Info(fmt.Sprintf("Custom Issuer %s not found, reconcile in %s", customIssuer, timeout.String()))
262+
263+
return ctrl.Result{RequeueAfter: timeout}, nil
264+
}
265+
266+
return ctrlResult, err
267+
}
268+
269+
caCert, ctrlResult, err := getCAFromSecret(ctx, instance, helper, caCertSecretName)
270+
if err != nil {
271+
return ctrl.Result{}, err
272+
} else if (ctrlResult != ctrl.Result{}) {
273+
return ctrlResult, nil
274+
}
275+
276+
ctrlResult, err = ensureCaBundles(
277+
instance,
278+
customIssuer,
279+
caCert,
280+
bundle,
281+
caOnlyBundle,
282+
)
283+
if err != nil {
284+
return ctrl.Result{}, err
285+
} else if (ctrlResult != ctrl.Result{}) {
286+
return ctrlResult, nil
287+
}
288+
}
289+
227290
// create CA for ovn
291+
issuerLabels = map[string]string{certmanager.RootCAIssuerOvnDBLabel: ""}
228292
if !instance.Spec.TLS.PodLevel.Ovn.Ca.IsCustomIssuer() {
229293
ctrlResult, err = ensureRootCA(
230294
ctx,
231295
instance,
232296
helper,
233297
issuerReq,
234298
corev1.OvnDbCaName,
235-
map[string]string{certmanager.RootCAIssuerOvnDBLabel: ""},
299+
issuerLabels,
236300
bundle,
237301
caOnlyBundle,
238302
instance.Spec.TLS.PodLevel.Ovn.Ca.CertConfig,
@@ -284,7 +348,6 @@ func ReconcileCAs(ctx context.Context, instance *corev1.OpenStackControlPlane, h
284348
} else if (ctrlResult != ctrl.Result{}) {
285349
return ctrlResult, nil
286350
}
287-
288351
}
289352

290353
instance.Status.Conditions.MarkTrue(corev1.OpenStackControlPlaneCAReadyCondition, corev1.OpenStackControlPlaneCAReadyMessage)

‎tests/functional/base_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type Names struct {
5353
RootCAPublicName types.NamespacedName
5454
RootCAInternalName types.NamespacedName
5555
RootCAOvnName types.NamespacedName
56+
RootCALibvirtName types.NamespacedName
5657
SelfSignedIssuerName types.NamespacedName
5758
CustomIssuerName types.NamespacedName
5859
CustomServiceCertSecretName types.NamespacedName
@@ -83,6 +84,9 @@ func CreateNames(openstackControlplaneName types.NamespacedName) Names {
8384
RootCAOvnName: types.NamespacedName{
8485
Namespace: openstackControlplaneName.Namespace,
8586
Name: "rootca-ovn"},
87+
RootCALibvirtName: types.NamespacedName{
88+
Namespace: openstackControlplaneName.Namespace,
89+
Name: "rootca-libvirt"},
8690
SelfSignedIssuerName: types.NamespacedName{
8791
Namespace: openstackControlplaneName.Namespace,
8892
Name: "selfsigned-issuer"},

‎tests/functional/openstackoperator_controller_test.go‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ var _ = Describe("OpenStackOperator controller", func() {
6161
DeferCleanup(k8sClient.Delete, ctx, CreateCertSecret(names.RootCAPublicName))
6262
DeferCleanup(k8sClient.Delete, ctx, CreateCertSecret(names.RootCAInternalName))
6363
DeferCleanup(k8sClient.Delete, ctx, CreateCertSecret(names.RootCAOvnName))
64+
DeferCleanup(k8sClient.Delete, ctx, CreateCertSecret(names.RootCALibvirtName))
6465
// create cert secrets for galera instances
6566
DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.DBCertName))
6667
DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.DBCell1CertName))
@@ -167,6 +168,19 @@ var _ = Describe("OpenStackOperator controller", func() {
167168
g.Expect(issuer).Should(Not(BeNil()))
168169
g.Expect(issuer.Spec.CA.SecretName).Should(Equal(names.RootCAOvnName.Name))
169170
}, timeout, interval).Should(Succeed())
171+
Eventually(func(g Gomega) {
172+
// ca cert
173+
cert := crtmgr.GetCert(names.RootCALibvirtName)
174+
g.Expect(cert).Should(Not(BeNil()))
175+
g.Expect(cert.Spec.CommonName).Should(Equal(names.RootCALibvirtName.Name))
176+
g.Expect(cert.Spec.IsCA).Should(BeTrue())
177+
g.Expect(cert.Spec.IssuerRef.Name).Should(Equal(names.SelfSignedIssuerName.Name))
178+
g.Expect(cert.Spec.SecretName).Should(Equal(names.RootCALibvirtName.Name))
179+
// issuer
180+
issuer := crtmgr.GetIssuer(names.RootCALibvirtName)
181+
g.Expect(issuer).Should(Not(BeNil()))
182+
g.Expect(issuer.Spec.CA.SecretName).Should(Equal(names.RootCALibvirtName.Name))
183+
}, timeout, interval).Should(Succeed())
170184
})
171185

172186
It("should create full ca bundle", func() {
@@ -176,6 +190,8 @@ var _ = Describe("OpenStackOperator controller", func() {
176190
crtmgr.GetIssuer(names.RootCAInternalName)
177191
crtmgr.GetCert(names.RootCAOvnName)
178192
crtmgr.GetIssuer(names.RootCAOvnName)
193+
crtmgr.GetCert(names.RootCALibvirtName)
194+
crtmgr.GetIssuer(names.RootCALibvirtName)
179195

180196
Eventually(func(g Gomega) {
181197
th.GetSecret(names.RootCAPublicName)
@@ -357,6 +373,19 @@ var _ = Describe("OpenStackOperator controller", func() {
357373
g.Expect(issuer).Should(Not(BeNil()))
358374
g.Expect(issuer.Spec.CA.SecretName).Should(Equal(names.RootCAOvnName.Name))
359375
}, timeout, interval).Should(Succeed())
376+
Eventually(func(g Gomega) {
377+
// ca cert
378+
cert := crtmgr.GetCert(names.RootCALibvirtName)
379+
g.Expect(cert).Should(Not(BeNil()))
380+
g.Expect(cert.Spec.CommonName).Should(Equal(names.RootCALibvirtName.Name))
381+
g.Expect(cert.Spec.IsCA).Should(BeTrue())
382+
g.Expect(cert.Spec.IssuerRef.Name).Should(Equal(names.SelfSignedIssuerName.Name))
383+
g.Expect(cert.Spec.SecretName).Should(Equal(names.RootCALibvirtName.Name))
384+
// issuer
385+
issuer := crtmgr.GetIssuer(names.RootCALibvirtName)
386+
g.Expect(issuer).Should(Not(BeNil()))
387+
g.Expect(issuer.Spec.CA.SecretName).Should(Equal(names.RootCALibvirtName.Name))
388+
}, timeout, interval).Should(Succeed())
360389

361390
th.ExpectCondition(
362391
names.OpenStackControlplaneName,
@@ -380,6 +409,8 @@ var _ = Describe("OpenStackOperator controller", func() {
380409
crtmgr.GetIssuer(names.RootCAInternalName)
381410
crtmgr.GetCert(names.RootCAOvnName)
382411
crtmgr.GetIssuer(names.RootCAOvnName)
412+
crtmgr.GetCert(names.RootCALibvirtName)
413+
crtmgr.GetIssuer(names.RootCALibvirtName)
383414

384415
Eventually(func(g Gomega) {
385416
th.GetSecret(names.RootCAPublicName)
@@ -549,6 +580,19 @@ var _ = Describe("OpenStackOperator controller", func() {
549580
g.Expect(issuer).Should(Not(BeNil()))
550581
g.Expect(issuer.Spec.CA.SecretName).Should(Equal(names.RootCAOvnName.Name))
551582
}, timeout, interval).Should(Succeed())
583+
Eventually(func(g Gomega) {
584+
// ca cert
585+
cert := crtmgr.GetCert(names.RootCALibvirtName)
586+
g.Expect(cert).Should(Not(BeNil()))
587+
g.Expect(cert.Spec.CommonName).Should(Equal(names.RootCALibvirtName.Name))
588+
g.Expect(cert.Spec.IsCA).Should(BeTrue())
589+
g.Expect(cert.Spec.IssuerRef.Name).Should(Equal(names.SelfSignedIssuerName.Name))
590+
g.Expect(cert.Spec.SecretName).Should(Equal(names.RootCALibvirtName.Name))
591+
// issuer
592+
issuer := crtmgr.GetIssuer(names.RootCALibvirtName)
593+
g.Expect(issuer).Should(Not(BeNil()))
594+
g.Expect(issuer.Spec.CA.SecretName).Should(Equal(names.RootCALibvirtName.Name))
595+
}, timeout, interval).Should(Succeed())
552596

553597
th.ExpectCondition(
554598
names.OpenStackControlplaneName,

0 commit comments

Comments
 (0)