From 6d9ecf48bc2ef3e74ec81e3c8fb3ad7576e66db2 Mon Sep 17 00:00:00 2001 From: Travis Nielsen Date: Fri, 24 Jun 2022 12:14:27 -0600 Subject: [PATCH] mon: disable insecure global ids for new deployments In new deployments we always want to disable the insecure global id. If the mgr deployment is newly created, we know it's a new cluster and the mons are in quorum, so we can go ahead and disable the insecure global IDs. Signed-off-by: Travis Nielsen (cherry picked from commit 28957b3ff1f9f082a0c4a4fcfc3f5d525c811aa0) --- pkg/operator/ceph/cluster/cephstatus.go | 7 +---- pkg/operator/ceph/cluster/cephstatus_test.go | 2 ++ pkg/operator/ceph/cluster/mgr/mgr.go | 6 ++++ pkg/operator/ceph/config/config.go | 29 ++++++++++++++++++++ pkg/operator/ceph/config/config_test.go | 15 ++++++++++ 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/pkg/operator/ceph/cluster/cephstatus.go b/pkg/operator/ceph/cluster/cephstatus.go index e6ead5cdb..c8045f5db 100644 --- a/pkg/operator/ceph/cluster/cephstatus.go +++ b/pkg/operator/ceph/cluster/cephstatus.go @@ -166,12 +166,7 @@ func (c *cephStatusChecker) configureHealthSettings(status cephclient.CephStatus if _, ok := status.Health.Checks["AUTH_INSECURE_GLOBAL_ID_RECLAIM_ALLOWED"]; ok { if _, ok := status.Health.Checks["AUTH_INSECURE_GLOBAL_ID_RECLAIM"]; !ok { logger.Info("Disabling the insecure global ID as no legacy clients are currently connected. If you still require the insecure connections, see the CVE to suppress the health warning and re-enable the insecure connections. https://docs.ceph.com/en/latest/security/CVE-2021-20288/") - monStore := config.GetMonStore(c.context, c.clusterInfo) - if err := monStore.Set("mon", "auth_allow_insecure_global_id_reclaim", "false"); err != nil { - logger.Warningf("failed to disable the insecure global ID. %v", err) - } else { - logger.Info("insecure global ID is now disabled") - } + config.DisableInsecureGlobalID(c.context, c.clusterInfo) } else { logger.Warning("insecure clients are connected to the cluster, to resolve the AUTH_INSECURE_GLOBAL_ID_RECLAIM health warning please refer to the upgrade guide to ensure all Ceph daemons are updated.") } diff --git a/pkg/operator/ceph/cluster/cephstatus_test.go b/pkg/operator/ceph/cluster/cephstatus_test.go index e09166609..1652d3051 100644 --- a/pkg/operator/ceph/cluster/cephstatus_test.go +++ b/pkg/operator/ceph/cluster/cephstatus_test.go @@ -29,6 +29,7 @@ import ( cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/rook/rook/pkg/clusterd" cephclient "github.com/rook/rook/pkg/daemon/ceph/client" + "github.com/rook/rook/pkg/operator/ceph/version" optest "github.com/rook/rook/pkg/operator/test" exectest "github.com/rook/rook/pkg/util/exec/test" "github.com/stretchr/testify/assert" @@ -161,6 +162,7 @@ func TestConfigureHealthSettings(t *testing.T) { context: &clusterd.Context{}, clusterInfo: cephclient.AdminTestClusterInfo("ns"), } + c.clusterInfo.CephVersion = version.Quincy setGlobalIDReclaim := false c.context.Executor = &exectest.MockExecutor{ MockExecuteCommandWithTimeout: func(timeout time.Duration, command string, args ...string) (string, error) { diff --git a/pkg/operator/ceph/cluster/mgr/mgr.go b/pkg/operator/ceph/cluster/mgr/mgr.go index 360a5e38e..f7f554178 100644 --- a/pkg/operator/ceph/cluster/mgr/mgr.go +++ b/pkg/operator/ceph/cluster/mgr/mgr.go @@ -160,6 +160,12 @@ func (c *Cluster) Start() error { } } + // Insecure global IDs should be disabled for new clusters immediately. + // If we're waiting for the mgr deployments to start, it is a clean deployment + if len(deploymentsToWaitFor) > 0 { + config.DisableInsecureGlobalID(c.context, c.clusterInfo) + } + // If the mgr is newly created, wait for it to start before continuing with the service and // module configuration for _, d := range deploymentsToWaitFor { diff --git a/pkg/operator/ceph/config/config.go b/pkg/operator/ceph/config/config.go index 5cb7754d7..46df830bf 100644 --- a/pkg/operator/ceph/config/config.go +++ b/pkg/operator/ceph/config/config.go @@ -29,6 +29,7 @@ import ( cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/rook/rook/pkg/clusterd" cephclient "github.com/rook/rook/pkg/daemon/ceph/client" + "github.com/rook/rook/pkg/operator/ceph/version" ) var logger = capnslog.NewPackageLogger("github.com/rook/rook", "op-config") @@ -161,3 +162,31 @@ func SetOrRemoveDefaultConfigs( return nil } + +func DisableInsecureGlobalID(context *clusterd.Context, clusterInfo *cephclient.ClusterInfo) { + if !canDisableInsecureGlobalID(clusterInfo) { + logger.Infof("cannot disable insecure global id on ceph version %v", clusterInfo.CephVersion.String()) + return + } + + monStore := GetMonStore(context, clusterInfo) + if err := monStore.Set("mon", "auth_allow_insecure_global_id_reclaim", "false"); err != nil { + logger.Warningf("failed to disable the insecure global ID. %v", err) + } else { + logger.Info("insecure global ID is now disabled") + } +} + +func canDisableInsecureGlobalID(clusterInfo *cephclient.ClusterInfo) bool { + cephver := clusterInfo.CephVersion + if cephver.IsAtLeastQuincy() { + return true + } + if cephver.IsPacific() && cephver.IsAtLeast(version.CephVersion{Major: 16, Minor: 2, Extra: 1}) { + return true + } + if cephver.IsOctopus() && cephver.IsAtLeast(version.CephVersion{Major: 15, Minor: 2, Extra: 11}) { + return true + } + return false +} diff --git a/pkg/operator/ceph/config/config_test.go b/pkg/operator/ceph/config/config_test.go index 89a4b477f..6175cef37 100644 --- a/pkg/operator/ceph/config/config_test.go +++ b/pkg/operator/ceph/config/config_test.go @@ -19,6 +19,8 @@ package config import ( "testing" + "github.com/rook/rook/pkg/daemon/ceph/client" + "github.com/rook/rook/pkg/operator/ceph/version" "github.com/stretchr/testify/assert" ) @@ -29,3 +31,16 @@ func TestNewFlag(t *testing.T) { assert.Equal(t, NewFlag("c key", "c"), "--c-key=c") assert.Equal(t, NewFlag("quotes", "\"quoted\""), "--quotes=\"quoted\"") } + +func TestInsecureGlobalIDVersion(t *testing.T) { + c := &client.ClusterInfo{CephVersion: version.CephVersion{Major: 17, Minor: 2, Extra: 0}} + assert.True(t, canDisableInsecureGlobalID(c)) + c = &client.ClusterInfo{CephVersion: version.CephVersion{Major: 16, Minor: 2, Extra: 0}} + assert.False(t, canDisableInsecureGlobalID(c)) + c = &client.ClusterInfo{CephVersion: version.CephVersion{Major: 16, Minor: 2, Extra: 1}} + assert.True(t, canDisableInsecureGlobalID(c)) + c = &client.ClusterInfo{CephVersion: version.CephVersion{Major: 15, Minor: 2, Extra: 10}} + assert.False(t, canDisableInsecureGlobalID(c)) + c = &client.ClusterInfo{CephVersion: version.CephVersion{Major: 15, Minor: 2, Extra: 11}} + assert.True(t, canDisableInsecureGlobalID(c)) +}