https://bugzilla.redhat.com/show_bug.cgi?id=1300769

Modify the Begin phase to add the checks to determine whether a migration
wishes to use TLS and whether it's configured including adding the secret
into the priv->migSecinfo for the source domain.

Modify the Perform phase in qemuMigrationRun in order to generate the
TLS objects to be used for the migration and set the migration channel
parameters 'tls-creds' and possibly 'tls-hostname' in order to enable TLS.

Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/qemu/qemu_migration.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 0e95fd9..4779d23 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3452,6 +3452,9 @@ qemuMigrationBegin(virConnectPtr conn,
         goto endjob;
     }
 
+    if (qemuMigrationCheckSetupTLS(driver, conn, vm, flags) < 0)
+        goto endjob;
+
     /* Check if there is any ejected media.
      * We don't want to require them on the destination.
      */
@@ -4802,8 +4805,12 @@ qemuMigrationRun(virQEMUDriverPtr driver,
 {
     int ret = -1;
     unsigned int migrate_flags = QEMU_MONITOR_MIGRATE_BACKGROUND;
+    virQEMUDriverConfigPtr cfg = NULL;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     qemuMigrationCookiePtr mig = NULL;
+    char *tlsAlias = NULL;
+    char *tlsHostname = NULL;
+    char *secAlias = NULL;
     qemuMigrationIOThreadPtr iothread = NULL;
     int fd = -1;
     unsigned long migrate_speed = resource ? resource : priv->migMaxBandwidth;
@@ -4867,6 +4874,29 @@ qemuMigrationRun(virQEMUDriverPtr driver,
     if (qemuDomainMigrateGraphicsRelocate(driver, vm, mig, graphicsuri) < 0)
         VIR_WARN("unable to provide data for graphics client relocation");
 
+    /* If we're using TLS attempt to add the objects */
+    if (priv->migrateTLS) {
+        cfg = virQEMUDriverGetConfig(driver);
+        if (qemuMigrationAddTLSObjects(driver, vm, "migrate",
+                                       cfg->migrateTLSx509certdir, false,
+                                       cfg->migrateTLSx509verify,
+                                       &tlsAlias, &secAlias, migParams) < 0)
+            goto cleanup;
+
+        /* We need to add the tls-hostname only for special circumstances.
+         * When using "fd:" or "exec:", qemu needs to know the hostname of
+         * the target qemu to correctly validate the x509 certificate
+         * it receives. */
+        if (STREQ(spec->dest.host.protocol, "fd") ||
+            STREQ(spec->dest.host.protocol, "exec")) {
+            if (VIR_STRDUP(tlsHostname, spec->dest.host.name) < 0) {
+                qemuDomainDelTLSObjects(driver, vm, secAlias, tlsAlias);
+                return -1;
+            }
+            migParams->migrateTLSHostname = tlsHostname;
+        }
+    }
+
     if (migrate_flags & (QEMU_MONITOR_MIGRATE_NON_SHARED_DISK |
                          QEMU_MONITOR_MIGRATE_NON_SHARED_INC)) {
         if (mig->nbd) {
@@ -5047,6 +5077,10 @@ qemuMigrationRun(virQEMUDriverPtr driver,
             ret = -1;
     }
 
+    qemuMigrationDelTLSObjects(driver, cfg, vm, &secAlias, &tlsAlias);
+    VIR_FREE(tlsHostname);
+    virObjectUnref(cfg);
+
     if (spec->fwdType != MIGRATION_FWD_DIRECT) {
         if (iothread && qemuMigrationStopTunnel(iothread, ret < 0) < 0)
             ret = -1;
-- 
2.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to