diff --git a/pkg/daemon/ceph/client/auth.go b/pkg/daemon/ceph/client/auth.go index 44f425327..8334766e1 100644 --- a/pkg/daemon/ceph/client/auth.go +++ b/pkg/daemon/ceph/client/auth.go @@ -59,7 +59,6 @@ func AuthGetKey(context *clusterd.Context, clusterName, name string) (string, er // AuthGetOrCreateKey gets or creates the key for the given user. func AuthGetOrCreateKey(context *clusterd.Context, clusterName, name string, caps []string) (string, error) { - args := append([]string{"auth", "get-or-create-key", name}, caps...) buf, err := ExecuteCephCommand(context, clusterName, args) if err != nil { @@ -69,6 +68,16 @@ func AuthGetOrCreateKey(context *clusterd.Context, clusterName, name string, cap return parseAuthKey(buf) } +// AuthUpdateCaps updates the capabilities for the given user. +func AuthUpdateCaps(context *clusterd.Context, clusterName, name string, caps []string) error { + args := append([]string{"auth", "caps", name}, caps...) + _, err := ExecuteCephCommand(context, clusterName, args) + if err != nil { + return fmt.Errorf("failed to update caps for %s. %+v", name, err) + } + return err +} + // AuthDelete will delete the given user. func AuthDelete(context *clusterd.Context, clusterName, name string) error { args := []string{"auth", "del", name} diff --git a/pkg/operator/ceph/config/keyring/store.go b/pkg/operator/ceph/config/keyring/store.go index 33ba2986d..5faca88b2 100644 --- a/pkg/operator/ceph/config/keyring/store.go +++ b/pkg/operator/ceph/config/keyring/store.go @@ -69,7 +69,16 @@ func (k *SecretStore) GenerateKey(resourceName, user string, access []string) (s // get-or-create-key for the user account key, err := client.AuthGetOrCreateKey(k.context, k.namespace, user, access) if err != nil { - return "", fmt.Errorf("failed to get or create auth key for %s. %+v", user, err) + logger.Infof("Error getting or creating key for %s. "+ + "Attempting to update capabilities in case the user already exists. %+v", user, err) + uErr := client.AuthUpdateCaps(k.context, k.namespace, user, access) + if uErr != nil { + return "", fmt.Errorf("failed to get, create, or update auth key for %s. %+v", user, err) + } + key, uErr = client.AuthGetKey(k.context, k.namespace, user) + if uErr != nil { + return "", fmt.Errorf("failed to get key after updating existing auth capabilities for %s. %+v", user, err) + } } return key, nil }