Refactor the security drivers to simplify usage
The current security driver usage requires horrible code like
if (driver->securityDriver &&
driver->securityDriver->domainSetSecurityHostdevLabel &&
driver->securityDriver->domainSetSecurityHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
This pair of checks for NULL clutters up the code, making the driver
calls 2 lines longer than they really need to be. The goal of the
patchset is to change the calling convention to simply
if (virSecurityManagerSetHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
The first check for 'driver->securityDriver' being NULL is removed
by introducing a 'no op' security driver that will always be present
if no real driver is enabled. This guarentees driver->securityDriver
!= NULL.
The second check for 'driver->securityDriver->domainSetSecurityHostdevLabel'
being non-NULL is hidden in a new abstraction called virSecurityManager.
This separates the driver callbacks, from main internal API. The addition
of a virSecurityManager object, that is separate from the virSecurityDriver
struct also allows for security drivers to carry state / configuration
information directly. Thus the DAC/Stack drivers from src/qemu which
used to pull config from 'struct qemud_driver' can now be moved into
the 'src/security' directory and store their config directly.
* src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update to
use new virSecurityManager APIs
* src/qemu/qemu_security_dac.c, src/qemu/qemu_security_dac.h
src/qemu/qemu_security_stacked.c, src/qemu/qemu_security_stacked.h:
Move into src/security directory
* src/security/security_stack.c, src/security/security_stack.h,
src/security/security_dac.c, src/security/security_dac.h: Generic
versions of previous QEMU specific drivers
* src/security/security_apparmor.c, src/security/security_apparmor.h,
src/security/security_driver.c, src/security/security_driver.h,
src/security/security_selinux.c, src/security/security_selinux.h:
Update to take virSecurityManagerPtr object as the first param
in all callbacks
* src/security/security_nop.c, src/security/security_nop.h: Stub
implementation of all security driver APIs.
* src/security/security_manager.h, src/security/security_manager.c:
New internal API for invoking security drivers
* src/libvirt.c: Add missing debug for security APIs
2010-11-17 20:26:30 +00:00
|
|
|
/*
|
|
|
|
* security_manager.h: Internal security manager API
|
|
|
|
*
|
security: add new virSecurityManagerSetChildProcessLabel API
The existing virSecurityManagerSetProcessLabel() API is designed so
that it must be called after forking the child process, but before
exec'ing the child. Due to the way the virCommand API works, that
means it needs to be put in a "hook" function that virCommand is told
to call out to at that time.
Setting the child process label is a basic enough need when executing
any process that virCommand should have a method of doing that. But
virCommand must be told what label to set, and only the security
driver knows the answer to that question.
The new virSecurityManagerSet*Child*ProcessLabel() API is the way to
transfer the knowledge about what label to set from the security
driver to the virCommand object. It is given a virCommandPtr, and each
security driver calls the appropriate virCommand* API to tell
virCommand what to do between fork and exec.
1) in the case of the DAC security driver, it calls
virCommandSetUID/GID() to set a uid and gid that must be set for the
child process.
2) for the SELinux security driver, it calls
virCommandSetSELinuxLabel() to save a copy of the char* that will be
sent to setexeccon_raw() *after forking the child process*.
3) for the AppArmor security drivers, it calls
virCommandSetAppArmorProfile() to save a copy of the char* that will
be sent to aa_change_profile() *after forking the child process*.
With this new API in place, we will be able to remove
virSecurityManagerSetProcessLabel() from any virCommand pre-exec
hooks.
(Unfortunately, the LXC driver uses clone() rather than virCommand, so
it can't take advantage of this new security driver API, meaning that
we need to keep around the older virSecurityManagerSetProcessLabel(),
at least for now.)
2013-02-01 15:02:03 -05:00
|
|
|
* Copyright (C) 2010-2013 Red Hat, Inc.
|
Refactor the security drivers to simplify usage
The current security driver usage requires horrible code like
if (driver->securityDriver &&
driver->securityDriver->domainSetSecurityHostdevLabel &&
driver->securityDriver->domainSetSecurityHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
This pair of checks for NULL clutters up the code, making the driver
calls 2 lines longer than they really need to be. The goal of the
patchset is to change the calling convention to simply
if (virSecurityManagerSetHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
The first check for 'driver->securityDriver' being NULL is removed
by introducing a 'no op' security driver that will always be present
if no real driver is enabled. This guarentees driver->securityDriver
!= NULL.
The second check for 'driver->securityDriver->domainSetSecurityHostdevLabel'
being non-NULL is hidden in a new abstraction called virSecurityManager.
This separates the driver callbacks, from main internal API. The addition
of a virSecurityManager object, that is separate from the virSecurityDriver
struct also allows for security drivers to carry state / configuration
information directly. Thus the DAC/Stack drivers from src/qemu which
used to pull config from 'struct qemud_driver' can now be moved into
the 'src/security' directory and store their config directly.
* src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update to
use new virSecurityManager APIs
* src/qemu/qemu_security_dac.c, src/qemu/qemu_security_dac.h
src/qemu/qemu_security_stacked.c, src/qemu/qemu_security_stacked.h:
Move into src/security directory
* src/security/security_stack.c, src/security/security_stack.h,
src/security/security_dac.c, src/security/security_dac.h: Generic
versions of previous QEMU specific drivers
* src/security/security_apparmor.c, src/security/security_apparmor.h,
src/security/security_driver.c, src/security/security_driver.h,
src/security/security_selinux.c, src/security/security_selinux.h:
Update to take virSecurityManagerPtr object as the first param
in all callbacks
* src/security/security_nop.c, src/security/security_nop.h: Stub
implementation of all security driver APIs.
* src/security/security_manager.h, src/security/security_manager.c:
New internal API for invoking security drivers
* src/libvirt.c: Add missing debug for security APIs
2010-11-17 20:26:30 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 16:30:55 -06:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 18:06:23 +08:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
Refactor the security drivers to simplify usage
The current security driver usage requires horrible code like
if (driver->securityDriver &&
driver->securityDriver->domainSetSecurityHostdevLabel &&
driver->securityDriver->domainSetSecurityHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
This pair of checks for NULL clutters up the code, making the driver
calls 2 lines longer than they really need to be. The goal of the
patchset is to change the calling convention to simply
if (virSecurityManagerSetHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
The first check for 'driver->securityDriver' being NULL is removed
by introducing a 'no op' security driver that will always be present
if no real driver is enabled. This guarentees driver->securityDriver
!= NULL.
The second check for 'driver->securityDriver->domainSetSecurityHostdevLabel'
being non-NULL is hidden in a new abstraction called virSecurityManager.
This separates the driver callbacks, from main internal API. The addition
of a virSecurityManager object, that is separate from the virSecurityDriver
struct also allows for security drivers to carry state / configuration
information directly. Thus the DAC/Stack drivers from src/qemu which
used to pull config from 'struct qemud_driver' can now be moved into
the 'src/security' directory and store their config directly.
* src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update to
use new virSecurityManager APIs
* src/qemu/qemu_security_dac.c, src/qemu/qemu_security_dac.h
src/qemu/qemu_security_stacked.c, src/qemu/qemu_security_stacked.h:
Move into src/security directory
* src/security/security_stack.c, src/security/security_stack.h,
src/security/security_dac.c, src/security/security_dac.h: Generic
versions of previous QEMU specific drivers
* src/security/security_apparmor.c, src/security/security_apparmor.h,
src/security/security_driver.c, src/security/security_driver.h,
src/security/security_selinux.c, src/security/security_selinux.h:
Update to take virSecurityManagerPtr object as the first param
in all callbacks
* src/security/security_nop.c, src/security/security_nop.h: Stub
implementation of all security driver APIs.
* src/security/security_manager.h, src/security/security_manager.c:
New internal API for invoking security drivers
* src/libvirt.c: Add missing debug for security APIs
2010-11-17 20:26:30 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-18 11:12:41 -05:00
|
|
|
#pragma once
|
Refactor the security drivers to simplify usage
The current security driver usage requires horrible code like
if (driver->securityDriver &&
driver->securityDriver->domainSetSecurityHostdevLabel &&
driver->securityDriver->domainSetSecurityHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
This pair of checks for NULL clutters up the code, making the driver
calls 2 lines longer than they really need to be. The goal of the
patchset is to change the calling convention to simply
if (virSecurityManagerSetHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
The first check for 'driver->securityDriver' being NULL is removed
by introducing a 'no op' security driver that will always be present
if no real driver is enabled. This guarentees driver->securityDriver
!= NULL.
The second check for 'driver->securityDriver->domainSetSecurityHostdevLabel'
being non-NULL is hidden in a new abstraction called virSecurityManager.
This separates the driver callbacks, from main internal API. The addition
of a virSecurityManager object, that is separate from the virSecurityDriver
struct also allows for security drivers to carry state / configuration
information directly. Thus the DAC/Stack drivers from src/qemu which
used to pull config from 'struct qemud_driver' can now be moved into
the 'src/security' directory and store their config directly.
* src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update to
use new virSecurityManager APIs
* src/qemu/qemu_security_dac.c, src/qemu/qemu_security_dac.h
src/qemu/qemu_security_stacked.c, src/qemu/qemu_security_stacked.h:
Move into src/security directory
* src/security/security_stack.c, src/security/security_stack.h,
src/security/security_dac.c, src/security/security_dac.h: Generic
versions of previous QEMU specific drivers
* src/security/security_apparmor.c, src/security/security_apparmor.h,
src/security/security_driver.c, src/security/security_driver.h,
src/security/security_selinux.c, src/security/security_selinux.h:
Update to take virSecurityManagerPtr object as the first param
in all callbacks
* src/security/security_nop.c, src/security/security_nop.h: Stub
implementation of all security driver APIs.
* src/security/security_manager.h, src/security/security_manager.c:
New internal API for invoking security drivers
* src/libvirt.c: Add missing debug for security APIs
2010-11-17 20:26:30 +00:00
|
|
|
|
2019-06-18 11:12:41 -05:00
|
|
|
#include "domain_conf.h"
|
|
|
|
#include "vircommand.h"
|
|
|
|
#include "virstoragefile.h"
|
2012-08-10 14:03:32 +01:00
|
|
|
|
Refactor the security drivers to simplify usage
The current security driver usage requires horrible code like
if (driver->securityDriver &&
driver->securityDriver->domainSetSecurityHostdevLabel &&
driver->securityDriver->domainSetSecurityHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
This pair of checks for NULL clutters up the code, making the driver
calls 2 lines longer than they really need to be. The goal of the
patchset is to change the calling convention to simply
if (virSecurityManagerSetHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
The first check for 'driver->securityDriver' being NULL is removed
by introducing a 'no op' security driver that will always be present
if no real driver is enabled. This guarentees driver->securityDriver
!= NULL.
The second check for 'driver->securityDriver->domainSetSecurityHostdevLabel'
being non-NULL is hidden in a new abstraction called virSecurityManager.
This separates the driver callbacks, from main internal API. The addition
of a virSecurityManager object, that is separate from the virSecurityDriver
struct also allows for security drivers to carry state / configuration
information directly. Thus the DAC/Stack drivers from src/qemu which
used to pull config from 'struct qemud_driver' can now be moved into
the 'src/security' directory and store their config directly.
* src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update to
use new virSecurityManager APIs
* src/qemu/qemu_security_dac.c, src/qemu/qemu_security_dac.h
src/qemu/qemu_security_stacked.c, src/qemu/qemu_security_stacked.h:
Move into src/security directory
* src/security/security_stack.c, src/security/security_stack.h,
src/security/security_dac.c, src/security/security_dac.h: Generic
versions of previous QEMU specific drivers
* src/security/security_apparmor.c, src/security/security_apparmor.h,
src/security/security_driver.c, src/security/security_driver.h,
src/security/security_selinux.c, src/security/security_selinux.h:
Update to take virSecurityManagerPtr object as the first param
in all callbacks
* src/security/security_nop.c, src/security/security_nop.h: Stub
implementation of all security driver APIs.
* src/security/security_manager.h, src/security/security_manager.c:
New internal API for invoking security drivers
* src/libvirt.c: Add missing debug for security APIs
2010-11-17 20:26:30 +00:00
|
|
|
typedef struct _virSecurityManager virSecurityManager;
|
|
|
|
|
2015-10-06 17:01:48 +02:00
|
|
|
typedef enum {
|
|
|
|
VIR_SECURITY_MANAGER_DEFAULT_CONFINED = 1 << 1,
|
|
|
|
VIR_SECURITY_MANAGER_REQUIRE_CONFINED = 1 << 2,
|
|
|
|
VIR_SECURITY_MANAGER_PRIVILEGED = 1 << 3,
|
|
|
|
VIR_SECURITY_MANAGER_DYNAMIC_OWNERSHIP = 1 << 4,
|
2017-08-27 11:23:47 -04:00
|
|
|
VIR_SECURITY_MANAGER_MOUNT_NAMESPACE = 1 << 5,
|
2015-10-06 17:01:48 +02:00
|
|
|
} virSecurityManagerNewFlags;
|
|
|
|
|
2019-06-18 11:12:41 -05:00
|
|
|
#define VIR_SECURITY_MANAGER_NEW_MASK \
|
2018-06-04 09:00:41 +02:00
|
|
|
(VIR_SECURITY_MANAGER_DEFAULT_CONFINED | \
|
2015-10-06 17:01:48 +02:00
|
|
|
VIR_SECURITY_MANAGER_REQUIRE_CONFINED | \
|
|
|
|
VIR_SECURITY_MANAGER_PRIVILEGED)
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
virSecurityManager *virSecurityManagerNew(const char *name,
|
2012-05-10 17:49:29 +01:00
|
|
|
const char *virtDriver,
|
2015-10-06 17:01:48 +02:00
|
|
|
unsigned int flags);
|
Refactor the security drivers to simplify usage
The current security driver usage requires horrible code like
if (driver->securityDriver &&
driver->securityDriver->domainSetSecurityHostdevLabel &&
driver->securityDriver->domainSetSecurityHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
This pair of checks for NULL clutters up the code, making the driver
calls 2 lines longer than they really need to be. The goal of the
patchset is to change the calling convention to simply
if (virSecurityManagerSetHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
The first check for 'driver->securityDriver' being NULL is removed
by introducing a 'no op' security driver that will always be present
if no real driver is enabled. This guarentees driver->securityDriver
!= NULL.
The second check for 'driver->securityDriver->domainSetSecurityHostdevLabel'
being non-NULL is hidden in a new abstraction called virSecurityManager.
This separates the driver callbacks, from main internal API. The addition
of a virSecurityManager object, that is separate from the virSecurityDriver
struct also allows for security drivers to carry state / configuration
information directly. Thus the DAC/Stack drivers from src/qemu which
used to pull config from 'struct qemud_driver' can now be moved into
the 'src/security' directory and store their config directly.
* src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update to
use new virSecurityManager APIs
* src/qemu/qemu_security_dac.c, src/qemu/qemu_security_dac.h
src/qemu/qemu_security_stacked.c, src/qemu/qemu_security_stacked.h:
Move into src/security directory
* src/security/security_stack.c, src/security/security_stack.h,
src/security/security_dac.c, src/security/security_dac.h: Generic
versions of previous QEMU specific drivers
* src/security/security_apparmor.c, src/security/security_apparmor.h,
src/security/security_driver.c, src/security/security_driver.h,
src/security/security_selinux.c, src/security/security_selinux.h:
Update to take virSecurityManagerPtr object as the first param
in all callbacks
* src/security/security_nop.c, src/security/security_nop.h: Stub
implementation of all security driver APIs.
* src/security/security_manager.h, src/security/security_manager.c:
New internal API for invoking security drivers
* src/libvirt.c: Add missing debug for security APIs
2010-11-17 20:26:30 +00:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
virSecurityManager *virSecurityManagerNewStack(virSecurityManager *primary);
|
|
|
|
int virSecurityManagerStackAddNested(virSecurityManager *stack,
|
|
|
|
virSecurityManager *nested);
|
Refactor the security drivers to simplify usage
The current security driver usage requires horrible code like
if (driver->securityDriver &&
driver->securityDriver->domainSetSecurityHostdevLabel &&
driver->securityDriver->domainSetSecurityHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
This pair of checks for NULL clutters up the code, making the driver
calls 2 lines longer than they really need to be. The goal of the
patchset is to change the calling convention to simply
if (virSecurityManagerSetHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
The first check for 'driver->securityDriver' being NULL is removed
by introducing a 'no op' security driver that will always be present
if no real driver is enabled. This guarentees driver->securityDriver
!= NULL.
The second check for 'driver->securityDriver->domainSetSecurityHostdevLabel'
being non-NULL is hidden in a new abstraction called virSecurityManager.
This separates the driver callbacks, from main internal API. The addition
of a virSecurityManager object, that is separate from the virSecurityDriver
struct also allows for security drivers to carry state / configuration
information directly. Thus the DAC/Stack drivers from src/qemu which
used to pull config from 'struct qemud_driver' can now be moved into
the 'src/security' directory and store their config directly.
* src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update to
use new virSecurityManager APIs
* src/qemu/qemu_security_dac.c, src/qemu/qemu_security_dac.h
src/qemu/qemu_security_stacked.c, src/qemu/qemu_security_stacked.h:
Move into src/security directory
* src/security/security_stack.c, src/security/security_stack.h,
src/security/security_dac.c, src/security/security_dac.h: Generic
versions of previous QEMU specific drivers
* src/security/security_apparmor.c, src/security/security_apparmor.h,
src/security/security_driver.c, src/security/security_driver.h,
src/security/security_selinux.c, src/security/security_selinux.h:
Update to take virSecurityManagerPtr object as the first param
in all callbacks
* src/security/security_nop.c, src/security/security_nop.h: Stub
implementation of all security driver APIs.
* src/security/security_manager.h, src/security/security_manager.c:
New internal API for invoking security drivers
* src/libvirt.c: Add missing debug for security APIs
2010-11-17 20:26:30 +00:00
|
|
|
|
2014-07-10 14:17:24 +02:00
|
|
|
/**
|
|
|
|
* virSecurityManagerDACChownCallback:
|
|
|
|
* @src: Storage file to chown
|
|
|
|
* @uid: target uid
|
|
|
|
* @gid: target gid
|
|
|
|
*
|
|
|
|
* A function callback to chown image files described by the disk source struct
|
|
|
|
* @src. The callback shall return 0 on success, -1 on error and errno set (no
|
|
|
|
* libvirt error reported) OR -2 and a libvirt error reported. */
|
|
|
|
typedef int
|
2016-12-14 15:25:22 +01:00
|
|
|
(*virSecurityManagerDACChownCallback)(const virStorageSource *src,
|
2014-07-10 14:17:24 +02:00
|
|
|
uid_t uid,
|
|
|
|
gid_t gid);
|
|
|
|
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
virSecurityManager *virSecurityManagerNewDAC(const char *virtDriver,
|
2012-05-10 17:49:29 +01:00
|
|
|
uid_t user,
|
Refactor the security drivers to simplify usage
The current security driver usage requires horrible code like
if (driver->securityDriver &&
driver->securityDriver->domainSetSecurityHostdevLabel &&
driver->securityDriver->domainSetSecurityHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
This pair of checks for NULL clutters up the code, making the driver
calls 2 lines longer than they really need to be. The goal of the
patchset is to change the calling convention to simply
if (virSecurityManagerSetHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
The first check for 'driver->securityDriver' being NULL is removed
by introducing a 'no op' security driver that will always be present
if no real driver is enabled. This guarentees driver->securityDriver
!= NULL.
The second check for 'driver->securityDriver->domainSetSecurityHostdevLabel'
being non-NULL is hidden in a new abstraction called virSecurityManager.
This separates the driver callbacks, from main internal API. The addition
of a virSecurityManager object, that is separate from the virSecurityDriver
struct also allows for security drivers to carry state / configuration
information directly. Thus the DAC/Stack drivers from src/qemu which
used to pull config from 'struct qemud_driver' can now be moved into
the 'src/security' directory and store their config directly.
* src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update to
use new virSecurityManager APIs
* src/qemu/qemu_security_dac.c, src/qemu/qemu_security_dac.h
src/qemu/qemu_security_stacked.c, src/qemu/qemu_security_stacked.h:
Move into src/security directory
* src/security/security_stack.c, src/security/security_stack.h,
src/security/security_dac.c, src/security/security_dac.h: Generic
versions of previous QEMU specific drivers
* src/security/security_apparmor.c, src/security/security_apparmor.h,
src/security/security_driver.c, src/security/security_driver.h,
src/security/security_selinux.c, src/security/security_selinux.h:
Update to take virSecurityManagerPtr object as the first param
in all callbacks
* src/security/security_nop.c, src/security/security_nop.h: Stub
implementation of all security driver APIs.
* src/security/security_manager.h, src/security/security_manager.c:
New internal API for invoking security drivers
* src/libvirt.c: Add missing debug for security APIs
2010-11-17 20:26:30 +00:00
|
|
|
gid_t group,
|
2015-10-06 17:01:48 +02:00
|
|
|
unsigned int flags,
|
2014-07-10 14:17:24 +02:00
|
|
|
virSecurityManagerDACChownCallback chownCallback);
|
Refactor the security drivers to simplify usage
The current security driver usage requires horrible code like
if (driver->securityDriver &&
driver->securityDriver->domainSetSecurityHostdevLabel &&
driver->securityDriver->domainSetSecurityHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
This pair of checks for NULL clutters up the code, making the driver
calls 2 lines longer than they really need to be. The goal of the
patchset is to change the calling convention to simply
if (virSecurityManagerSetHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
The first check for 'driver->securityDriver' being NULL is removed
by introducing a 'no op' security driver that will always be present
if no real driver is enabled. This guarentees driver->securityDriver
!= NULL.
The second check for 'driver->securityDriver->domainSetSecurityHostdevLabel'
being non-NULL is hidden in a new abstraction called virSecurityManager.
This separates the driver callbacks, from main internal API. The addition
of a virSecurityManager object, that is separate from the virSecurityDriver
struct also allows for security drivers to carry state / configuration
information directly. Thus the DAC/Stack drivers from src/qemu which
used to pull config from 'struct qemud_driver' can now be moved into
the 'src/security' directory and store their config directly.
* src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update to
use new virSecurityManager APIs
* src/qemu/qemu_security_dac.c, src/qemu/qemu_security_dac.h
src/qemu/qemu_security_stacked.c, src/qemu/qemu_security_stacked.h:
Move into src/security directory
* src/security/security_stack.c, src/security/security_stack.h,
src/security/security_dac.c, src/security/security_dac.h: Generic
versions of previous QEMU specific drivers
* src/security/security_apparmor.c, src/security/security_apparmor.h,
src/security/security_driver.c, src/security/security_driver.h,
src/security/security_selinux.c, src/security/security_selinux.h:
Update to take virSecurityManagerPtr object as the first param
in all callbacks
* src/security/security_nop.c, src/security/security_nop.h: Stub
implementation of all security driver APIs.
* src/security/security_manager.h, src/security/security_manager.c:
New internal API for invoking security drivers
* src/libvirt.c: Add missing debug for security APIs
2010-11-17 20:26:30 +00:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerPreFork(virSecurityManager *mgr);
|
|
|
|
void virSecurityManagerPostFork(virSecurityManager *mgr);
|
2013-02-11 16:08:42 +00:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerTransactionStart(virSecurityManager *mgr);
|
|
|
|
int virSecurityManagerTransactionCommit(virSecurityManager *mgr,
|
2018-11-13 10:57:25 +01:00
|
|
|
pid_t pid,
|
|
|
|
bool lock);
|
2021-03-11 08:16:13 +01:00
|
|
|
void virSecurityManagerTransactionAbort(virSecurityManager *mgr);
|
|
|
|
|
|
|
|
void *virSecurityManagerGetPrivateData(virSecurityManager *mgr);
|
|
|
|
|
|
|
|
const char *virSecurityManagerGetDriver(virSecurityManager *mgr);
|
|
|
|
const char *virSecurityManagerGetVirtDriver(virSecurityManager *mgr);
|
|
|
|
const char *virSecurityManagerGetDOI(virSecurityManager *mgr);
|
|
|
|
const char *virSecurityManagerGetModel(virSecurityManager *mgr);
|
|
|
|
const char *virSecurityManagerGetBaseLabel(virSecurityManager *mgr, int virtType);
|
|
|
|
|
|
|
|
bool virSecurityManagerGetDefaultConfined(virSecurityManager *mgr);
|
|
|
|
bool virSecurityManagerGetRequireConfined(virSecurityManager *mgr);
|
|
|
|
bool virSecurityManagerGetPrivileged(virSecurityManager *mgr);
|
|
|
|
|
|
|
|
int virSecurityManagerSetDaemonSocketLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm);
|
|
|
|
int virSecurityManagerSetSocketLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def);
|
|
|
|
int virSecurityManagerClearSocketLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def);
|
|
|
|
int virSecurityManagerRestoreHostdevLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def,
|
|
|
|
virDomainHostdevDef *dev,
|
2012-11-27 16:17:47 +00:00
|
|
|
const char *vroot);
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerSetHostdevLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def,
|
|
|
|
virDomainHostdevDef *dev,
|
2012-11-27 16:17:47 +00:00
|
|
|
const char *vroot);
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerSetSavedStateLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def,
|
2020-06-26 17:05:39 +02:00
|
|
|
const char *savefile);
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerRestoreSavedStateLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def,
|
2020-06-26 17:05:39 +02:00
|
|
|
const char *savefile);
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerGenLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *sec);
|
|
|
|
int virSecurityManagerReserveLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *sec,
|
Change security driver APIs to use virDomainDefPtr instead of virDomainObjPtr
When sVirt is integrated with the LXC driver, it will be neccessary
to invoke the security driver APIs using only a virDomainDefPtr
since the lxc_container.c code has no virDomainObjPtr available.
Aside from two functions which want obj->pid, every bit of the
security driver code only touches obj->def. So we don't need to
pass a virDomainObjPtr into the security drivers, a virDomainDefPtr
is sufficient. Two functions also gain a 'pid_t pid' argument.
* src/qemu/qemu_driver.c, src/qemu/qemu_hotplug.c,
src/qemu/qemu_migration.c, src/qemu/qemu_process.c,
src/security/security_apparmor.c,
src/security/security_dac.c,
src/security/security_driver.h,
src/security/security_manager.c,
src/security/security_manager.h,
src/security/security_nop.c,
src/security/security_selinux.c,
src/security/security_stack.c: Change all security APIs to use a
virDomainDefPtr instead of virDomainObjPtr
2011-07-14 14:32:06 +01:00
|
|
|
pid_t pid);
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerReleaseLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *sec);
|
|
|
|
int virSecurityManagerCheckAllLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *sec);
|
|
|
|
int virSecurityManagerSetAllLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *sec,
|
2020-07-01 11:50:00 +02:00
|
|
|
const char *incomingPath,
|
2019-09-11 07:53:09 +02:00
|
|
|
bool chardevStdioLogd,
|
|
|
|
bool migrated);
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerRestoreAllLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def,
|
2017-05-29 14:27:51 +02:00
|
|
|
bool migrated,
|
|
|
|
bool chardevStdioLogd);
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerGetProcessLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def,
|
Change security driver APIs to use virDomainDefPtr instead of virDomainObjPtr
When sVirt is integrated with the LXC driver, it will be neccessary
to invoke the security driver APIs using only a virDomainDefPtr
since the lxc_container.c code has no virDomainObjPtr available.
Aside from two functions which want obj->pid, every bit of the
security driver code only touches obj->def. So we don't need to
pass a virDomainObjPtr into the security drivers, a virDomainDefPtr
is sufficient. Two functions also gain a 'pid_t pid' argument.
* src/qemu/qemu_driver.c, src/qemu/qemu_hotplug.c,
src/qemu/qemu_migration.c, src/qemu/qemu_process.c,
src/security/security_apparmor.c,
src/security/security_dac.c,
src/security/security_driver.h,
src/security/security_manager.c,
src/security/security_manager.h,
src/security/security_nop.c,
src/security/security_selinux.c,
src/security/security_stack.c: Change all security APIs to use a
virDomainDefPtr instead of virDomainObjPtr
2011-07-14 14:32:06 +01:00
|
|
|
pid_t pid,
|
Refactor the security drivers to simplify usage
The current security driver usage requires horrible code like
if (driver->securityDriver &&
driver->securityDriver->domainSetSecurityHostdevLabel &&
driver->securityDriver->domainSetSecurityHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
This pair of checks for NULL clutters up the code, making the driver
calls 2 lines longer than they really need to be. The goal of the
patchset is to change the calling convention to simply
if (virSecurityManagerSetHostdevLabel(driver->securityDriver,
vm, hostdev) < 0)
The first check for 'driver->securityDriver' being NULL is removed
by introducing a 'no op' security driver that will always be present
if no real driver is enabled. This guarentees driver->securityDriver
!= NULL.
The second check for 'driver->securityDriver->domainSetSecurityHostdevLabel'
being non-NULL is hidden in a new abstraction called virSecurityManager.
This separates the driver callbacks, from main internal API. The addition
of a virSecurityManager object, that is separate from the virSecurityDriver
struct also allows for security drivers to carry state / configuration
information directly. Thus the DAC/Stack drivers from src/qemu which
used to pull config from 'struct qemud_driver' can now be moved into
the 'src/security' directory and store their config directly.
* src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update to
use new virSecurityManager APIs
* src/qemu/qemu_security_dac.c, src/qemu/qemu_security_dac.h
src/qemu/qemu_security_stacked.c, src/qemu/qemu_security_stacked.h:
Move into src/security directory
* src/security/security_stack.c, src/security/security_stack.h,
src/security/security_dac.c, src/security/security_dac.h: Generic
versions of previous QEMU specific drivers
* src/security/security_apparmor.c, src/security/security_apparmor.h,
src/security/security_driver.c, src/security/security_driver.h,
src/security/security_selinux.c, src/security/security_selinux.h:
Update to take virSecurityManagerPtr object as the first param
in all callbacks
* src/security/security_nop.c, src/security/security_nop.h: Stub
implementation of all security driver APIs.
* src/security/security_manager.h, src/security/security_manager.c:
New internal API for invoking security drivers
* src/libvirt.c: Add missing debug for security APIs
2010-11-17 20:26:30 +00:00
|
|
|
virSecurityLabelPtr sec);
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerSetProcessLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def);
|
|
|
|
int virSecurityManagerSetChildProcessLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def,
|
|
|
|
virCommand *cmd);
|
|
|
|
int virSecurityManagerVerify(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def);
|
|
|
|
int virSecurityManagerSetImageFDLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def,
|
2011-06-24 14:43:43 +01:00
|
|
|
int fd);
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerSetTapFDLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm,
|
2012-10-15 17:03:49 +08:00
|
|
|
int fd);
|
2021-03-11 08:16:13 +01:00
|
|
|
char *virSecurityManagerGetMountOptions(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm);
|
|
|
|
virSecurityManager ** virSecurityManagerGetNested(virSecurityManager *mgr);
|
2012-08-15 19:10:37 -03:00
|
|
|
|
2019-01-23 11:50:33 +01:00
|
|
|
typedef enum {
|
|
|
|
VIR_SECURITY_DOMAIN_IMAGE_LABEL_BACKING_CHAIN = 1 << 0,
|
2020-02-27 11:06:22 +01:00
|
|
|
/* The VIR_SECURITY_DOMAIN_IMAGE_PARENT_CHAIN_TOP should be set if the
|
|
|
|
* image passed to virSecurityManagerSetImageLabel() is the top parent of
|
|
|
|
* the whole backing chain. */
|
|
|
|
VIR_SECURITY_DOMAIN_IMAGE_PARENT_CHAIN_TOP = 1 << 1,
|
2019-01-23 11:50:33 +01:00
|
|
|
} virSecurityDomainImageLabelFlags;
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerSetImageLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm,
|
|
|
|
virStorageSource *src,
|
2019-01-23 11:50:33 +01:00
|
|
|
virSecurityDomainImageLabelFlags flags);
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerRestoreImageLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm,
|
|
|
|
virStorageSource *src,
|
2019-01-23 11:50:33 +01:00
|
|
|
virSecurityDomainImageLabelFlags flags);
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerMoveImageMetadata(virSecurityManager *mgr,
|
2019-03-21 11:44:21 +01:00
|
|
|
pid_t pid,
|
2021-03-11 08:16:13 +01:00
|
|
|
virStorageSource *src,
|
|
|
|
virStorageSource *dst);
|
|
|
|
|
|
|
|
int virSecurityManagerSetMemoryLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm,
|
|
|
|
virDomainMemoryDef *mem);
|
|
|
|
int virSecurityManagerRestoreMemoryLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm,
|
|
|
|
virDomainMemoryDef *mem);
|
|
|
|
|
|
|
|
int virSecurityManagerSetInputLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm,
|
|
|
|
virDomainInputDef *input);
|
|
|
|
int virSecurityManagerRestoreInputLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm,
|
|
|
|
virDomainInputDef *input);
|
|
|
|
|
|
|
|
int virSecurityManagerDomainSetPathLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm,
|
2018-01-09 16:04:03 +01:00
|
|
|
const char *path,
|
|
|
|
bool allowSubtree);
|
2015-08-17 10:43:43 -07:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerDomainSetPathLabelRO(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm,
|
2020-04-03 14:31:35 +02:00
|
|
|
const char *path);
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerDomainRestorePathLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def,
|
2020-06-17 11:32:53 +02:00
|
|
|
const char *path);
|
|
|
|
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerSetChardevLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def,
|
|
|
|
virDomainChrSourceDef *dev_source,
|
2017-12-01 10:39:26 +01:00
|
|
|
bool chardevStdioLogd);
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerRestoreChardevLabel(virSecurityManager *mgr,
|
|
|
|
virDomainDef *def,
|
|
|
|
virDomainChrSourceDef *dev_source,
|
2017-12-01 10:39:26 +01:00
|
|
|
bool chardevStdioLogd);
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerSetTPMLabels(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm);
|
2018-04-04 12:40:32 -04:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virSecurityManagerRestoreTPMLabels(virSecurityManager *mgr,
|
|
|
|
virDomainDef *vm);
|
2018-04-04 12:40:32 -04:00
|
|
|
|
2018-10-02 14:47:20 +02:00
|
|
|
typedef struct _virSecurityManagerMetadataLockState virSecurityManagerMetadataLockState;
|
2020-02-20 15:38:10 +01:00
|
|
|
struct _virSecurityManagerMetadataLockState {
|
|
|
|
size_t nfds; /* Captures size of both @fds and @paths */
|
|
|
|
int *fds;
|
|
|
|
const char **paths;
|
|
|
|
};
|
|
|
|
|
2018-10-02 14:47:20 +02:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
virSecurityManagerMetadataLockState *
|
|
|
|
virSecurityManagerMetadataLock(virSecurityManager *mgr,
|
2018-10-02 14:47:20 +02:00
|
|
|
const char **paths,
|
|
|
|
size_t npaths);
|
|
|
|
|
|
|
|
void
|
2021-03-11 08:16:13 +01:00
|
|
|
virSecurityManagerMetadataUnlock(virSecurityManager *mgr,
|
|
|
|
virSecurityManagerMetadataLockState **state);
|