Skip to content

Commit e1260ff

Browse files
committed
Operator certificate handling refactor
- Move the ServiceServingCertCAFile var from options.go to util.go - Fix the MountPath of the OCp injected CA bundle and improve handling of the configmap - Readd the global refreshing transport to the S3 clients in prepareAWSBackingStore - Rename AddToRootCAs to CombineCaBundle for added clarity - Add an explanation about the current certificate flow and its implication on other pods, and their HTTP agents Signed-off-by: Ben <[email protected]>
1 parent 5f40461 commit e1260ff

File tree

5 files changed

+54
-18
lines changed

5 files changed

+54
-18
lines changed

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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,11 @@ func (r *Reconciler) SetDesiredCoreApp() error {
603603
util.MergeVolumeMountList(&c.VolumeMounts, &dbSecretVolumeMounts)
604604
}
605605

606-
if util.KubeCheckQuiet(r.CaBundleConf) {
606+
// we want to check that the cm exists and also that it has data in it
607+
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
607608
configMapVolumeMounts := []corev1.VolumeMount{{
608609
Name: r.CaBundleConf.Name,
609-
MountPath: "/etc/ocp-injected-ca-bundle.crt",
610+
MountPath: "/etc/ocp-injected-ca-bundle",
610611
ReadOnly: true,
611612
}}
612613
util.MergeVolumeMountList(&c.VolumeMounts, &configMapVolumeMounts)
@@ -686,10 +687,11 @@ func (r *Reconciler) SetDesiredCoreApp() error {
686687
Limits: logResourceList,
687688
}
688689
}
689-
if util.KubeCheckQuiet(r.CaBundleConf) {
690+
// we want to check that the cm exists and also that it has data in it
691+
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
690692
configMapVolumeMounts := []corev1.VolumeMount{{
691693
Name: r.CaBundleConf.Name,
692-
MountPath: "/etc/ocp-injected-ca-bundle.crt",
694+
MountPath: "/etc/ocp-injected-ca-bundle",
693695
ReadOnly: true,
694696
}}
695697
util.MergeVolumeMountList(&c.VolumeMounts, &configMapVolumeMounts)
@@ -729,7 +731,8 @@ func (r *Reconciler) SetDesiredCoreApp() error {
729731

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

732-
if util.KubeCheckQuiet(r.CaBundleConf) {
734+
// we want to check that the cm exists and also that it has data in it
735+
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
733736
configMapVolumes := []corev1.Volume{{
734737
Name: r.CaBundleConf.Name,
735738
VolumeSource: corev1.VolumeSource{

pkg/system/phase4_configuring.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ func (r *Reconciler) setDesiredEndpointMounts(podSpec *corev1.PodSpec, container
546546
util.MergeVolumeMountList(&container.VolumeMounts, &dbSecretVolumeMounts)
547547
}
548548

549-
if util.KubeCheckQuiet(r.CaBundleConf) {
549+
// we want to check that the cm exists and also that it has data in it
550+
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
550551
configMapVolumes := []corev1.Volume{{
551552
Name: r.CaBundleConf.Name,
552553
VolumeSource: corev1.VolumeSource{
@@ -564,7 +565,7 @@ func (r *Reconciler) setDesiredEndpointMounts(podSpec *corev1.PodSpec, container
564565
util.MergeVolumeList(&podSpec.Volumes, &configMapVolumes)
565566
configMapVolumeMounts := []corev1.VolumeMount{{
566567
Name: r.CaBundleConf.Name,
567-
MountPath: "/etc/ocp-injected-ca-bundle.crt",
568+
MountPath: "/etc/ocp-injected-ca-bundle",
568569
ReadOnly: true,
569570
}}
570571
util.MergeVolumeMountList(&container.VolumeMounts, &configMapVolumeMounts)
@@ -1108,6 +1109,10 @@ func (r *Reconciler) prepareAWSBackingStore() error {
11081109
*result.Credentials.SecretAccessKey,
11091110
*result.Credentials.SessionToken,
11101111
),
1112+
HTTPClient: &http.Client{
1113+
Transport: util.GlobalCARefreshingTransport,
1114+
Timeout: 10 * time.Second,
1115+
},
11111116
Region: &region,
11121117
}
11131118
} else { // handle AWS long-lived credentials (not STS)
@@ -1117,6 +1122,10 @@ func (r *Reconciler) prepareAWSBackingStore() error {
11171122
cloudCredsSecret.StringData["aws_secret_access_key"],
11181123
"",
11191124
),
1125+
HTTPClient: &http.Client{
1126+
Transport: util.GlobalCARefreshingTransport,
1127+
Timeout: 10 * time.Second,
1128+
},
11201129
Region: &region,
11211130
}
11221131
}

pkg/system/reconciler.go

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

7373
NooBaa *nbv1.NooBaa
7474
ServiceAccount *corev1.ServiceAccount
@@ -286,7 +286,7 @@ func NewReconciler(
286286
r.RouteS3.Name = r.ServiceS3.Name
287287
r.RouteSts.Name = r.ServiceSts.Name
288288
r.DeploymentEndpoint.Name = r.Request.Name + "-endpoint"
289-
r.CaBundleConf.Name = r.Request.Name + "-ca-inject"
289+
r.CaBundleConf.Name = "ocp-injected-ca-bundle"
290290
r.KedaScaled.Name = r.Request.Name
291291
r.AdapterHPA.Name = r.Request.Name + "-hpav2"
292292
r.BucketLoggingPVC.Name = r.Request.Name + "-bucket-logging-pvc"
@@ -409,9 +409,30 @@ func (r *Reconciler) Reconcile() (reconcile.Result, error) {
409409
}
410410
}
411411

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

pkg/util/util.go

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

8585
topologyConstraintsEnabledKubeVersion = "1.26.0"
8686
trueStr = "true"
87+
88+
// ServiceServingCertCAFile points to OCP default root CA list
89+
ServiceServingCertCAFile = "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt"
90+
91+
// InjectedBundleCertCAFile points to OCP root CA to be added to the default root CA list
92+
InjectedBundleCertCAFile = "/etc/ocp-injected-ca-bundle/ca-bundle.crt"
8793
)
8894

8995
// OAuth2Endpoints holds OAuth2 endpoints information.
@@ -143,15 +149,15 @@ var (
143149
}
144150
)
145151

146-
// AddToRootCAs adds a local cert file to Our GlobalCARefreshingTransport
147-
func AddToRootCAs(localCertFile string) error {
152+
// CombineCaBundle combines a local cert file to Our GlobalCARefreshingTransport
153+
func CombineCaBundle(localCertFile string) error {
148154
rootCAs, _ := x509.SystemCertPool()
149155
if rootCAs == nil {
150156
rootCAs = x509.NewCertPool()
151157
}
152158

153159
var certFiles = []string{
154-
"/etc/ocp-injected-ca-bundle.crt",
160+
InjectedBundleCertCAFile,
155161
localCertFile,
156162
}
157163

@@ -169,7 +175,7 @@ func AddToRootCAs(localCertFile string) error {
169175
}
170176

171177
// Trust the augmented cert pool in our client
172-
log.Infof("Successfuly appended %q to RootCAs", certFile)
178+
log.Infof("Successfully appended %q to RootCAs", certFile)
173179
}
174180
GlobalCARefreshingTransport.TLSClientConfig.RootCAs = rootCAs
175181
return nil

0 commit comments

Comments
 (0)