Skip to content

Commit f418c73

Browse files
committed
Reapply "Operator certificate handling refactor"
This reverts commit aab2515.
1 parent 495deec commit f418c73

5 files changed

Lines changed: 55 additions & 18 deletions

File tree

pkg/options/options.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ const (
4848

4949
// SystemName is a constant as we want just a single system per namespace
5050
SystemName = "noobaa"
51-
52-
// ServiceServingCertCAFile points to OCP root CA to be added to the default root CA list
53-
ServiceServingCertCAFile = "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt"
5451
)
5552

5653
// Namespace is the target namespace for locating the noobaa system

pkg/system/phase2_creating.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,12 @@ func (r *Reconciler) SetDesiredCoreApp() error {
546546
if r.NooBaa.Spec.CoreResources != nil {
547547
c.Resources = *r.NooBaa.Spec.CoreResources
548548
}
549-
if util.KubeCheckQuiet(r.CaBundleConf) {
549+
550+
// we want to check that the cm exists and also that it has data in it
551+
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
550552
configMapVolumeMounts := []corev1.VolumeMount{{
551553
Name: r.CaBundleConf.Name,
552-
MountPath: "/etc/ocp-injected-ca-bundle.crt",
554+
MountPath: "/etc/ocp-injected-ca-bundle",
553555
ReadOnly: true,
554556
}}
555557
util.MergeVolumeMountList(&c.VolumeMounts, &configMapVolumeMounts)
@@ -629,10 +631,11 @@ func (r *Reconciler) SetDesiredCoreApp() error {
629631
Limits: logResourceList,
630632
}
631633
}
632-
if util.KubeCheckQuiet(r.CaBundleConf) {
634+
// we want to check that the cm exists and also that it has data in it
635+
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
633636
configMapVolumeMounts := []corev1.VolumeMount{{
634637
Name: r.CaBundleConf.Name,
635-
MountPath: "/etc/ocp-injected-ca-bundle.crt",
638+
MountPath: "/etc/ocp-injected-ca-bundle",
636639
ReadOnly: true,
637640
}}
638641
util.MergeVolumeMountList(&c.VolumeMounts, &configMapVolumeMounts)
@@ -672,7 +675,8 @@ func (r *Reconciler) SetDesiredCoreApp() error {
672675

673676
r.CoreApp.Spec.Template.Annotations["noobaa.io/configmap-hash"] = r.CoreAppConfig.Annotations["noobaa.io/configmap-hash"]
674677

675-
if util.KubeCheckQuiet(r.CaBundleConf) {
678+
// we want to check that the cm exists and also that it has data in it
679+
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
676680
configMapVolumes := []corev1.Volume{{
677681
Name: r.CaBundleConf.Name,
678682
VolumeSource: corev1.VolumeSource{

pkg/system/phase4_configuring.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ func (r *Reconciler) setDesiredEndpointMounts(podSpec *corev1.PodSpec, container
480480
podSpec.Volumes = r.DefaultDeploymentEndpoint.Volumes
481481
container.VolumeMounts = r.DefaultDeploymentEndpoint.Containers[0].VolumeMounts
482482

483-
if util.KubeCheckQuiet(r.CaBundleConf) {
483+
// we want to check that the cm exists and also that it has data in it
484+
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
484485
configMapVolumes := []corev1.Volume{{
485486
Name: r.CaBundleConf.Name,
486487
VolumeSource: corev1.VolumeSource{
@@ -498,7 +499,7 @@ func (r *Reconciler) setDesiredEndpointMounts(podSpec *corev1.PodSpec, container
498499
util.MergeVolumeList(&podSpec.Volumes, &configMapVolumes)
499500
configMapVolumeMounts := []corev1.VolumeMount{{
500501
Name: r.CaBundleConf.Name,
501-
MountPath: "/etc/ocp-injected-ca-bundle.crt",
502+
MountPath: "/etc/ocp-injected-ca-bundle",
502503
ReadOnly: true,
503504
}}
504505
util.MergeVolumeMountList(&container.VolumeMounts, &configMapVolumeMounts)
@@ -1011,6 +1012,10 @@ func (r *Reconciler) prepareAWSBackingStore() error {
10111012
*result.Credentials.SecretAccessKey,
10121013
*result.Credentials.SessionToken,
10131014
),
1015+
HTTPClient: &http.Client{
1016+
Transport: util.GlobalCARefreshingTransport,
1017+
Timeout: 10 * time.Second,
1018+
},
10141019
Region: &region,
10151020
}
10161021
} else { // handle AWS long-lived credentials (not STS)
@@ -1020,6 +1025,10 @@ func (r *Reconciler) prepareAWSBackingStore() error {
10201025
cloudCredsSecret.StringData["aws_secret_access_key"],
10211026
"",
10221027
),
1028+
HTTPClient: &http.Client{
1029+
Transport: util.GlobalCARefreshingTransport,
1030+
Timeout: 10 * time.Second,
1031+
},
10231032
Region: &region,
10241033
}
10251034
}

pkg/system/reconciler.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type Reconciler struct {
6666
OperatorVersion string
6767
OAuthEndpoints *util.OAuth2Endpoints
6868
PostgresConnectionString string
69-
ApplyCAsToPods string
69+
ApplyCAsToPods string // the path that will be applied to the core and endpoint pods in NODE_EXTRA_CA_CERTS
7070

7171
NooBaa *nbv1.NooBaa
7272
ServiceAccount *corev1.ServiceAccount
@@ -273,7 +273,7 @@ func NewReconciler(
273273
r.RouteS3.Name = r.ServiceS3.Name
274274
r.RouteSts.Name = r.ServiceSts.Name
275275
r.DeploymentEndpoint.Name = r.Request.Name + "-endpoint"
276-
r.CaBundleConf.Name = r.Request.Name + "-ca-inject"
276+
r.CaBundleConf.Name = "ocp-injected-ca-bundle"
277277
r.KedaScaled.Name = r.Request.Name
278278
r.AdapterHPA.Name = r.Request.Name + "-hpav2"
279279
r.BucketLoggingPVC.Name = r.Request.Name + "-bucket-logging-pvc"
@@ -394,9 +394,30 @@ func (r *Reconciler) Reconcile() (reconcile.Result, error) {
394394
}
395395
}
396396

397-
err = util.AddToRootCAs(options.ServiceServingCertCAFile)
397+
/*
398+
This code is problematic due to the way other parts of the product work.
399+
On the core side, get_unsecured_agent() relies on the presence of the NODE_EXTRA_CA_CERTS
400+
environment variable to determine whether an HTTP or HTTPS client should be used.
401+
402+
At the time of writing this comment, if the environment variable is not set, an HTTP agent
403+
will be used for *all* S3-compatible domains that aren't under amazonaws.com - including
404+
domains that are already present by default in the system's certificate store.
405+
406+
Forcing the environment variable to always be set leads to a different problem where
407+
some things might fail - e.g. the admission tests that rely on creating a namespacestore
408+
that points towards NooBaa's (self-signed) S3 service. In that case, the HTTPS agent fails
409+
due to the self-signed certificate.
410+
411+
Also, note that the code that combines certificates only applies to the operator.
412+
Based on whether the certificate bundling was successful, the operator will set the value of
413+
NODE_EXTRA_CA_CERTS in endpoints and core pods to point to *the system generated service-serving certs*.
414+
415+
At the time of writing, user certs are not included at any point.
416+
*/
417+
418+
err = util.CombineCaBundle(util.ServiceServingCertCAFile)
398419
if err == nil {
399-
r.ApplyCAsToPods = options.ServiceServingCertCAFile
420+
r.ApplyCAsToPods = util.ServiceServingCertCAFile
400421
} else if !os.IsNotExist(err) {
401422
log.Errorf("❌ NooBaa %q failed to add root CAs to system default", r.NooBaa.Name)
402423
res.RequeueAfter = 3 * time.Second

pkg/util/util.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ const (
8181

8282
topologyConstraintsEnabledKubeVersion = "1.26.0"
8383
trueStr = "true"
84+
85+
// ServiceServingCertCAFile points to OCP default root CA list
86+
ServiceServingCertCAFile = "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt"
87+
88+
// InjectedBundleCertCAFile points to OCP root CA to be added to the default root CA list
89+
InjectedBundleCertCAFile = "/etc/ocp-injected-ca-bundle/ca-bundle.crt"
8490
)
8591

8692
// OAuth2Endpoints holds OAuth2 endpoints information.
@@ -140,15 +146,15 @@ var (
140146
}
141147
)
142148

143-
// AddToRootCAs adds a local cert file to Our GlobalCARefreshingTransport
144-
func AddToRootCAs(localCertFile string) error {
149+
// CombineCaBundle combines a local cert file to Our GlobalCARefreshingTransport
150+
func CombineCaBundle(localCertFile string) error {
145151
rootCAs, _ := x509.SystemCertPool()
146152
if rootCAs == nil {
147153
rootCAs = x509.NewCertPool()
148154
}
149155

150156
var certFiles = []string{
151-
"/etc/ocp-injected-ca-bundle.crt",
157+
InjectedBundleCertCAFile,
152158
localCertFile,
153159
}
154160

@@ -166,7 +172,7 @@ func AddToRootCAs(localCertFile string) error {
166172
}
167173

168174
// Trust the augmented cert pool in our client
169-
log.Infof("Successfuly appended %q to RootCAs", certFile)
175+
log.Infof("Successfully appended %q to RootCAs", certFile)
170176
}
171177
GlobalCARefreshingTransport.TLSClientConfig.RootCAs = rootCAs
172178
return nil

0 commit comments

Comments
 (0)