Skip to content

Commit 22c635d

Browse files
authored
Merge pull request #627 from harshad16/include-service-ca
[RHOAIENG-363] Include service-ca cert bundle to workbench-ca bundle
2 parents 0b1dcd8 + b35f148 commit 22c635d

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

components/odh-notebook-controller/controllers/notebook_controller.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ const (
5656
AnnotationLogoutUrl = "notebooks.opendatahub.io/oauth-logout-url"
5757
)
5858

59+
const (
60+
OdhConfigMapName = "odh-trusted-ca-bundle" // Use ODH Trusted CA Bundle Contains ca-bundle.crt and odh-ca-bundle.crt
61+
SelfSignedConfigMapName = "kube-root-ca.crt" // Self-Signed Certs Contains ca.crt
62+
ServiceCAConfigMapName = "openshift-service-ca.crt" // Service CA Bundle Contains service-ca.crt
63+
)
64+
5965
// OpenshiftNotebookReconciler holds the controller configuration.
6066
type OpenshiftNotebookReconciler struct {
6167
client.Client
@@ -285,14 +291,13 @@ func (r *OpenshiftNotebookReconciler) CreateNotebookCertConfigMap(notebook *nbv1
285291
// Initialize logger format
286292
log := r.Log.WithValues("notebook", notebook.Name, "namespace", notebook.Namespace)
287293

288-
rootCertPool := [][]byte{} // Root certificate pool
289-
odhConfigMapName := "odh-trusted-ca-bundle" // Use ODH Trusted CA Bundle Contains ca-bundle.crt and odh-ca-bundle.crt
290-
selfSignedConfigMapName := "kube-root-ca.crt" // Self-Signed Certs Contains ca.crt
294+
rootCertPool := [][]byte{} // Root certificate pool
291295

292-
configMapList := []string{odhConfigMapName, selfSignedConfigMapName}
296+
configMapList := []string{OdhConfigMapName, SelfSignedConfigMapName, ServiceCAConfigMapName}
293297
configMapFileNames := map[string][]string{
294-
odhConfigMapName: {"ca-bundle.crt", "odh-ca-bundle.crt"},
295-
selfSignedConfigMapName: {"ca.crt"},
298+
OdhConfigMapName: {"ca-bundle.crt", "odh-ca-bundle.crt"},
299+
SelfSignedConfigMapName: {"ca.crt"},
300+
ServiceCAConfigMapName: {"service-ca.crt"},
296301
}
297302

298303
for _, configMapName := range configMapList {
@@ -301,7 +306,7 @@ func (r *OpenshiftNotebookReconciler) CreateNotebookCertConfigMap(notebook *nbv1
301306
if err := r.Get(ctx, client.ObjectKey{Namespace: notebook.Namespace, Name: configMapName}, configMap); err != nil {
302307
// if configmap odh-trusted-ca-bundle is not found,
303308
// no need to create the workbench-trusted-ca-bundle
304-
if apierrs.IsNotFound(err) && configMapName == odhConfigMapName {
309+
if apierrs.IsNotFound(err) && configMapName == OdhConfigMapName {
305310
return nil
306311
}
307312
log.Info("Unable to fetch ConfigMap", "configMap", configMapName)
@@ -500,9 +505,9 @@ func (r *OpenshiftNotebookReconciler) SetupWithManager(mgr ctrl.Manager) error {
500505
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request {
501506
log := r.Log.WithValues("namespace", o.GetNamespace(), "name", o.GetName())
502507

503-
// If the ConfigMap is odh-trusted-ca-bundle or kube-root-ca.crt
508+
// If the ConfigMap name matches on of our interested ConfigMaps
504509
// trigger a reconcile event for first notebook in the namespace
505-
if o.GetName() == "odh-trusted-ca-bundle" {
510+
if o.GetName() == OdhConfigMapName || o.GetName() == SelfSignedConfigMapName || o.GetName() == ServiceCAConfigMapName {
506511
// List all the notebooks in the namespace and trigger a reconcile event
507512
var nbList nbv1.NotebookList
508513
if err := r.List(ctx, &nbList, client.InNamespace(o.GetNamespace())); err != nil {

components/odh-notebook-controller/controllers/notebook_controller_test.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,32 @@ var _ = Describe("The Openshift Notebook controller", func() {
263263
"odh-ca-bundle.crt": "-----BEGIN CERTIFICATE-----\nMIGrMF+gAwIBAgIBATAFBgMrZXAwADAeFw0yNDExMTMyMzI2NTlaFw0yNTExMTMy\nMzI2NTlaMAAwKjAFBgMrZXADIQB/v02zcoIIcuan/8bd7cvrBuCGTuVZBrYr1RdA\n0k58yzAFBgMrZXADQQBKsL1tkpOZ6NW+zEX3mD7bhmhxtODQHnANMXEXs0aljWrm\nAxDrLdmzsRRYFYxe23OdXhWqPs8SfO8EZWEvXoME\n-----END CERTIFICATE-----",
264264
})
265265

266+
serviceCACertBundle := &corev1.ConfigMap{
267+
ObjectMeta: metav1.ObjectMeta{
268+
Name: "openshift-service-ca.crt",
269+
Namespace: "default",
270+
// Annotations: map[string]string{
271+
// "service.beta.openshift.io/inject-cabundle": "true",
272+
// },
273+
},
274+
Data: map[string]string{
275+
"service-ca.crt": "-----BEGIN CERTIFICATE-----\nMIIBATCBtKADAgECAgEBMAUGAytlcDAAMB4XDTI1MDYxNjE2MTg0MVoXDTI2MDYx\nNjE2MTg0MVowADAqMAUGAytlcAMhAP7g8UxhoFPZXQiy4sSbOsLrlXq2RgFTzQOD\nj8O8e9qmo1MwUTAdBgNVHQ4EFgQUTCWpJDtMDVadBlVpkVTiLnCihqMwHwYDVR0j\nBBgwFoAUTCWpJDtMDVadBlVpkVTiLnCihqMwDwYDVR0TAQH/BAUwAwEB/zAFBgMr\nZXADQQDKpiapbn7ub7/hT7Whad9wbvIY8wXrWojgZXXbWaMQFV8i8GW7QN4w/C1p\nB8i0efvecoLP/mqmXNyl7KgTnC4D\n-----END CERTIFICATE-----",
276+
},
277+
}
278+
266279
// Create the ConfigMap
267280
Expect(cli.Create(ctx, trustedCACertBundle)).Should(Succeed())
281+
Expect(cli.Create(ctx, serviceCACertBundle)).Should(Succeed())
268282
defer func() {
269283
// Clean up the ConfigMap after the test
270284
if err := cli.Delete(ctx, trustedCACertBundle); err != nil {
271285
// Log the error without failing the test
272286
logger.Info("Error occurred during deletion of ConfigMap: %v", err)
273287
}
288+
if err := cli.Delete(ctx, serviceCACertBundle); err != nil {
289+
// Log the error without failing the test
290+
logger.Info("Error occurred during deletion of ConfigMap: %v", err)
291+
}
274292
}()
275293

276294
By("By creating a new Notebook")
@@ -308,12 +326,12 @@ var _ = Describe("The Openshift Notebook controller", func() {
308326
Expect(notebook.Spec.Template.Spec.Volumes).To(ContainElement(expectedVolume))
309327

310328
// Check the content in workbench-trusted-ca-bundle matches what we expect:
311-
// - have 2 certificates there in ca-bundle.crt
312-
// - both certificates are valid
329+
// - have 3 certificates there in ca-bundle.crt
330+
// - all certificates are valid
313331
// TODO(RHOAIENG-15907): adding sleep to reduce flakiness
314332
time.Sleep(2 * time.Second)
315333
configMapName := "workbench-trusted-ca-bundle"
316-
checkCertConfigMap(ctx, notebook.Namespace, configMapName, "ca-bundle.crt", 2)
334+
checkCertConfigMap(ctx, notebook.Namespace, configMapName, "ca-bundle.crt", 3)
317335
})
318336

319337
})
@@ -537,12 +555,12 @@ var _ = Describe("The Openshift Notebook controller", func() {
537555
Expect(notebook.Spec.Template.Spec.Volumes).To(ContainElement(expectedVolume))
538556

539557
// Check the content in workbench-trusted-ca-bundle matches what we expect:
540-
// - have 2 certificates there in ca-bundle.crt
541-
// - both certificates are valid
558+
// - have 3 certificates there in ca-bundle.crt
559+
// - all certificates are valid
542560
// TODO(RHOAIENG-15907): adding sleep to reduce flakiness
543561
time.Sleep(2 * time.Second)
544562
configMapName := "workbench-trusted-ca-bundle"
545-
checkCertConfigMap(ctx, notebook.Namespace, configMapName, "ca-bundle.crt", 2)
563+
checkCertConfigMap(ctx, notebook.Namespace, configMapName, "ca-bundle.crt", 3)
546564
})
547565
})
548566

0 commit comments

Comments
 (0)