Giter VIP home page Giter VIP logo

libkrun's Introduction

libkrun

libkrun is a dynamic library that allows programs to easily acquire the ability to run processes in a partially isolated environment using KVM Virtualization.

It integrates a VMM (Virtual Machine Monitor, the userspace side of an Hypervisor) with the minimum amount of emulated devices required to its purpose, abstracting most of the complexity that comes from Virtual Machine management, offering users a simple C API.

Possible use cases

  • Adding VM-isolation capabilities to an OCI runtime.
  • Implementing a lightweight jailer for serverless workloads.
  • Bringing additional self-isolation capabilities to conventional services (think of something as simple as chroot, but more powerful).

Goals and non-goals

Goals

  • Enable other projects to easily gain KVM-based process isolation capabilities.
  • Be self-sufficient (no need for calling to an external VMM) and very simple to use.
  • Be as small as possible, implementing only the features required to achieve its goals.
  • Have the smallest possible footprint in every aspect (RAM consumption, CPU usage and boot time).
  • Be compatible with a reasonable amount of workloads.

Non-goals

  • Become a generic VMM.
  • Be compatible with all kinds of workloads.
  • Provide the best possible performance.

Device support

Virtio devices

  • virtio-console
  • virtio-fs
  • virtio-vsock
  • virtio-balloon (only free-page reporting)

Networking

In libkrun, networking is implemented using a novel technique called socket-to-vsock impersonation. This allows the VM to have network connectivity without a virtual interface (hence, virtio-net is not among the list of supported devices).

The current implementation of this technique, found part in this repository and the other part in the kernel patches included with libkrunfw is just a proof-of-concept. It's limited to IPv4 TCP and UNIX connections, only supports recv/send operations, and the implementation itself is still quite hacky. We expect this technique to mature within libkrun, so it can be eventually upstreamed into the Linux kernel and other VMMs.

DNS resolutions issues

As, by default, glibc will use UDP for DNS requests, which is not yet supported by the socket-to-vsock impersonation technique described above, name resolution will fail with the default configuration. To work around this, you need to add the following line to the /etc/resolv.conf of the root filesystem servicing the isolated process:

options use-vc

Building and installing

Requirements

Compiling

make

Installing

sudo make install

Using the library

Despite being written in Rust, this library provides a simple C API defined in include/libkrun.h

Examples

chroot_vm

This is a simple example providing chroot-like functionality using libkrun.

Building chroot_vm

cd examples
make

Running chroot_vm

To be able to chroot_vm, you need first a directory to act as the root filesystem for your isolated program. An easy way to prepare one, is by using podman:

podman create --name chroot_vm fedora
mkdir rootfs
podman export chroot_vm | tar xpf - -C rootfs
podman rm chroot_vm

Now you can use chroot_vm to run a process within this new root filesystem:

./chroot_vm ./rootfs /bin/sh

If the libkrun and/or libkrunfw libraries were installed on a path that's not included in your /etc/ld.so.conf configuration, you may get an error like this one:

./chroot_vm: error while loading shared libraries: libkrun.so: cannot open shared object file: No such file or directory

To avoid this problem, use the LD_LIBRARY_PATH environment variable to point to the location where the libraries were installed. For example, if the libraries were installed in /usr/local/lib64, use something like this:

LD_LIBRARY_PATH=/usr/local/lib64 ./chroot_vm rootfs/ /bin/sh

Status

While functional, libkrun is still in a very early development stage.

Our first priority now is getting feedback from potential users of the library, to build a Community around it that would help us set the priorities and shape it to be useful for them.

Acknowledgments

libkrun incorporates code from Firecracker, rust-vmm and Cloud-Hypervisor.

libkrun's People

Contributors

giuseppe avatar slp avatar stefano-garzarella avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.