diff --git a/pkg/operator/ceph/cluster/mgr/dashboard.go b/pkg/operator/ceph/cluster/mgr/dashboard.go index f87e2da01..dedf20a18 100644 --- a/pkg/operator/ceph/cluster/mgr/dashboard.go +++ b/pkg/operator/ceph/cluster/mgr/dashboard.go @@ -55,6 +55,13 @@ var ( removeMgrDaemonConfiguration = true ) +type KeyType int + +const ( + DefaultKey KeyType = iota + AccessKey +) + func (c *Cluster) configureDashboardService() error { dashboardService, err := c.makeDashboardService(AppName) if err != nil { @@ -325,7 +332,7 @@ func (c *Cluster) getOrGenerateDashboardPassword() (string, error) { } // Generate a password - password, err := GeneratePassword(passwordLength) + password, err := GeneratePassword(passwordLength, DefaultKey) if err != nil { return "", errors.Wrap(err, "failed to generate password") } @@ -354,9 +361,15 @@ func (c *Cluster) getOrGenerateDashboardPassword() (string, error) { return password, nil } -func GeneratePassword(length int) (string, error) { +func GeneratePassword(length int, keyType KeyType) (string, error) { //nolint:gosec // because of the word password - const passwordChars = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" + passwordChars := "!\"#$%&'()*+,-.0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" + + if keyType == DefaultKey { + //nolint:gosec // because of the word password + passwordChars += "/" + } + passwd, err := GenerateRandomBytes(length) if err != nil { return "", errors.Wrap(err, "failed to generate password") diff --git a/pkg/operator/ceph/cluster/mgr/dashboard_test.go b/pkg/operator/ceph/cluster/mgr/dashboard_test.go index 4fea16c18..7790a7260 100644 --- a/pkg/operator/ceph/cluster/mgr/dashboard_test.go +++ b/pkg/operator/ceph/cluster/mgr/dashboard_test.go @@ -35,16 +35,16 @@ import ( ) func TestGeneratePassword(t *testing.T) { - password, err := GeneratePassword(0) + password, err := GeneratePassword(0, DefaultKey) require.Nil(t, err) assert.Equal(t, "", password) - password, err = GeneratePassword(1) + password, err = GeneratePassword(1, DefaultKey) require.Nil(t, err) assert.Equal(t, 1, len(password)) logger.Infof("password: %s", password) - password, err = GeneratePassword(10) + password, err = GeneratePassword(10, DefaultKey) require.Nil(t, err) assert.Equal(t, 10, len(password)) logger.Infof("password: %s", password) diff --git a/pkg/operator/ceph/object/realm/controller.go b/pkg/operator/ceph/object/realm/controller.go index a8d24f49b..5f92ad592 100644 --- a/pkg/operator/ceph/object/realm/controller.go +++ b/pkg/operator/ceph/object/realm/controller.go @@ -275,13 +275,13 @@ func (r *ReconcileObjectRealm) createRealmKeys(realm *cephv1.CephObjectRealm) (r } // the realm's secret key and access key are randomly generated and then encoded to base64 - accessKey, err := mgr.GeneratePassword(accessKeyLength) + accessKey, err := mgr.GeneratePassword(accessKeyLength, mgr.AccessKey) if err != nil { return reconcile.Result{}, errors.Wrapf(err, "access key failed to generate") } accessKey = base64.StdEncoding.EncodeToString([]byte(accessKey)) - secretKey, err := mgr.GeneratePassword(secretKeyLength) + secretKey, err := mgr.GeneratePassword(secretKeyLength, mgr.DefaultKey) if err != nil { return reconcile.Result{}, errors.Wrapf(err, "failed to generate secret key") }