From a34fbaa59466e86e2548634fe30fe2a6fbeff38b Mon Sep 17 00:00:00 2001 From: Blaine Gardner Date: Wed, 3 Apr 2019 13:04:30 -0600 Subject: [PATCH] ceph: update auth caps if get/create key fails Update integration test suite fails on an error with getting the keyring for the mgr. The mgr's cephx capabilities have changed and need to be updated before get, create, or get-or-create can be called. Since other daemons' caps may change in the future, make an attempt to update the user's caps on any key generation. This makes the key generation more declarative from within the operator code for individual Ceph daemons. Signed-off-by: Blaine Gardner --- pkg/daemon/ceph/client/auth.go | 11 ++++++++++- pkg/operator/ceph/config/keyring/store.go | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) 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 }