From a97233102d1cdeb97c1d463e6c651ddade9973d2 Mon Sep 17 00:00:00 2001 From: Sunnatillo Date: Thu, 15 Jan 2026 16:57:10 +0200 Subject: [PATCH] object: use ceph version aware CA bundle handling for RGW Add ceph version check to determine CA bundle configuration method. Ceph Tentacle+ supports CURL_CA_BUNDLE environment variable, while older versions require system CA trust update via init container. Signed-off-by: Sunnatillo --- pkg/operator/ceph/object/config.go | 32 +++++++------ pkg/operator/ceph/object/spec.go | 73 +++++++++++++++++++++++++----- 2 files changed, 80 insertions(+), 25 deletions(-) diff --git a/pkg/operator/ceph/object/config.go b/pkg/operator/ceph/object/config.go index ebbc303fc..c7e5af0d2 100644 --- a/pkg/operator/ceph/object/config.go +++ b/pkg/operator/ceph/object/config.go @@ -40,20 +40,24 @@ caps mon = "allow rw" caps osd = "allow rwx" ` - caBundleVolumeName = "rook-ceph-custom-ca-bundle" - caBundleKeyName = "cabundle" - caBundleFileName = "custom-ca-bundle.pem" - caBundleMountPath = "/etc/ceph/rgw-ca-bundle/" - certVolumeName = "rook-ceph-rgw-cert" - certDir = "/etc/ceph/private" - certKeyName = "cert" - certFilename = "rgw-cert.pem" - certKeyFileName = "rgw-key.pem" - rgwPortInternalPort int32 = 8080 - ServiceServingCertCAFile = "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt" - HttpTimeOut = time.Second * 15 - rgwVaultVolumeName = "rgw-vault-volume" - rgwVaultDirName = "/etc/vault/rgw/" + caBundleVolumeName = "rook-ceph-custom-ca-bundle" + caBundleUpdatedVolumeName = "rook-ceph-ca-bundle-updated" + caBundleTrustedDir = "/etc/pki/ca-trust/" + caBundleSourceCustomDir = caBundleTrustedDir + "source/anchors/" + caBundleExtractedDir = caBundleTrustedDir + "extracted/" + caBundleKeyName = "cabundle" + caBundleFileName = "custom-ca-bundle.crt" + caBundleMountPath = "/etc/ceph/rgw-ca-bundle/" + certVolumeName = "rook-ceph-rgw-cert" + certDir = "/etc/ceph/private" + certKeyName = "cert" + certFilename = "rgw-cert.pem" + certKeyFileName = "rgw-key.pem" + rgwPortInternalPort int32 = 8080 + ServiceServingCertCAFile = "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt" + HttpTimeOut = time.Second * 15 + rgwVaultVolumeName = "rgw-vault-volume" + rgwVaultDirName = "/etc/vault/rgw/" ) var rgwFrontendName = "beast" diff --git a/pkg/operator/ceph/object/spec.go b/pkg/operator/ceph/object/spec.go index 490e5d478..b4d1cfd2e 100644 --- a/pkg/operator/ceph/object/spec.go +++ b/pkg/operator/ceph/object/spec.go @@ -134,6 +134,13 @@ type rgwProbeConfig struct { Path string } +// supportsCurlCaBundle returns true if the Ceph version supports CURL_CA_BUNDLE +// environment variable for CA bundle handling (Tentacle v20.0.0+). +// TODO: Remove this helper after Ceph Squid is no longer supported +func supportsCurlCaBundle(c *clusterConfig) bool { + return c.clusterInfo.CephVersion.IsAtLeastTentacle() +} + func (c *clusterConfig) createDeployment(rgwConfig *rgwConfig) (*apps.Deployment, error) { pod, err := c.makeRGWPodSpec(rgwConfig) if err != nil { @@ -244,6 +251,22 @@ func (c *clusterConfig) makeRGWPodSpec(rgwConfig *rgwConfig) (v1.PodTemplateSpec }, } podSpec.Volumes = append(podSpec.Volumes, customCaBundleVol) + // Determine CA bundle handling method based on Ceph version + // Newer Ceph versions support CURL_CA_BUNDLE env var (see PR + // https://github.com/ceph/ceph/pull/44283) + // Older versions require system CA trust update via init container + // TODO: Remove this logic after Ceph Squid is no longer supported + if !supportsCurlCaBundle(c) { + updatedCaBundleVol := v1.Volume{ + Name: caBundleUpdatedVolumeName, + VolumeSource: v1.VolumeSource{ + EmptyDir: &v1.EmptyDirVolumeSource{}, + }, + } + podSpec.Volumes = append(podSpec.Volumes, updatedCaBundleVol) + podSpec.InitContainers = append(podSpec.InitContainers, + c.createCaBundleUpdateInitContainer(rgwConfig)) + } } kmsEnabled, err := c.CheckRGWKMS() if err != nil { @@ -307,6 +330,27 @@ func (c *clusterConfig) makeRGWPodSpec(rgwConfig *rgwConfig) (v1.PodTemplateSpec return podTemplateSpec, nil } +func (c *clusterConfig) createCaBundleUpdateInitContainer(rgwConfig *rgwConfig) v1.Container { + caBundleMount := v1.VolumeMount{Name: caBundleVolumeName, MountPath: caBundleSourceCustomDir, ReadOnly: true} + volumeMounts := append(controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName, c.clusterSpec.DataDirHostPath), caBundleMount) + updatedCaBundleDir := "/tmp/new-ca-bundle/" + updatedBundleMount := v1.VolumeMount{Name: caBundleUpdatedVolumeName, MountPath: updatedCaBundleDir, ReadOnly: false} + volumeMounts = append(volumeMounts, updatedBundleMount) + return v1.Container{ + Name: "update-ca-bundle-initcontainer", + Command: []string{"/bin/bash", "-c"}, + // copy all content of caBundleExtractedDir to avoid directory mount itself + Args: []string{ + fmt.Sprintf("/usr/bin/update-ca-trust extract; cp -rf %s/* %s", caBundleExtractedDir, updatedCaBundleDir), + }, + Image: c.clusterSpec.CephVersion.Image, + ImagePullPolicy: controller.GetContainerImagePullPolicy(c.clusterSpec.CephVersion.ImagePullPolicy), + VolumeMounts: volumeMounts, + Resources: c.store.Spec.Gateway.Resources, + SecurityContext: controller.DefaultContainerSecurityContext(), + } +} + // The vault token is passed as Secret for rgw container. So it is mounted as read only. // RGW has restrictions over vault token file, it should owned by same user (ceph) which // rgw daemon runs and all other permission should be nil or zero. Here ownership can be @@ -409,17 +453,24 @@ func (c *clusterConfig) makeDaemonContainer(rgwConfig *rgwConfig) (v1.Container, container.VolumeMounts = append(container.VolumeMounts, mount) } if c.store.Spec.Gateway.CaBundleRef != "" { - customCaBundleMount := v1.VolumeMount{Name: caBundleVolumeName, MountPath: caBundleMountPath, ReadOnly: true} - container.VolumeMounts = append(container.VolumeMounts, customCaBundleMount) - container.Env = append(container.Env, - v1.EnvVar{ - // Following PR introduced sot specify ssl certificate for RGW - // admon operations with this CURL_CA_BUNDLE env variable. - // https://github.com/ceph/ceph/pull/44283 - Name: "CURL_CA_BUNDLE", - Value: path.Join(caBundleMountPath, caBundleFileName), - }, - ) + // Use same CA bundle handling method as determined in makeRGWPodSpec + if supportsCurlCaBundle(c) { + customCaBundleMount := v1.VolumeMount{Name: caBundleVolumeName, MountPath: caBundleMountPath, ReadOnly: true} + container.VolumeMounts = append(container.VolumeMounts, customCaBundleMount) + container.Env = append(container.Env, + v1.EnvVar{ + // Following PR introduced to specify ssl certificate for RGW + // admin operations with this CURL_CA_BUNDLE env variable. + // https://github.com/ceph/ceph/pull/44283 + Name: "CURL_CA_BUNDLE", + Value: path.Join(caBundleMountPath, caBundleFileName), + }, + ) + } else { + // TODO: Remove this logic after Ceph Squid is no longer supported + updatedBundleMount := v1.VolumeMount{Name: caBundleUpdatedVolumeName, MountPath: caBundleExtractedDir, ReadOnly: true} + container.VolumeMounts = append(container.VolumeMounts, updatedBundleMount) + } } kmsEnabled, err := c.CheckRGWKMS() if err != nil {