From nobody Sat May 4 04:03:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1501103132903683.4203961821847; Wed, 26 Jul 2017 14:05:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D24DB104D62; Wed, 26 Jul 2017 21:05:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF6645D96D; Wed, 26 Jul 2017 21:05:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7D75B180597B; Wed, 26 Jul 2017 21:05:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6QL5PYK025115 for ; Wed, 26 Jul 2017 17:05:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id EF1AF60472; Wed, 26 Jul 2017 21:05:25 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-46.phx2.redhat.com [10.3.117.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3A385C7A2 for ; Wed, 26 Jul 2017 21:05:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D24DB104D62 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Wed, 26 Jul 2017 17:05:17 -0400 Message-Id: <20170726210517.31341-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4] qemu: Check for existence of provided *_tls_x509_cert_dir X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 26 Jul 2017 21:05:31 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1458630 Introduce virQEMUDriverConfigTLSDirResetDefaults in order to check if the defaultTLSx509certdir was changed, then change the default for any other *TLSx509certdir that was not set to the default default. Introduce virQEMUDriverConfigValidate to validate the existence of any of the *_tls_x509_cert_dir values that were uncommented/set, incuding the default. Update the qemu.conf description for default to describe the consequences if the default directory path does not exist. Signed-off-by: John Ferlan --- v3: https://www.redhat.com/archives/libvir-list/2017-July/msg00915.html Changes since v3 - rework even more based on code review. src/qemu/qemu.conf | 8 ++++ src/qemu/qemu_conf.c | 105 +++++++++++++++++++++++++++++++++++++++++++++= +++- src/qemu/qemu_conf.h | 4 ++ src/qemu/qemu_driver.c | 3 ++ 4 files changed, 119 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf index 1d81472..f977e3b 100644 --- a/src/qemu/qemu.conf +++ b/src/qemu/qemu.conf @@ -13,6 +13,14 @@ # # dh-params.pem - the DH params configuration file # +# If the directory does not exist or contain the necessary files, QEMU +# domains will fail to start if they are configured to use TLS. +# +# In order to overwrite the default path alter the following. This path +# definition will be used as the default path for other *_tls_x509_cert_dir +# configuration settings if their default path does not exist or is not +# specifically set. +# #default_tls_x509_cert_dir =3D "/etc/pki/qemu" =20 =20 diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index c4714ed..1a4a998 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -425,6 +425,43 @@ virQEMUDriverConfigHugeTLBFSInit(virHugeTLBFSPtr huget= lbfs, } =20 =20 +/** + * @cfg: Just read config TLS values + * + * If the default_tls_x509_cert_dir was uncommented or changed from + * the default value assigned to the *_tls_x509_cert_dir values when + * virQEMUDriverConfigNew was executed, we need to check if we need + * to update the other defaults. + * + * Returns 0 on success, -1 on failure + */ +static int +virQEMUDriverConfigTLSDirResetDefaults(virQEMUDriverConfigPtr cfg) +{ + /* Not changed or set to the default default, nothing to do */ + if (!cfg->checkdefaultTLSx509certdir || + STREQ(cfg->defaultTLSx509certdir, SYSCONFDIR "/pki/qemu")) + return 0; + +#define CHECK_RESET_CERT_DIR_DEFAULT(val) \ + do { \ + if (STREQ(cfg->val ## TLSx509certdir, SYSCONFDIR "/pki/qemu")) { \ + VIR_FREE(cfg->val ## TLSx509certdir); \ + if (VIR_STRDUP(cfg->val ## TLSx509certdir, \ + cfg->defaultTLSx509certdir) < 0) \ + return -1; \ + } \ + } while (0) + + CHECK_RESET_CERT_DIR_DEFAULT(vnc); + CHECK_RESET_CERT_DIR_DEFAULT(spice); + CHECK_RESET_CERT_DIR_DEFAULT(chardev); + CHECK_RESET_CERT_DIR_DEFAULT(migrate); + + return 0; +} + + int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, const char *filename, bool privileged) @@ -452,8 +489,9 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr = cfg, if (!(conf =3D virConfReadFile(filename, 0))) goto cleanup; =20 - if (virConfGetValueString(conf, "default_tls_x509_cert_dir", &cfg->def= aultTLSx509certdir) < 0) + if ((rv =3D virConfGetValueString(conf, "default_tls_x509_cert_dir", &= cfg->defaultTLSx509certdir)) < 0) goto cleanup; + cfg->checkdefaultTLSx509certdir =3D (rv =3D=3D 1); if (virConfGetValueBool(conf, "default_tls_x509_verify", &cfg->default= TLSx509verify) < 0) goto cleanup; if (virConfGetValueString(conf, "default_tls_x509_secret_uuid", @@ -549,6 +587,9 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr = cfg, =20 #undef GET_CONFIG_TLS_CERTINFO =20 + if (virQEMUDriverConfigTLSDirResetDefaults(cfg) < 0) + goto cleanup; + if (virConfGetValueUInt(conf, "remote_websocket_port_min", &cfg->webSo= cketPortMin) < 0) goto cleanup; if (cfg->webSocketPortMin < QEMU_WEBSOCKET_PORT_MIN) { @@ -873,6 +914,68 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr= cfg, return ret; } =20 + +/** + * @cfg: Recently read config values + * + * Validate the recently read configuration values. + * + * Returns 0 on success, -1 on failure + */ +int +virQEMUDriverConfigValidate(virQEMUDriverConfigPtr cfg) +{ + /* If the default entry was uncommented, then validate existence */ + if (cfg->checkdefaultTLSx509certdir) { + if (!virFileExists(cfg->defaultTLSx509certdir)) { + virReportError(VIR_ERR_CONF_SYNTAX, + _("default_tls_x509_cert_dir directory '%s' " + "does not exist"), + cfg->defaultTLSx509certdir); + return -1; + } + } + + /* For each of the others - if the value is not to the default default + * then check if the directory exists (this may duplicate the check do= ne + * during virQEMUDriverConfigNew). + */ + if (STRNEQ(cfg->vncTLSx509certdir, SYSCONFDIR "/pki/qemu") && + !virFileExists(cfg->vncTLSx509certdir)) { + virReportError(VIR_ERR_CONF_SYNTAX, + _("vnc_tls_x509_cert_dir directory '%s' does not ex= ist"), + cfg->vncTLSx509certdir); + return -1; + } + + if (STRNEQ(cfg->spiceTLSx509certdir, SYSCONFDIR "/pki/qemu") && + !virFileExists(cfg->spiceTLSx509certdir)) { + virReportError(VIR_ERR_CONF_SYNTAX, + _("spice_tls_x509_cert_dir directory '%s' does not = exist"), + cfg->spiceTLSx509certdir); + return -1; + } + + if (STRNEQ(cfg->chardevTLSx509certdir, SYSCONFDIR "/pki/qemu") && + !virFileExists(cfg->chardevTLSx509certdir)) { + virReportError(VIR_ERR_CONF_SYNTAX, + _("chardev_tls_x509_cert_dir directory '%s' does no= t exist"), + cfg->chardevTLSx509certdir); + return -1; + } + + if (STRNEQ(cfg->migrateTLSx509certdir, SYSCONFDIR "/pki/qemu") && + !virFileExists(cfg->migrateTLSx509certdir)) { + virReportError(VIR_ERR_CONF_SYNTAX, + _("migrate_tls_x509_cert_dir directory '%s' does no= t exist"), + cfg->migrateTLSx509certdir); + return -1; + } + + return 0; +} + + virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver) { virQEMUDriverConfigPtr conf; diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 3013f24..d469b50 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -113,6 +113,7 @@ struct _virQEMUDriverConfig { char *nvramDir; =20 char *defaultTLSx509certdir; + bool checkdefaultTLSx509certdir; bool defaultTLSx509verify; char *defaultTLSx509secretUUID; =20 @@ -302,6 +303,9 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr = cfg, const char *filename, bool privileged); =20 +int +virQEMUDriverConfigValidate(virQEMUDriverConfigPtr cfg); + virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver); bool virQEMUDriverIsPrivileged(virQEMUDriverPtr driver); =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a423663..3ad71e6 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -667,6 +667,9 @@ qemuStateInitialize(bool privileged, goto error; VIR_FREE(driverConf); =20 + if (virQEMUDriverConfigValidate(cfg) < 0) + goto error; + if (virFileMakePath(cfg->stateDir) < 0) { virReportSystemError(errno, _("Failed to create state dir %s"), cfg->stateDir); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list