Sophie

Sophie

distrib > Fedora > 20 > x86_64 > by-pkgid > 61fdd74826134151e6379e5dac3cf74d > files > 7

libvirt-docs-1.1.3.8-1.fc20.x86_64.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
        This file is autogenerated from aclpolkit.html.in
        Do not edit this file. Changes will be lost.
      -->
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css" href="main.css" />
    <link rel="SHORTCUT ICON" href="32favicon.png" />
    <title>libvirt: Polkit access control</title>
    <meta name="description" content="libvirt, virtualization, virtualization API" />
  </head>
  <body>
    <div id="header">
      <div id="headerLogo"></div>
      <div id="headerSearch">
        <form action="search.php" enctype="application/x-www-form-urlencoded" method="get"><div>
            <input id="query" name="query" type="text" size="12" value="" />
            <input id="submit" name="submit" type="submit" value="Search" />
          </div></form>
      </div>
    </div>
    <div id="body">
      <div id="menu">
        <ul class="l0"><li>
            <div>
              <a title="Front page of the libvirt website" class="inactive" href="index.html">Home</a>
            </div>
          </li><li>
            <div>
              <a title="Details of new features and bugs fixed in each release" class="inactive" href="news.html">News</a>
            </div>
          </li><li>
            <div>
              <a title="Applications known to use libvirt" class="inactive" href="apps.html">Applications</a>
            </div>
          </li><li>
            <div>
              <a title="Get the latest source releases, binary builds and get access to the source repository" class="inactive" href="downloads.html">Downloads</a>
            </div>
          </li><li>
            <div>
              <a title="Information for users, administrators and developers" class="active" href="docs.html">Documentation</a>
              <ul class="l1"><li>
                  <div>
                    <a title="How to compile libvirt" class="inactive" href="compiling.html">Compiling</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Information about deploying and using libvirt" class="active" href="deployment.html">Deployment</a>
                    <ul class="l2"><li>
                        <div>
                          <a title="The URI formats used for connecting to libvirt" class="inactive" href="uri.html">URI format</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Enable remote access over TCP" class="inactive" href="remote.html">Remote access</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Configure authentication for the libvirt daemon" class="inactive" href="auth.html">Authentication</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Configure access control libvirt APIs" class="active" href="acl.html">Access control</a>
                          <ul class="l3"><li>
                              <div>
                                <span class="active">Polkit access control</span>
                              </div>
                            </li></ul>
                        </div>
                      </li><li>
                        <div>
                          <a title="Migrating guests between machines" class="inactive" href="migration.html">Migration</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Access the libvirt daemon from a native Windows client" class="inactive" href="windows.html">Windows port</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="The library and the daemon logging support" class="inactive" href="logging.html">Logging</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Firewall and network filter configuration" class="inactive" href="firewall.html">Firewall</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Ensuring exclusive guest access to disks" class="inactive" href="locking.html">Disk locking</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Control groups integration" class="inactive" href="cgroups.html">CGroups</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Hooks for system specific management" class="inactive" href="hooks.html">Hooks</a>
                        </div>
                      </li></ul>
                  </div>
                </li><li>
                  <div>
                    <a title="Overview of the logical subsystems in the libvirt API" class="inactive" href="intro.html">Architecture</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Description of the XML formats used in libvirt" class="inactive" href="format.html">XML format</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Hypervisor specific driver information" class="inactive" href="drivers.html">Drivers</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Reference manual for the C public API" class="inactive" href="html/index.html">API reference</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Bindings of the libvirt API for other languages" class="inactive" href="bindings.html">Language bindings</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Working on the internals of libvirt API, driver and daemon code" class="inactive" href="internals.html">Internals</a>
                  </div>
                </li><li>
                  <div>
                    <a title="A guide and reference for developing with libvirt" class="inactive" href="devguide.html">Development Guide</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Command reference for virsh" class="inactive" href="virshcmdref.html">Virsh Commands</a>
                  </div>
                </li></ul>
            </div>
          </li><li>
            <div>
              <a title="User contributed content" class="inactive" href="http://wiki.libvirt.org">Wiki</a>
            </div>
          </li><li>
            <div>
              <a title="Frequently asked questions" class="inactive" href="http://wiki.libvirt.org/page/FAQ">FAQ</a>
            </div>
          </li><li>
            <div>
              <a title="How and where to report bugs and request features" class="inactive" href="bugs.html">Bug reports</a>
            </div>
          </li><li>
            <div>
              <a title="How to contact the developers via email and IRC" class="inactive" href="contact.html">Contact</a>
            </div>
          </li><li>
            <div>
              <a title="Available test suites for libvirt" class="inactive" href="testsuites.html">Test suites</a>
            </div>
          </li><li>
            <div>
              <a title="Miscellaneous links of interest related to libvirt" class="inactive" href="relatedlinks.html">Related Links</a>
            </div>
          </li><li>
            <div>
              <a title="Overview of all content on the website" class="inactive" href="sitemap.html">Sitemap</a>
            </div>
          </li></ul>
      </div>
      <div id="content">
        <h1>Polkit access control</h1>
        <p>
      Libvirt's client <a href="acl.html" shape="rect">access control framework</a> allows
      administrators to setup fine grained permission rules across client users,
      managed objects and API operations. This allows client connections
      to be locked down to a minimal set of privileges. The polkit driver
      provides a simple implementation of the access control framework.
    </p>
        <ul><li>
            <a href="#intro">Introduction</a>
          </li><li>
            <a href="#perms">Permission names</a>
          </li><li>
            <a href="#attrs">Object identity attributes</a>
            <ul><li>
                <a href="#object_connect">virConnectPtr</a>
              </li><li>
                <a href="#object_domain">virDomainPtr</a>
              </li><li>
                <a href="#object_interface">virInterfacePtr</a>
              </li><li>
                <a href="#object_network">virNetworkPtr</a>
              </li><li>
                <a href="#object_node_device">virNodeDevicePtr</a>
              </li><li>
                <a href="#object_nwfilter">virNWFilterPtr</a>
              </li><li>
                <a href="#object_secret">virSecretPtr</a>
              </li><li>
                <a href="#object_storage_pool">virStoragePoolPtr</a>
              </li><li>
                <a href="#object_storage_vol">virStorageVolPtr</a>
              </li></ul>
          </li><li>
            <a href="#user">User identity attributes</a>
          </li><li>
            <a href="#checks">Writing acces control policies</a>
            <ul><li>
                <a href="#exconnect">Example: restricting ability to connect to drivers</a>
              </li><li>
                <a href="#exdomain">Example: restricting access to a single domain</a>
              </li></ul>
          </li></ul>
        <h2>
          <a name="intro" shape="rect" id="intro">Introduction</a>
        </h2>
        <p>
      A default install of libvirt will typically use
      <a href="http://www.freedesktop.org/wiki/Software/polkit/" shape="rect">polkit</a>
      to authenticate the initial user connection to libvirtd. This is a
      very coarse grained check though, either allowing full read-write
      access to all APIs, or just read-only access. The polkit access
      control driver in libvirt builds on this capability to allow for
      fine grained control over the operations a user may perform on an
      object.
    </p>
        <h2>
          <a name="perms" shape="rect" id="perms">Permission names</a>
        </h2>
        <p>
      The libvirt <a href="acl.html#perms" shape="rect">object names and permission names</a>
      are mapped onto polkit action names using the simple pattern:
    </p>
        <pre xml:space="preserve">org.libvirt.api.$object.$permission
</pre>
        <p>
      The only caveat is that any underscore characters in the
      object or permission names are converted to hyphens. So,
      for example, the <code>search_storage_vols</code> permission
      on the <code>storage_pool</code> object maps to the polkit
      action:
    </p>
        <pre xml:space="preserve">org.libvirt.api.storage-pool.search-storage-vols
</pre>
        <p>
      The default policy for any permission which corresponds to
      a "read only" operation, is to allow access. All other
      permissions default to deny access.
    </p>
        <h2>
          <a name="attrs" shape="rect" id="attrs">Object identity attributes</a>
        </h2>
        <p>
      To allow polkit authorization rules to be written to match
      against individual object instances, libvirt provides a number
      of authorization detail attributes when performing a permission
      check. The set of attributes varies according to the type
      of object being checked
    </p>
        <h3>
          <a name="object_connect" shape="rect" id="object_connect">virConnectPtr</a>
        </h3>
        <table class="acl"><thead><tr><th rowspan="1" colspan="1">Attribute</th><th rowspan="1" colspan="1">Description</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">connect_driver</td><td rowspan="1" colspan="1">Name of the libvirt connection driver</td></tr></tbody></table>
        <h3>
          <a name="object_domain" shape="rect" id="object_domain">virDomainPtr</a>
        </h3>
        <table class="acl"><thead><tr><th rowspan="1" colspan="1">Attribute</th><th rowspan="1" colspan="1">Description</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">connect_driver</td><td rowspan="1" colspan="1">Name of the libvirt connection driver</td></tr><tr><td rowspan="1" colspan="1">domain_name</td><td rowspan="1" colspan="1">Name of the domain, unique to the local host</td></tr><tr><td rowspan="1" colspan="1">domain_uuid</td><td rowspan="1" colspan="1">UUID of the domain, globally unique</td></tr></tbody></table>
        <h3>
          <a name="object_interface" shape="rect" id="object_interface">virInterfacePtr</a>
        </h3>
        <table class="acl"><thead><tr><th rowspan="1" colspan="1">Attribute</th><th rowspan="1" colspan="1">Description</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">connect_driver</td><td rowspan="1" colspan="1">Name of the libvirt connection driver</td></tr><tr><td rowspan="1" colspan="1">interface_name</td><td rowspan="1" colspan="1">Name of the network interface, unique to the local host</td></tr><tr><td rowspan="1" colspan="1">interface_mac</td><td rowspan="1" colspan="1">MAC address of the network interface, not unique</td></tr></tbody></table>
        <h3>
          <a name="object_network" shape="rect" id="object_network">virNetworkPtr</a>
        </h3>
        <table class="acl"><thead><tr><th rowspan="1" colspan="1">Attribute</th><th rowspan="1" colspan="1">Description</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">connect_driver</td><td rowspan="1" colspan="1">Name of the libvirt connection driver</td></tr><tr><td rowspan="1" colspan="1">network_name</td><td rowspan="1" colspan="1">Name of the network, unique to the local host</td></tr><tr><td rowspan="1" colspan="1">network_uuid</td><td rowspan="1" colspan="1">UUID of the network, globally unique</td></tr></tbody></table>
        <h3>
          <a name="object_node_device" shape="rect" id="object_node_device">virNodeDevicePtr</a>
        </h3>
        <table class="acl"><thead><tr><th rowspan="1" colspan="1">Attribute</th><th rowspan="1" colspan="1">Description</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">connect_driver</td><td rowspan="1" colspan="1">Name of the libvirt connection driver</td></tr><tr><td rowspan="1" colspan="1">node_device_name</td><td rowspan="1" colspan="1">Name of the node device, unique to the local host</td></tr></tbody></table>
        <h3>
          <a name="object_nwfilter" shape="rect" id="object_nwfilter">virNWFilterPtr</a>
        </h3>
        <table class="acl"><thead><tr><th rowspan="1" colspan="1">Attribute</th><th rowspan="1" colspan="1">Description</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">connect_driver</td><td rowspan="1" colspan="1">Name of the libvirt connection driver</td></tr><tr><td rowspan="1" colspan="1">nwfilter_name</td><td rowspan="1" colspan="1">Name of the network filter, unique to the local host</td></tr><tr><td rowspan="1" colspan="1">nwfilter_uuid</td><td rowspan="1" colspan="1">UUID of the network filter, globally unique</td></tr></tbody></table>
        <h3>
          <a name="object_secret" shape="rect" id="object_secret">virSecretPtr</a>
        </h3>
        <table class="acl"><thead><tr><th rowspan="1" colspan="1">Attribute</th><th rowspan="1" colspan="1">Description</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">connect_driver</td><td rowspan="1" colspan="1">Name of the libvirt connection driver</td></tr><tr><td rowspan="1" colspan="1">secret_uuid</td><td rowspan="1" colspan="1">UUID of the secret, globally unique</td></tr><tr><td rowspan="1" colspan="1">secret_usage_volume</td><td rowspan="1" colspan="1">Name of the associated volume, if any</td></tr><tr><td rowspan="1" colspan="1">secret_usage_ceph</td><td rowspan="1" colspan="1">Name of the associated Ceph server, if any</td></tr><tr><td rowspan="1" colspan="1">secret_usage_target</td><td rowspan="1" colspan="1">Name of the associated iSCSI target, if any</td></tr></tbody></table>
        <h3>
          <a name="object_storage_pool" shape="rect" id="object_storage_pool">virStoragePoolPtr</a>
        </h3>
        <table class="acl"><thead><tr><th rowspan="1" colspan="1">Attribute</th><th rowspan="1" colspan="1">Description</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">connect_driver</td><td rowspan="1" colspan="1">Name of the libvirt connection driver</td></tr><tr><td rowspan="1" colspan="1">pool_name</td><td rowspan="1" colspan="1">Name of the storage pool, unique to the local host</td></tr><tr><td rowspan="1" colspan="1">pool_uuid</td><td rowspan="1" colspan="1">UUID of the storage pool, globally unique</td></tr></tbody></table>
        <h3>
          <a name="object_storage_vol" shape="rect" id="object_storage_vol">virStorageVolPtr</a>
        </h3>
        <table class="acl"><thead><tr><th rowspan="1" colspan="1">Attribute</th><th rowspan="1" colspan="1">Description</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">connect_driver</td><td rowspan="1" colspan="1">Name of the libvirt connection driver</td></tr><tr><td rowspan="1" colspan="1">pool_name</td><td rowspan="1" colspan="1">Name of the storage pool, unique to the local host</td></tr><tr><td rowspan="1" colspan="1">pool_uuid</td><td rowspan="1" colspan="1">UUID of the storage pool, globally unique</td></tr><tr><td rowspan="1" colspan="1">vol_name</td><td rowspan="1" colspan="1">Name of the storage volume, unique to the pool</td></tr><tr><td rowspan="1" colspan="1">vol_key</td><td rowspan="1" colspan="1">Key of the storage volume, globally unique</td></tr></tbody></table>
        <h2>
          <a name="user" shape="rect" id="user">User identity attributes</a>
        </h2>
        <p>
      At this point in time, the only attribute provided by
      libvirt to identify the user invoking the operation
      is the PID of the client program. This means that the
      polkit access control driver is only useful if connections
      to libvirt are restricted to its UNIX domain socket. If
      connections are being made to a TCP socket, no identifying
      information is available and access will be denied.
      Also note that if the client is connecting via an SSH
      tunnel, it is the local SSH user that will be identified.
      In future versions, it is expected that more information
      about the client user will be provided, including the
      SASL / Kerberos username and/or x509 distinguished
      name obtained from the authentication provider in use.
    </p>
        <h2>
          <a name="checks" shape="rect" id="checks">Writing acces control policies</a>
        </h2>
        <p>
      If using versions of polkit prior to 0.106 then it is only
      possible to validate (user, permission) pairs via the <code>.pkla</code>
      files. Fully validation of the (user, permission, object) triple
      requires the new JavaScript <code>.rules</code> support that
      was introduced in version 0.106. The latter is what will be
      described here.
    </p>
        <p>
      Libvirt does not ship any rules files by default. It merely
      provides a definition of the default behaviour for each
      action (permission). As noted earlier, permissions which
      correspond to read-only operations in libvirt will be allowed
      to all users by default; everything else is denied by default.
      Defining custom rules requires creation of a file in the
      <code>/etc/polkit-1/rules.d</code> directory with a name
      chosen by the administrator (<code>100-libvirt-acl.rules</code>
      would be a reasonable choice). See the <code>polkit(8)</code>
      manual page for a description of how to write these files
      in general. The key idea is to create a file containing
      something like
    </p>
        <pre xml:space="preserve">
      polkit.addRule(function(action, subject) {
        ....logic to check 'action' and 'subject'...
      });
    </pre>
        <p>
      In this code snippet above, the <code>action</code> object
      instance will represent the libvirt permission being checked
      along with identifying attributes for the object it is being
      applied to. The <code>subject</code> meanwhile will identify
      the libvirt client app (with the caveat above about it only
      dealing with local clients connected via the UNIX socket).
      On the <code>action</code> object, the permission name is
      accessible via the <code>id</code> attribute, while the
      object identifying attributes are exposed via the
      <code>lookup</code> method.
    </p>
        <h3>
          <a name="exconnect" shape="rect" id="exconnect">Example: restricting ability to connect to drivers</a>
        </h3>
        <p>
      Consider a local user <code>berrange</code>
      who has been granted permission to connect to libvirt in
      full read-write mode. The goal is to only allow them to
      use the <code>QEMU</code> driver and not the Xen or LXC
      drivers which are also available in libvirtd.
      To achieve this we need to write a rule which checks
      whether the <code>connect_driver</code> attribute
      is <code>QEMU</code>, and match on an action
      name of <code>org.libvirt.api.connect.getattr</code>. Using
      the javascript rules format, this ends up written as
    </p>
        <pre xml:space="preserve">
polkit.addRule(function(action, subject) {
    if (action.id == "org.libvirt.api.connect.getattr" &amp;&amp;
        subject.user == "berrange") {
          if (action.lookup("connect_driver") == 'QEMU') {
            return polkit.Result.YES;
          } else {
            return polkit.Result.NO;
          }
    }
});
    </pre>
        <h3>
          <a name="exdomain" shape="rect" id="exdomain">Example: restricting access to a single domain</a>
        </h3>
        <p>
      Consider a local user <code>berrange</code>
      who has been granted permission to connect to libvirt in
      full read-write mode. The goal is to only allow them to
      see the domain called <code>demo</code> on the LXC driver.
      To achieve this we need to write a rule which checks
      whether the <code>connect_driver</code> attribute
      is <code>LXC</code> and the <code>domain_name</code>
      attribute is <code>demo</code>, and match on a action
      name of <code>org.libvirt.api.domain.getattr</code>. Using
      the javascript rules format, this ends up written as
    </p>
        <pre xml:space="preserve">
polkit.addRule(function(action, subject) {
    if (action.id == "org.libvirt.api.domain.getattr" &amp;&amp;
        subject.user == "berrange") {
          if (action.lookup("connect_driver") == 'LXC' &amp;&amp;
              action.lookup("domain_name") == 'demo') {
            return polkit.Result.YES;
          } else {
            return polkit.Result.NO;
          }
    }
});
    </pre>
      </div>
    </div>
    <div id="footer">
      <p id="sponsor">
	    Sponsored by:<br /><a href="http://et.redhat.com/"><img src="et.png" alt="Project sponsored by Red Hat Emerging Technology" /></a></p>
    </div>
  </body>
</html>