Skip to content

CA Paths Fixes #1587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ const (

// SystemName is a constant as we want just a single system per namespace
SystemName = "noobaa"

// ServiceServingCertCAFile points to OCP root CA to be added to the default root CA list
ServiceServingCertCAFile = "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt"
)

// Namespace is the target namespace for locating the noobaa system
Expand Down
15 changes: 9 additions & 6 deletions pkg/system/phase2_creating.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (r *Reconciler) setDesiredCoreEnv(c *corev1.Container) {
c.Env[j].Value = postgresSecretMountPath + "/db_url"

case "NODE_EXTRA_CA_CERTS":
c.Env[j].Value = r.ApplyCAsToPods
c.Env[j].Value = r.UserCertBundlePath
case "GUARANTEED_LOGS_PATH":
if r.NooBaa.Spec.BucketLogging.LoggingType == nbv1.BucketLoggingTypeGuaranteed {
c.Env[j].Value = r.BucketLoggingVolumeMount
Expand Down Expand Up @@ -575,10 +575,11 @@ func (r *Reconciler) SetDesiredCoreApp() error {
util.MergeVolumeMountList(&c.VolumeMounts, &dbSecretVolumeMounts)
}

if util.KubeCheckQuiet(r.CaBundleConf) {
// we want to check that the cm exists and also that it has data in it
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
configMapVolumeMounts := []corev1.VolumeMount{{
Name: r.CaBundleConf.Name,
MountPath: "/etc/ocp-injected-ca-bundle.crt",
MountPath: "/etc/ocp-injected-ca-bundle",
ReadOnly: true,
}}
util.MergeVolumeMountList(&c.VolumeMounts, &configMapVolumeMounts)
Expand Down Expand Up @@ -658,10 +659,11 @@ func (r *Reconciler) SetDesiredCoreApp() error {
Limits: logResourceList,
}
}
if util.KubeCheckQuiet(r.CaBundleConf) {
// we want to check that the cm exists and also that it has data in it
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
configMapVolumeMounts := []corev1.VolumeMount{{
Name: r.CaBundleConf.Name,
MountPath: "/etc/ocp-injected-ca-bundle.crt",
MountPath: "/etc/ocp-injected-ca-bundle",
ReadOnly: true,
}}
util.MergeVolumeMountList(&c.VolumeMounts, &configMapVolumeMounts)
Expand Down Expand Up @@ -701,7 +703,8 @@ func (r *Reconciler) SetDesiredCoreApp() error {

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

if util.KubeCheckQuiet(r.CaBundleConf) {
// we want to check that the cm exists and also that it has data in it
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
configMapVolumes := []corev1.Volume{{
Name: r.CaBundleConf.Name,
VolumeSource: corev1.VolumeSource{
Expand Down
9 changes: 5 additions & 4 deletions pkg/system/phase4_configuring.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func (r *Reconciler) SetDesiredDeploymentEndpoint() error {
c.Env[j].Value = ""
}
case "NODE_EXTRA_CA_CERTS":
c.Env[j].Value = r.ApplyCAsToPods
c.Env[j].Value = r.UserCertBundlePath
case "GUARANTEED_LOGS_PATH":
if r.NooBaa.Spec.BucketLogging.LoggingType == nbv1.BucketLoggingTypeGuaranteed {
c.Env[j].Value = r.BucketLoggingVolumeMount
Expand Down Expand Up @@ -507,7 +507,8 @@ func (r *Reconciler) setDesiredEndpointMounts(podSpec *corev1.PodSpec, container
util.MergeVolumeMountList(&container.VolumeMounts, &dbSecretVolumeMounts)
}

if util.KubeCheckQuiet(r.CaBundleConf) {
// we want to check that the cm exists and also that it has data in it
if util.KubeCheckQuiet(r.CaBundleConf) && len(r.CaBundleConf.Data) > 0 {
configMapVolumes := []corev1.Volume{{
Name: r.CaBundleConf.Name,
VolumeSource: corev1.VolumeSource{
Expand All @@ -525,7 +526,7 @@ func (r *Reconciler) setDesiredEndpointMounts(podSpec *corev1.PodSpec, container
util.MergeVolumeList(&podSpec.Volumes, &configMapVolumes)
configMapVolumeMounts := []corev1.VolumeMount{{
Name: r.CaBundleConf.Name,
MountPath: "/etc/ocp-injected-ca-bundle.crt",
MountPath: "/etc/ocp-injected-ca-bundle",
ReadOnly: true,
}}
util.MergeVolumeMountList(&container.VolumeMounts, &configMapVolumeMounts)
Expand Down Expand Up @@ -1408,7 +1409,7 @@ func (r *Reconciler) prepareCephBackingStore() error {
Transport: util.InsecureHTTPTransport,
Timeout: 10 * time.Second,
}
if r.ApplyCAsToPods != "" {
if r.UserCertBundlePath != "" {
client.Transport = util.GlobalCARefreshingTransport
}

Expand Down
12 changes: 8 additions & 4 deletions pkg/system/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Reconciler struct {
OperatorVersion string
OAuthEndpoints *util.OAuth2Endpoints
PostgresConnectionString string
ApplyCAsToPods string
UserCertBundlePath string

NooBaa *nbv1.NooBaa
ServiceAccount *corev1.ServiceAccount
Expand Down Expand Up @@ -282,7 +282,7 @@ func NewReconciler(
r.RouteS3.Name = r.ServiceS3.Name
r.RouteSts.Name = r.ServiceSts.Name
r.DeploymentEndpoint.Name = r.Request.Name + "-endpoint"
r.CaBundleConf.Name = r.Request.Name + "-ca-inject"
r.CaBundleConf.Name = "ocp-injected-ca-bundle"
r.KedaScaled.Name = r.Request.Name
r.AdapterHPA.Name = r.Request.Name + "-hpav2"
r.BucketLoggingPVC.Name = r.Request.Name + "-bucket-logging-pvc"
Expand Down Expand Up @@ -404,9 +404,13 @@ func (r *Reconciler) Reconcile() (reconcile.Result, error) {
}
}

err = util.AddToRootCAs(options.ServiceServingCertCAFile)
err = util.CombineCaBundle(util.ServiceServingCertCAFile)
if err == nil {
r.ApplyCAsToPods = options.ServiceServingCertCAFile
// TODO: Use this once noobaa-core#8973 is merged
// Until then, we have to choose between using the injected cert bundle or the service serving cert ca file.
// For now, we use the service serving certs to allow the product to continue working, even if without user provided certs.
// r.UserCertBundlePath = util.CombinedCaBundlePath
r.UserCertBundlePath = util.ServiceServingCertCAFile
} else if !os.IsNotExist(err) {
log.Errorf("❌ NooBaa %q failed to add root CAs to system default", r.NooBaa.Name)
res.RequeueAfter = 3 * time.Second
Expand Down
21 changes: 15 additions & 6 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ const (

topologyConstraintsEnabledKubeVersion = "1.26.0"
trueStr = "true"

// ServiceServingCertCAFile points to OCP default root CA list
ServiceServingCertCAFile = "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt"

// InjectedBundleCertCAFile points to OCP root CA to be added to the default root CA list
InjectedBundleCertCAFile = "/etc/ocp-injected-ca-bundle/ca-bundle.crt"

// CombinedCaBundlePath points to the combined CA bundle file
CombinedCaBundlePath = "/tmp/ca-bundle.crt"
)

// OAuth2Endpoints holds OAuth2 endpoints information.
Expand Down Expand Up @@ -120,12 +129,12 @@ var (
lazyConfig *rest.Config
lazyClient client.Client

// InsecureHTTPTransport is a global insecure http transport
// InsecureHTTPTransport is an HTTP transport that skips certificate signature verification
InsecureHTTPTransport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}

// GlobalCARefreshingTransport is a global secure http transport
// GlobalCARefreshingTransport is an HTTP transport that verifies certificate signing
GlobalCARefreshingTransport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: false},
}
Expand All @@ -143,15 +152,15 @@ var (
}
)

// AddToRootCAs adds a local cert file to Our GlobalCARefreshingTransport
func AddToRootCAs(localCertFile string) error {
// CombineCaBundle combines a local cert file to Our GlobalCARefreshingTransport
func CombineCaBundle(localCertFile string) error {
rootCAs, _ := x509.SystemCertPool()
if rootCAs == nil {
rootCAs = x509.NewCertPool()
}

var certFiles = []string{
"/etc/ocp-injected-ca-bundle.crt",
InjectedBundleCertCAFile,
localCertFile,
}

Expand All @@ -169,7 +178,7 @@ func AddToRootCAs(localCertFile string) error {
}

// Trust the augmented cert pool in our client
log.Infof("Successfuly appended %q to RootCAs", certFile)
log.Infof("Successfully appended %q to RootCAs", certFile)
}
GlobalCARefreshingTransport.TLSClientConfig.RootCAs = rootCAs
return nil
Expand Down
Loading