Skip to main content

A text user interface (TUI) to control virtual machines on a per user basis

Project description

VMTUI

a text user interface to control libvirt VMs on a per user basis.

libvirt polkit configuration

VMTUI is intended as a simple interface to allow unprivileged user accounts to control (i.e. (re)start, shutdown, install) their personal virtual machines. To make use of this, libvirt must be configured to use polkit. The package provides a helper script gen_libvirt_polkit_acl that allows the generation of an ACL policy based on a yaml database.

The libvirtd.conf file must be modified src

/etc/libvirt/libvirtd.conf:

access_drivers = [ "polkit" ]

In this example, a user account must belong to the adm_vmhost group to get full priviliges. User accounts with personal VMs must belong to the user_vm group.

/etc/polkit-1/rules.d/90-libvirt-admin.rules:

polkit.addRule(function(action, subject) {
    if (subject.isInGroup("adm_vmhost")) {
        // Grant full access to all libvirt actions related to domains
        if (action.id.startsWith("org.libvirt.api.domain")) {
            return polkit.Result.YES;
        }

        // Grant access to manage networks and storage as well
        if (action.id.startsWith("org.libvirt.api.network") ||
            action.id.startsWith("org.libvirt.api.storage")) {
            return polkit.Result.YES;
        }
    }
});

/etc/polkit-1/rules.d/100-libvirt-acl.rules:

polkit.addRule(function(action, subject) {
    if ( subject.isInGroup("user_vm") ) {
        if (action.id.startsWith("org.libvirt.api.domain") && action.lookup("connect_driver")=="QEMU") {
            var dom = action.lookup("domain_name");
            if( (subject.user == "alice" && dom == "rocky9-2") ||
                (subject.user == "bob" && dom == "rocky9-3") || // these are the "entry types that must be read from a file, either to grant access to a user or a group
                false // makes generation easier
            ) {
                return polkit.Result.YES;
                } else {
                return polkit.Result.NO;
            }
        } else if ( action.id.startsWith("org.libvirt.api.network") ) {
            if ( action.id.endsWith("getattr") ||
                 action.id.endsWith("read") ||
                 action.id.endsWith("create")
                ) {
                return polkit.Result.YES;
            } else {
                return polkit.Result.NO;
            }
        }
    }
}
);

The example grants the user alice access to the domain rocky9-2, while bob is allowed to manage rocky9-3.

To simplify the generation of the polkit ACL use the s script and provide a user_acl.yaml:

libvirt_acl:
  admin_groups: # configure groups that have full access
    - adm_vmhost
  domains: # domain specific ACL
    rocky9: # grant users alice and bob and members of the group mod_vmhost access to 'rocky9''
      users:
        - alice
        - bob
      groups:
        - mod_vmhost
    rocky9-2: # grant alice access to rocky9-2 
      users:
        - alice
    rocky9-3: # grant bob access to rocky9-3
      users:
        - bob

To generate the ACL (as root):

# User ACLs
gen_libvirt_polkit_acl --acl user_acl.yaml 

# Libvirt Admins
gen_libvirt_polkit_acl --admins user_acl.yaml 

It might be necessary to restart libvirt and polkit.

systemctl restart polkit
systemctl restart libvirtd

SSH configuration for vmtui

You can limit ssh access to vmtui with the following configuration (limits members of the user_vm group to vmtui). It is recommended to use a virtual environment (here /opt/vmtui).

/etc/ssh/sshd_config.d/10-vmtui-conf

Match Group user_vm
    ForceCommand /opt/vmtui/bin/vmtui

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vmtui-0.9.3.dev6.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

vmtui-0.9.3.dev6-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file vmtui-0.9.3.dev6.tar.gz.

File metadata

  • Download URL: vmtui-0.9.3.dev6.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for vmtui-0.9.3.dev6.tar.gz
Algorithm Hash digest
SHA256 9e09beb60b2a93bb4230856b8225ea0f952965feb5bc9bc320a200894cef46e8
MD5 1e1cefa398c7b61d8754a102e16058d5
BLAKE2b-256 8dc5a577a1ebbdc4449770d0598a6f20b2c543ab13676735b6b7ea4a7ecd84aa

See more details on using hashes here.

File details

Details for the file vmtui-0.9.3.dev6-py3-none-any.whl.

File metadata

  • Download URL: vmtui-0.9.3.dev6-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for vmtui-0.9.3.dev6-py3-none-any.whl
Algorithm Hash digest
SHA256 c81de494f44a23cd4b688a652f6795c1e133ff614eb8131c3fefce32e244500d
MD5 48da7d8dd151a4401c73b5fd42b352ce
BLAKE2b-256 670cd2f958972888e82a46f2b673cde9e13caef52bfef86a571c41eeb19b517c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page