]> xenbits.xensource.com Git - libvirt.git/commitdiff
secret: Add check/validation for correct usage when LookupByUUID
authorJohn Ferlan <jferlan@redhat.com>
Tue, 4 Dec 2018 20:15:22 +0000 (15:15 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 13 Dec 2018 15:22:25 +0000 (10:22 -0500)
https://bugzilla.redhat.com/show_bug.cgi?id=1656255

If virSecretGetSecretString is using by secretLookupByUUID,
then it's possible the found sec->usageType doesn't match the
desired @secretUsageType. If this occurs for the encrypted
volume creation processing and a subsequent pool refresh is
executed, then the secret used to create the volume will not
be found by the storageBackendLoadDefaultSecrets which expects
to find secrets by VIR_SECRET_USAGE_TYPE_VOLUME.

Add a check to virSecretGetSecretString to avoid the possibility
along with an error indicating the incorrect matched types.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
src/secret/secret_util.c
tests/qemuxml2argvtest.c

index 16e43ab2cc9a6965ca58e0bb77d97cecbe86eec5..27e164a42502a6789490ce898a414ccba484c6ef 100644 (file)
@@ -71,6 +71,23 @@ virSecretGetSecretString(virConnectPtr conn,
     if (!sec)
         goto cleanup;
 
+    /* NB: NONE is a byproduct of the qemuxml2argvtest test mocking
+     * for UUID lookups. Normal secret XML processing would fail if
+     * the usage type was NONE and since we have no way to set the
+     * expected usage in that environment, let's just accept NONE */
+    if (sec->usageType != VIR_SECRET_USAGE_TYPE_NONE &&
+        sec->usageType != secretUsageType) {
+        char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+        virUUIDFormat(seclookupdef->u.uuid, uuidstr);
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("secret with uuid %s is of type '%s' not "
+                         "expected '%s' type"),
+                       uuidstr, virSecretUsageTypeToString(sec->usageType),
+                       virSecretUsageTypeToString(secretUsageType));
+        goto cleanup;
+    }
+
     *secret = conn->secretDriver->secretGetValue(sec, secret_size, 0,
                                                  VIR_SECRET_GET_VALUE_INTERNAL_CALL);
 
index 88ecbba1c96b5b6e8112a16fa354bbd5115c2c9e..ddc488be87fe7b455f5415feda046ff3d46acd68 100644 (file)
@@ -77,7 +77,9 @@ static virSecretPtr
 fakeSecretLookupByUUID(virConnectPtr conn,
                        const unsigned char *uuid)
 {
-    return virGetSecret(conn, uuid, 0, "");
+    /* NB: This mocked value could be "tls" or "volume" depending on
+     * which test is being run, we'll leave at NONE (or 0) */
+    return virGetSecret(conn, uuid, VIR_SECRET_USAGE_TYPE_NONE, "");
 }
 
 static virSecretDriver fakeSecretDriver = {