csi: default to secure kernel mount options if network encrypted

If the network is encrypted with msgr2, cephfs requires
the mount options to include ms_mode=secure. Now this
will be set by default if the mount options are not
already set in the cephcluster CR or the operator env
var CSI_CEPHFS_KERNEL_MOUNT_OPTIONS.

Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
This commit is contained in:
Travis Nielsen committed 2025-08-27 16:30:47 -06:00
1 parent eeebfbf496
commit 6309cd367e
4 files changed
+46 -12

No files matched your search

+11
View File
@@ -33,6 +33,17 @@ func (c *ClusterSpec) RequireMsgr2() bool {
return false
}
// RequireMsgr2 checks if the network settings require the msgr2 protocol
func (c *ClusterSpec) NetworkEncryptionEnabled() bool {
if c.Network.Connections == nil {
return false
}
if c.Network.Connections.Encryption == nil {
return false
}
return c.Network.Connections.Encryption.Enabled
}
func (c *ClusterSpec) IsStretchCluster() bool {
return c.Mon.StretchCluster != nil && len(c.Mon.StretchCluster.Zones) > 0
}
+1 -3
View File
@@ -734,9 +734,7 @@ func (c *cluster) configureMsgr2() error {
}
monStore := config.GetMonStore(c.context, c.ClusterInfo)
encryptionEnabled := c.Spec.Network.Connections != nil &&
c.Spec.Network.Connections.Encryption != nil &&
c.Spec.Network.Connections.Encryption.Enabled
encryptionEnabled := c.Spec.NetworkEncryptionEnabled()
if encryptionEnabled {
logger.Infof("setting msgr2 encryption mode to %q", encryptionSetting)
+21 -9
View File
@@ -163,15 +163,8 @@ func CreateOrLoadClusterInfo(clusterdContext *clusterd.Context, context context.
// can run on remote executor
clusterInfo.NetworkSpec = cephClusterSpec.Network
// update clusterInfo with cephClusterSpec.CSI.
clusterInfo.CSIDriverSpec = cephClusterSpec.CSI
if len(clusterInfo.CSIDriverSpec.ReadAffinity.CrushLocationLabels) == 0 {
clusterInfo.CSIDriverSpec.ReadAffinity.CrushLocationLabels = strings.Split(topology.GetDefaultTopologyLabels(), ",")
}
// if the csi spec does not specify mount options, apply them from the operator env vars
if cephClusterSpec.CSI.CephFS.KernelMountOptions == "" {
clusterInfo.CSIDriverSpec.CephFS.KernelMountOptions = k8sutil.GetOperatorSetting("CSI_CEPHFS_KERNEL_MOUNT_OPTIONS", "")
}
// update clusterInfo with cephClusterSpec.CSI settings
clusterInfo.CSIDriverSpec = loadCsiSettings(cephClusterSpec)
// If an admin key was provided we don't need to load the other resources
// Some people might want to give the admin key
@@ -195,6 +188,25 @@ func CreateOrLoadClusterInfo(clusterdContext *clusterd.Context, context context.
return clusterInfo, maxMonID, monMapping, nil
}
func loadCsiSettings(cephClusterSpec *cephv1.ClusterSpec) cephv1.CSIDriverSpec {
settings := cephClusterSpec.CSI
if len(settings.ReadAffinity.CrushLocationLabels) == 0 {
settings.ReadAffinity.CrushLocationLabels = strings.Split(topology.GetDefaultTopologyLabels(), ",")
}
// if the csi spec does not specify mount options, apply them from the operator env vars
if cephClusterSpec.CSI.CephFS.KernelMountOptions == "" {
settings.CephFS.KernelMountOptions = k8sutil.GetOperatorSetting("CSI_CEPHFS_KERNEL_MOUNT_OPTIONS", "")
// if the kernel mount options are not set and encryption is enabled, set the default to secure
if settings.CephFS.KernelMountOptions == "" {
if cephClusterSpec.NetworkEncryptionEnabled() {
logger.Info("setting default cephfs kernel mount options to 'ms_mode=secure' since encryption is enabled")
settings.CephFS.KernelMountOptions = "ms_mode=secure"
}
}
}
return settings
}
// create new cluster info (FSID, shared keys)
func createNamedClusterInfo(context *clusterd.Context, namespace string) (*cephclient.ClusterInfo, error) {
fsid, err := uuid.NewRandom()
@@ -141,7 +141,20 @@ func TestCreateClusterSecrets(t *testing.T) {
assert.Equal(t, "testkey", info.CephCred.Secret)
assert.Equal(t, "", info.CSIDriverSpec.CephFS.KernelMountOptions)
// Verify the csi settings default to secure if the network is encrypted
cephClusterSpec.Network = cephv1.NetworkSpec{
Connections: &cephv1.ConnectionsSpec{
Encryption: &cephv1.EncryptionSpec{
Enabled: true,
},
},
}
info, _, _, err = CreateOrLoadClusterInfo(context, ctx, namespace, ownerInfo, cephClusterSpec)
assert.NoError(t, err)
assert.Equal(t, "ms_mode=secure", info.CSIDriverSpec.CephFS.KernelMountOptions)
// Verify the csi settings are loaded from an env var
cephClusterSpec.Network = cephv1.NetworkSpec{}
t.Setenv("CSI_CEPHFS_KERNEL_MOUNT_OPTIONS", "ms_mode=crc")
info, _, _, err = CreateOrLoadClusterInfo(context, ctx, namespace, ownerInfo, cephClusterSpec)
assert.NoError(t, err)