lxc: Set default security model in XML parser config

Attempting to create a lxc domain with <seclabel type='none'/> fails

virsh --connect lxc:/// create distro_nosec.xml
error: Failed to create domain from distro_nosec.xml
error: unsupported configuration: Security driver model '(null)' is not available

Commit 638ffa2228 adjusted the logic for setting a driver's default
security model.

The lxc driver does not set a default security driver model in the XML
parser config, causing seclabels of type='none' to have a null model.
The lxc driver's security manager is initialized in lxcStateInitialize()
by calling lxcSecurityInit(). Use the model of this manager as the
default in the XML parser config.

For the record, this is a regression caused by commit 638ffa2228, which
changed the logic for setting a driver's default security model. The
qemu driver was adjusted accordingly, but a similar change was missed
in the lxc driver.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Jim Fehlig 2020-12-03 11:55:24 -07:00
parent f6c11a23c8
commit cf4e7e620a
5 changed files with 10 additions and 5 deletions

View File

@ -209,9 +209,10 @@ virCapsPtr virLXCDriverGetCapabilities(virLXCDriverPtr driver,
virDomainXMLOptionPtr
lxcDomainXMLConfInit(virLXCDriverPtr driver)
lxcDomainXMLConfInit(virLXCDriverPtr driver, const char *defsecmodel)
{
virLXCDriverDomainDefParserConfig.priv = driver;
virLXCDriverDomainDefParserConfig.defSecModel = defsecmodel;
return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig,
&virLXCDriverPrivateDataCallbacks,
&virLXCDriverDomainXMLNamespace,

View File

@ -112,7 +112,8 @@ int virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg,
virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver);
virCapsPtr virLXCDriverGetCapabilities(virLXCDriverPtr driver,
bool refresh);
virDomainXMLOptionPtr lxcDomainXMLConfInit(virLXCDriverPtr driver);
virDomainXMLOptionPtr lxcDomainXMLConfInit(virLXCDriverPtr driver,
const char *defsecmodel);
static inline void lxcDriverLock(virLXCDriverPtr driver)
{

View File

@ -169,7 +169,7 @@ virLXCControllerDriverNew(void)
}
driver->caps = virLXCDriverCapsInit(NULL);
driver->xmlopt = lxcDomainXMLConfInit(driver);
driver->xmlopt = lxcDomainXMLConfInit(driver, NULL);
return driver;
}

View File

@ -1470,6 +1470,7 @@ static int lxcStateInitialize(bool privileged,
{
virLXCDriverConfigPtr cfg = NULL;
bool autostart = true;
const char *defsecmodel;
if (root != NULL) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
@ -1525,7 +1526,9 @@ static int lxcStateInitialize(bool privileged,
if (!(lxc_driver->hostdevMgr = virHostdevManagerGetDefault()))
goto cleanup;
if (!(lxc_driver->xmlopt = lxcDomainXMLConfInit(lxc_driver)))
defsecmodel = virSecurityManagerGetModel(lxc_driver->securityManager);
if (!(lxc_driver->xmlopt = lxcDomainXMLConfInit(lxc_driver, defsecmodel)))
goto cleanup;
if (!(lxc_driver->closeCallbacks = virCloseCallbacksNew()))

View File

@ -71,7 +71,7 @@ testLXCDriverInit(void)
}
driver->caps = testLXCCapsInit();
driver->xmlopt = lxcDomainXMLConfInit(driver);
driver->xmlopt = lxcDomainXMLConfInit(driver, NULL);
return driver;
}