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 <blaine.gardner@suse.com>
This commit is contained in:
Blaine Gardner committed 2019-04-03 15:54:00 -06:00
1 parent feff587992
commit a34fbaa594
2 files changed
+20 -2

No files matched your search

+10 -1
View File
@@ -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}
+10 -1
View File
@@ -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
}